⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgxmlparser.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					}
					else{
						Individual ind = onto.newIndividual(new Terms(label,l),onto.getUniversalConceptType());
						indTable.put(id,new Integer(ind.getId()));
					}
					if(trace) System.out.println("Individual " + label);
				}
			}
			// Axiom schemata
			for(String s = buf.readLine();(s != null) && (s.indexOf("</support") == -1);s = buf.readLine()){
				if(s.indexOf("<subprop") != -1){
					String subid = CGXMLParser.getValueFromXMLLine(s,"subid");
					if(subid.equals("abstract")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						ConceptType ct = onto.getConceptType(((Integer) ctTable.get(id)).intValue());
						new ConceptAbstraction(ct);	
						if(trace) System.out.println("Abstract type " + ct.getTerm(l));
					}
					if(subid.equals("disjoint")){
						String id1 = CGXMLParser.getValueFromXMLLine(s,"id1");
						String id2 = CGXMLParser.getValueFromXMLLine(s,"id2");
						ConceptType ct1 = onto.getConceptType(((Integer) ctTable.get(id1)).intValue());
						ConceptType ct2 = onto.getConceptType(((Integer) ctTable.get(id2)).intValue());
						new ConceptDisjunction(ct1,ct2);	
						if(trace) System.out.println("Disjonction between " + ct1.getTerm(l) + " and " + ct2.getTerm(l));
					}
					if(subid.equals("partition")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						ConceptType ct = onto.getConceptType(((Integer) ctTable.get(id)).intValue());
						new ConceptPartition(ct);	
						if(trace) System.out.println("Partition " + ct.getTerm(l));
					}
					if(subid.equals("exclusivity")){
						String id1 = CGXMLParser.getValueFromXMLLine(s,"id1");
						String id2 = CGXMLParser.getValueFromXMLLine(s,"id2");
						RelationType rt1 = onto.getRelationType(((Integer) rtTable.get(id1)).intValue());
						RelationType rt2 = onto.getRelationType(((Integer) rtTable.get(id2)).intValue());
						new RelationExclusivity(rt1,rt2);	
						if(trace) System.out.println("Exclusivity between " + rt1.getTerm(l) + " and " + rt2.getTerm(l));
					}
					if(subid.equals("incompatibility")){
						String id1 = CGXMLParser.getValueFromXMLLine(s,"id1");
						String id2 = CGXMLParser.getValueFromXMLLine(s,"id2");
						RelationType rt1 = onto.getRelationType(((Integer) rtTable.get(id1)).intValue());
						RelationType rt2 = onto.getRelationType(((Integer) rtTable.get(id2)).intValue());
						new RelationIncompatibility(rt1,rt2);	
						if(trace) System.out.println("Incompatibility between " + rt1.getTerm(l) + " and " + rt2.getTerm(l));
					}
					if(subid.equals("symmetry")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						RelationType rt = onto.getRelationType(((Integer) rtTable.get(id)).intValue());
						new RelationSymmetry(rt);	
						if(trace) System.out.println("Symmetry " + rt.getTerm(l));
					}
					if(subid.equals("antisymmetry")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						RelationType rt = onto.getRelationType(((Integer) rtTable.get(id)).intValue());
						new RelationAntisymmetry(rt);	
						if(trace) System.out.println("Antisymmetry " + rt.getTerm(l));
					}
					if(subid.equals("reflexivity")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						RelationType rt = onto.getRelationType(((Integer) rtTable.get(id)).intValue());
						new RelationReflexivity(rt);	
						if(trace) System.out.println("Reflexivity " + rt.getTerm(l));
					}
					if(subid.equals("irreflexivity")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						RelationType rt = onto.getRelationType(((Integer) rtTable.get(id)).intValue());
						new RelationIrreflexivity(rt);	
						if(trace) System.out.println("Irreflexivity " + rt.getTerm(l));
					}
					if(subid.equals("transitivity")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						RelationType rt = onto.getRelationType(((Integer) rtTable.get(id)).intValue());
						new RelationTransitivity(rt);	
						if(trace) System.out.println("Transitivity " + rt.getTerm(l));
					}
					if(subid.equals("mincardinality")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						String index = CGXMLParser.getValueFromXMLLine(s,"index");
						String value = CGXMLParser.getValueFromXMLLine(s,"value");
						RelationType rt = onto.getRelationType(((Integer) rtTable.get(id)).intValue());
						new RelationMinCardinality(rt,Integer.parseInt(index),Integer.parseInt(value));	
						if(trace) System.out.println("Min Cardinality " + rt.getTerm(l));
					}
					if(subid.equals("maxcardinality")){
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						String index = CGXMLParser.getValueFromXMLLine(s,"index");
						String value = CGXMLParser.getValueFromXMLLine(s,"value");
						RelationType rt = onto.getRelationType(((Integer) rtTable.get(id)).intValue());
						new RelationMaxCardinality(rt,Integer.parseInt(index),Integer.parseInt(value));	
						if(trace) System.out.println("Max Cardinality " + rt.getTerm(l));
					}
					// This part of the code is kept for version compatibility
					if(subid.equals("property")){
						String type = CGXMLParser.getValueFromXMLLine(s,"type");
						String id = CGXMLParser.getValueFromXMLLine(s,"id");
						Integer i = (Integer) rtTable.get(id);
						if(type.equals("C-")){
							int index = Integer.parseInt(CGXMLParser.getValueFromXMLLine(s,"index"));
							int value = Integer.parseInt(CGXMLParser.getValueFromXMLLine(s,"value"));
							RelationType rt = onto.getRelationType(i.intValue());
							new RelationMinCardinality(rt,index,value);
							if(trace) System.out.println("Cardinality min on conceptual primitive " + rt.getTerm(l));
						}
						if(type.equals("C+")){
							int index = Integer.parseInt(CGXMLParser.getValueFromXMLLine(s,"index"));
							int value = Integer.parseInt(CGXMLParser.getValueFromXMLLine(s,"value"));
							RelationType rt = onto.getRelationType(i.intValue());
							new RelationMaxCardinality(rt,index,value);
							if(trace) System.out.println("Cardinality max on conceptual primitive " + rt.getTerm(l));
						}
						if(!type.equals("C-") && !type.equals("C+")){
							if(i == null){
								i = (Integer) ctTable.get(id);
								ConceptualPrimitive cp = onto.getConceptType(i.intValue());
							}
							else{
								ConceptualPrimitive cp = onto.getRelationType(i.intValue());
								if(Integer.parseInt(type) == 1) new RelationSymmetry((RelationType) cp);
								if(Integer.parseInt(type) == 2) new RelationReflexivity((RelationType) cp);
								if(Integer.parseInt(type) == 3) new RelationTransitivity((RelationType) cp);
								if(Integer.parseInt(type) == 4) new RelationIrreflexivity((RelationType) cp);
								if(Integer.parseInt(type) == 5) new RelationAntisymmetry((RelationType) cp);
								if(trace) System.out.println("Property on conceptual primitive " + cp.getTerm(l));
							}
						}
					}
				}
			}
			// Axioms
			// flag : 0-(between axioms) 1-(name passed) 2-(in hypothesis graph) 
			// 3-(hypothesis passed) 4-(in conclusion graph)
			// 5-(conclusion graph passed) 6-(in couples) 7-(couples passed)
			int flag = 0;
			Axiom a = new Axiom();
			Hashtable cHypTable = new Hashtable();
			Hashtable cConTable = new Hashtable();
			Hashtable rHypTable = new Hashtable();
			Hashtable rConTable = new Hashtable();
			for(String s = buf.readLine();(s != null) && (s.indexOf("</cogxml>") == -1);s = buf.readLine()){
				if((flag == 0) && (s.indexOf("<rule") != -1)){
					String id = CGXMLParser.getValueFromXMLLine(s,"id");
					a = onto.newAxiom(new Terms(id,l));
					if(trace) System.out.println("Axiom " + a.getTerm(l));
					cHypTable.clear();
					cConTable.clear();
					rHypTable.clear();
					rConTable.clear();
					flag = 1;
				}
				if((flag == 1) && ((s.indexOf("<subprop subid=\"note\"") != -1))){
					if(s.indexOf("\"/>") != -1){
						String note = CGXMLParser.getValueFromXMLLine(s,"text");
						if(note != null) a.setNote(note);
					}
					else{
						String note = s.substring(s.indexOf("text=\"") + 6);
						s = buf.readLine();
						for(;s.indexOf("\"/>") == -1;s = buf.readLine()){
							note = note.concat("\n");
							note = note.concat(s);
						}
						if((s.indexOf("\"/>") != -1) && (s.length() > 3)){
							note = note.concat("\n");
							note = note.concat(s.substring(0,s.length() - 3));
						}
						a.setNote(note);
					}
				}
				if((flag == 1) && ((s.indexOf("<subprop subid=\"hard\"") != -1))){
					String value = CGXMLParser.getValueFromXMLLine(s,"value");
					if(value.equals("yes")) a.setHard(true);
				}
				if((flag == 1) && (s.indexOf("<graph id=\"hypothesis\">") != -1)){
					flag = 2;
				}
				if((flag == 2) && (s.indexOf("<concept") != -1)){
					String id = CGXMLParser.getValueFromXMLLine(s,"id");
					String idType = CGXMLParser.getValueFromXMLLine(s,"idType");
					String idMarker = CGXMLParser.getValueFromXMLLine(s,"idMarker");
					String gx = CGXMLParser.getValueFromXMLLine(s,"gx");
					String gy = CGXMLParser.getValueFromXMLLine(s,"gy");
					Concept c;
					if(idType != null){
						c = new Concept(onto.getConceptType(((Integer) ctTable.get(idType)).intValue()));
					}
					else{
						c = new Concept();
					}
					if(idMarker != null){
						c.setIndividual(onto.getIndividual(((Integer) indTable.get(idMarker)).intValue()));
					}
					if((gx != null) && (gy != null)){
						int x = Integer.parseInt(gx);
						int y = Integer.parseInt(gy);
						c.setLocation(x,y);
					}
					else c.setRandomLocation();
					a.addHypothesisConcept(c);
					cHypTable.put(id,new Integer(c.getId()));
				}
				if((flag == 2) && (s.indexOf("<relation") != -1)){
					String id = CGXMLParser.getValueFromXMLLine(s,"id");
					String idType = CGXMLParser.getValueFromXMLLine(s,"idType");
					String gx = CGXMLParser.getValueFromXMLLine(s,"gx");
					String gy = CGXMLParser.getValueFromXMLLine(s,"gy");
					Relation r;
					if(idType != null){
						r = new Relation(onto.getRelationType(((Integer) rtTable.get(idType)).intValue()));
					}
					else{
						r = new Relation();
					}
					if((gx != null) && (gy != null)){
						int x = Integer.parseInt(gx);
						int y = Integer.parseInt(gy);
						r.setLocation(x,y);
					}
					else r.setRandomLocation();
					a.addHypothesisRelation(r);
					rHypTable.put(id,new Integer(r.getId()));
				}
				if((flag == 2) && (s.indexOf("<edge") != -1)){
					String label = CGXMLParser.getValueFromXMLLine(s,"label");
					String rid = CGXMLParser.getValueFromXMLLine(s,"rid");
					String cid = CGXMLParser.getValueFromXMLLine(s,"cid");
					Relation r = a.getRelation(((Integer) rHypTable.get(rid)).intValue());
					Concept c = a.getConcept(((Integer) cHypTable.get(cid)).intValue());
					r.setLinkedConcept(c,Integer.parseInt(label));
				}
				if((flag == 2) && (s.indexOf("</graph>") != -1)){
					flag = 3;
				}
				if((flag == 3) && (s.indexOf("<graph id=\"conclusion\">") != -1)){
					flag = 4;
				}
				if((flag == 4) && (s.indexOf("<concept") != -1)){
					String id = CGXMLParser.getValueFromXMLLine(s,"id");
					String idType = CGXMLParser.getValueFromXMLLine(s,"idType");
					String idMarker = CGXMLParser.getValueFromXMLLine(s,"idMarker");
					String gx = CGXMLParser.getValueFromXMLLine(s,"gx");
					String gy = CGXMLParser.getValueFromXMLLine(s,"gy");
					Concept c;
					if(idType != null){
						c = new Concept(onto.getConceptType(((Integer) ctTable.get(idType)).intValue()));
					}
					else{
						c = new Concept();
					}
					if(idMarker != null){
						c.setIndividual(onto.getIndividual(((Integer) indTable.get(idMarker)).intValue()));
					}
					if((gx != null) && (gy != null)){
						int x = Integer.parseInt(gx);
						int y = Integer.parseInt(gy);
						c.setLocation(x,y);
					}
					else c.setRandomLocation();
					a.addConclusionConcept(c);
					cConTable.put(id,new Integer(c.getId()));
				}
				if((flag == 4) && (s.indexOf("<relation") != -1)){
					String id = CGXMLParser.getValueFromXMLLine(s,"id");
					String idType = CGXMLParser.getValueFromXMLLine(s,"idType");
					String gx = CGXMLParser.getValueFromXMLLine(s,"gx");
					String gy = CGXMLParser.getValueFromXMLLine(s,"gy");
					Relation r;
					if(idType != null){
						r = new Relation(onto.getRelationType(((Integer) rtTable.get(idType)).intValue()));
					}
					else{
						r = new Relation();
					}
					if((gx != null) && (gy != null)){
						int x = Integer.parseInt(gx);
						int y = Integer.parseInt(gy);
						r.setLocation(x,y);
					}
					else r.setRandomLocation();
					a.addConclusionRelation(r);
					rConTable.put(id,new Integer(r.getId()));
				}
				if((flag == 4) && (s.indexOf("<edge") != -1)){
					String label = CGXMLParser.getValueFromXMLLine(s,"label");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -