package de.fuberlin.wiwiss.semmf.examples; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Iterator; import java.util.List; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Bag; import com.hp.hpl.jena.vocabulary.RDF; import de.fuberlin.wiwiss.semmf.engine.MatchingEngine; import de.fuberlin.wiwiss.semmf.result.ClusterMatchingResult; import de.fuberlin.wiwiss.semmf.result.GraphMatchingResult; import de.fuberlin.wiwiss.semmf.result.MatchingResult; import de.fuberlin.wiwiss.semmf.result.NodeMatchingResult; import de.fuberlin.wiwiss.semmf.result.PropertyMatchingResult; import de.fuberlin.wiwiss.semmf.vocabulary.MD; /** * Class providing the running java code for tutorials included in SemMF distribution. * * @author Radoslaw Oldakowski * @version 1.0 * last modified on 29.11.2006 */ public class JobMatching { public static void main(String[] args) { Model jobMD = createJobMD(); writeJobMDtoFile (jobMD, "doc/examples/jobMD.n3", "N3"); MatchingEngine me = new MatchingEngine("file:doc/examples/jobMD.n3", "N3"); MatchingResult mr = me.exec(); printMatchingResult(mr); mr.sortByClusterSim("job details"); System.out.println("\r\rAnd now the same matching result sortedy by similarity vlaue for cluster 'job details':\r\r"); printMatchingResult(mr); } /** * see tutorial: how to create a matching description (included in SemMF distribution) */ public static Model createJobMD () { Model m = ModelFactory.createDefaultModel(); Resource gmd = m.createResource(); gmd.addProperty(RDF.type, MD.GraphMatchingDescription); gmd.addProperty(MD.queryModelURL, "file:./doc/examples/jpp.rdf"); gmd.addProperty(MD.resModelURL, "file:./doc/examples/jps.rdf"); gmd.addProperty(MD.queryGraphURI, "http://example.org/JobPositionPosting.rdfs#JPP_1"); gmd.addProperty(MD.resGraphURIpath, "(?x )"); Bag cmds = m.createBag(); gmd.addProperty(MD.hasClusterMatchingDescriptions, cmds); Resource cmd_1 = m.createResource(); cmd_1.addProperty(RDF.type, MD.ClusterMatchingDescription); cmd_1.addProperty(MD.label, "job details"); cmd_1.addProperty(MD.weight, "0.25"); cmds.add(cmd_1); Resource cmd_2 = m.createResource(); cmd_2.addProperty(RDF.type, MD.ClusterMatchingDescription); cmd_2.addProperty(MD.label, "skills"); cmd_2.addProperty(MD.weight, "0.75"); cmds.add(cmd_2); Bag nmds_c1 = m.createBag(); cmd_1.addProperty(MD.hasNodeMatchingDescriptions, nmds_c1); Resource c1_nmd_1 = m.createResource(); nmds_c1.add(c1_nmd_1); c1_nmd_1.addProperty(RDF.type, MD.NodeMatchingDescription); c1_nmd_1.addProperty(MD.label, "travel required"); c1_nmd_1.addProperty(MD.weight, "0.3"); c1_nmd_1.addProperty(MD.queryNodePath, "( ?jobDetails) (?jobDetails ?x)"); c1_nmd_1.addProperty(MD.resNodePath, "(<#graphEntryURI#> ?x)"); c1_nmd_1.addProperty(MD.reverseMatching, "false"); Resource sm = m.createResource(); sm.addProperty(RDF.type, MD.StringMatcher); sm.addProperty(MD.caseSensitive, "false"); c1_nmd_1.addProperty(MD.useMatcher, sm); Resource c1_nmd_2 = m.createResource(); nmds_c1.add(c1_nmd_2); c1_nmd_2.addProperty(RDF.type, MD.NodeMatchingDescription); c1_nmd_2.addProperty(MD.label, "salary"); c1_nmd_2.addProperty(MD.weight, "0.7"); c1_nmd_2.addProperty(MD.queryNodePath, "( ?jobDetails) (?jobDetails ?x)"); c1_nmd_2.addProperty(MD.resNodePath, "(<#graphEntryURI#> ?x)"); c1_nmd_2.addProperty(MD.reverseMatching, "false"); Resource nm = m.createResource(); nm.addProperty(RDF.type, MD.NumericMatcher); nm.addProperty(MD.decreaseSim, "upwards"); nm.addProperty(MD.maxDevFraction, "0.25"); c1_nmd_2.addProperty(MD.useMatcher, nm); Bag nmds_c2 = m.createBag(); cmd_2.addProperty(MD.hasNodeMatchingDescriptions, nmds_c2); Resource c2_nmd_1 = m.createResource(); nmds_c2.add(c2_nmd_1); c2_nmd_1.addProperty(RDF.type, MD.NodeMatchingDescription); c2_nmd_1.addProperty(MD.label, "skill node"); c2_nmd_1.addProperty(MD.weight, "1"); c2_nmd_1.addProperty(MD.queryNodePath, "( ?jobDetails) (?jobDetails ?x)"); c2_nmd_1.addProperty(MD.resNodePath, "(<#graphEntryURI#> ?x)"); c2_nmd_1.addProperty(MD.reverseMatching, "false"); Bag pmds = m.createBag(); c2_nmd_1.addProperty(MD.hasPropertyMatchingDescriptions, pmds); Resource pmd_1 = m.createResource(); pmds.add(pmd_1); pmd_1.addProperty(RDF.type, MD.PropertyMatchingDescription); pmd_1.addProperty(MD.label, "skill"); pmd_1.addProperty(MD.weight, "0.8"); pmd_1.addProperty(MD.queryPropURI, RDF.type); pmd_1.addProperty(MD.resPropURI, RDF.type); pmd_1.addProperty(MD.reverseMatching, "false"); Resource tm_1 = m.createResource(); tm_1.addProperty(RDF.type, MD.TaxonomicMatcher); pmd_1.addProperty(MD.useMatcher, tm_1); tm_1.addProperty(MD.simInheritance, "true"); Resource taxon_skills = m.createResource(); taxon_skills.addProperty(RDF.type, MD.Taxonomy); taxon_skills.addProperty(MD.taxonomyURL, "file:./doc/examples/it-skills.rdfs"); taxon_skills.addProperty(MD.rootConceptURI, "http://example.org/it-skills.rdfs#IT_Skills"); tm_1.addProperty(MD.taxonomy, taxon_skills); Resource emc = m.createResource(); emc.addProperty(RDF.type, MD.ExpMilestCalc); emc.addProperty(MD.k_factor, "2"); tm_1.addProperty(MD.useMilestoneCalc, emc); Resource pmd_2 = m.createResource(); pmds.add(pmd_2); pmd_2.addProperty(RDF.type, MD.PropertyMatchingDescription); pmd_2.addProperty(MD.label, "skill level"); pmd_2.addProperty(MD.weight, "0.2"); pmd_2.addProperty(MD.queryPropURI, "http://example.org/it-skills.rdfs#competenceLevel"); pmd_2.addProperty(MD.resPropURI, "http://example.org/it-skills.rdfs#competenceLevel"); pmd_2.addProperty(MD.reverseMatching, "false"); Resource tm_2 = m.createResource(); tm_2.addProperty(RDF.type, MD.TaxonomicMatcher); pmd_2.addProperty(MD.useMatcher, tm_2); tm_2.addProperty(MD.simInheritance, "true"); Resource taxon_skillLevel = m.createResource(); taxon_skillLevel.addProperty(RDF.type, MD.Taxonomy); taxon_skillLevel.addProperty(MD.taxonomyURL, "file:./doc/examples/it-skills.rdfs"); taxon_skillLevel.addProperty(MD.rootConceptURI, "http://example.org/it-skills.rdfs#Skill_level"); tm_2.addProperty(MD.taxonomy, taxon_skillLevel); Resource lmc = m.createResource(); lmc.addProperty(RDF.type, MD.LinMilestCalc); tm_2.addProperty(MD.useMilestoneCalc, lmc); return m; } /** * see tutorial: traaversing the matching result (included in SemMF distribution) */ public static void printMatchingResult (MatchingResult mr) { System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); System.out.println("Query Graph: " + mr.getFirst().getQueryGraphEntryNode().getURI()); System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\r"); while (mr.hasNext()) { GraphMatchingResult gmr = mr.next(); System.out.println("\r==========================================================="); System.out.println("Res Graph : " + gmr.getResGraphEntryNode().getURI()); System.out.println("Sim : " + gmr.getSimilarity()); System.out.println("===========================================================\r"); List clusterList = gmr.getClusterMatchingResultList(); for (Iterator itC = clusterList.iterator(); itC.hasNext();) { ClusterMatchingResult cmr = (ClusterMatchingResult) itC.next(); System.out.println("-------------------------------------------"); System.out.println("Cluster label : " + cmr.getLabel()); System.out.println("Cluster sim : " + cmr.getSimilarity()); System.out.println("Cluster weight: " + cmr.getWeight()); List nodeList = cmr.getNodeMatchingResultList(); for (Iterator itN = nodeList.iterator(); itN.hasNext();) { NodeMatchingResult nmr = (NodeMatchingResult) itN.next(); List propertyList = nmr.getPropertyMatchingResultList(); System.out.println(" - - - - - - - - - - - - - - - - - - --"); System.out.println(" Node label : " + nmr.getLabel()); if (propertyList.isEmpty()) { System.out.println(" query node : " + nmr.getQueryNode().toString()); System.out.println(" res node : " + nmr.getResNode().toString()); } System.out.println(" Node sim : " + nmr.getSimilarity()); System.out.println(" Node weight: " + nmr.getWeight()); for (Iterator itP = propertyList.iterator(); itP.hasNext();) { PropertyMatchingResult pmr = (PropertyMatchingResult) itP.next(); System.out.println(" . . . . . . . . . . . . . . . . . "); System.out.println(" prop label : " + pmr.getLabel()); System.out.println(" query prop : " + pmr.getQueryPropVal().toString()); System.out.println(" res prop : " + pmr.getResPropVal().toString()); System.out.println(" prop sim : " + pmr.getSimilarity()); System.out.println(" prop weight: " + pmr.getWeight()); } } } } mr.setToFirst(); } private static void writeJobMDtoFile(Model m, String filePath, String lang) { m.setNsPrefix("semmf", MD.NS); m.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); m.setNsPrefix("ja", "http://jena.hpl.hp.com/2005/11/Assembler#"); try { File outputFile = new File(filePath); if (!outputFile.exists()) { outputFile.createNewFile(); } FileOutputStream out = new FileOutputStream(outputFile); m.write(out, lang); out.close(); } catch (IOException e) { System.out.println(e.toString()); } } }