Exemple #1
0
  /** Sets up the default matching configuration for the ontologies */
  public void defaultConfig() {
    bkSources = new Vector<String>();
    File ontRoot = new File(BK_PATH);
    if (ontRoot.exists()) {
      FileFilter ont =
          new ExtensionFilter(
              "Ontology Files (*.owl, *.rdf, *.rdfs, *.xml)",
              new String[] {".owl", ".rdf", ".rdfs", ".xml"},
              false);
      File[] ontFiles = ontRoot.listFiles(ont);
      for (File f : ontFiles) bkSources.add(f.getName());
      FileFilter lex =
          new ExtensionFilter("Lexicon Files (*.lexicon)", new String[] {".lexicon"}, false);
      File[] lexFiles = ontRoot.listFiles(lex);
      for (File f : lexFiles) bkSources.add(f.getName());
      bkSources.add("WordNet");
    } else {
      System.out.println("WARNING: 'store/knowledge' directory not found!");
    }
    selectedSources = new Vector<String>(bkSources);

    size = SizeCategory.getSizeCategory();
    lang = LanguageSetting.getLanguageSetting();
    languages = new HashSet<String>();
    for (String s : source.getLexicon().getLanguages())
      if (target.getLexicon().getLanguages().contains(s)) languages.add(s);
    if (languages.contains("en") || languages.size() == 0) language = "en";
    else language = languages.iterator().next();
    matchSteps = new Vector<MatchStep>();
    if (lang.equals(LanguageSetting.TRANSLATE)) matchSteps.add(MatchStep.TRANSLATE);
    matchSteps.add(MatchStep.LEXICAL);
    if (lang.equals(LanguageSetting.SINGLE)) matchSteps.add(MatchStep.BK);
    if (!size.equals(SizeCategory.HUGE)) matchSteps.add(MatchStep.WORD);
    matchSteps.add(MatchStep.STRING);
    if (size.equals(SizeCategory.SMALL) || size.equals(SizeCategory.MEDIUM))
      matchSteps.add(MatchStep.STRUCT);
    double sourceRatio =
        (source.dataPropertyCount() + source.objectPropertyCount()) * 1.0 / source.classCount();
    double targetRatio =
        (target.dataPropertyCount() + target.objectPropertyCount()) * 1.0 / target.classCount();
    if (sourceRatio >= 0.05 && targetRatio >= 0.05) matchSteps.add(MatchStep.PROPERTY);
    if (size.equals(SizeCategory.HUGE)) matchSteps.add(MatchStep.OBSOLETE);
    matchSteps.add(MatchStep.SELECT);
    matchSteps.add(MatchStep.REPAIR);
    hierarchic = true;
    wms = WordMatchStrategy.AVERAGE;
    ssm = StringSimMeasure.ISUB;
    primaryStringMatcher = size.equals(SizeCategory.SMALL);
    nss = NeighborSimilarityStrategy.DESCENDANTS;
    directNeighbors = false;
    sType = SelectionType.getSelectionType();
    structuralSelection = size.equals(SizeCategory.HUGE);
    flagSteps = new Vector<Problem>();
    for (Problem f : Problem.values()) flagSteps.add(f);
  }
Exemple #2
0
 public void translateOntologies() {
   Vector<String> sLangs = new Vector<String>(source.getLexicon().getLanguages());
   Vector<String> tLangs = new Vector<String>(target.getLexicon().getLanguages());
   for (String l1 : sLangs) {
     for (String l2 : tLangs) {
       if (!l1.equals(l2)) {
         Dictionary d = new Dictionary(l1, l2);
         d.translateLexicon(source.getLexicon());
         d = new Dictionary(l2, l1);
         d.translateLexicon(target.getLexicon());
       }
     }
   }
   languages = new HashSet<String>();
   for (String s : source.getLexicon().getLanguages())
     if (target.getLexicon().getLanguages().contains(s)) languages.add(s);
 }
Exemple #3
0
 public void openOntologies(URI src, URI tgt) throws OWLOntologyCreationException {
   closeOntologies();
   // Initialize the URIMap and RelationshipMap
   uris = new URIMap();
   rels = new RelationshipMap();
   if (useReasoner) PropertyConfigurator.configure(dir + LOG);
   long time = System.currentTimeMillis() / 1000;
   System.out.println("Loading source ontology");
   source = new Ontology2Match(src);
   time = System.currentTimeMillis() / 1000 - time;
   System.out.println(source.getURI() + " loaded in " + time + " seconds");
   System.out.println("Classes: " + source.classCount());
   System.out.println("Names: " + source.getLexicon().size());
   System.out.println("Individuals: " + source.individualCount());
   System.out.println(
       "Properties: " + (source.dataPropertyCount() + source.objectPropertyCount()));
   time = System.currentTimeMillis() / 1000;
   System.out.println("Loading target ontology");
   target = new Ontology2Match(tgt);
   time = System.currentTimeMillis() / 1000 - time;
   System.out.println(target.getURI() + " loaded in " + time + " seconds");
   System.out.println("Classes: " + target.classCount());
   System.out.println("Names: " + target.getLexicon().size());
   System.out.println("Individuals: " + target.individualCount());
   System.out.println(
       "Properties: " + (target.dataPropertyCount() + target.objectPropertyCount()));
   System.out.println("Direct Relationships: " + rels.relationshipCount());
   time = System.currentTimeMillis() / 1000;
   System.out.println("Running transitive closure on RelationshipMap");
   rels.transitiveClosure();
   time = System.currentTimeMillis() / 1000 - time;
   System.out.println("Transitive closure finished in " + time + " seconds");
   System.out.println("Extended Relationships: " + rels.relationshipCount());
   System.out.println("Disjoints: " + rels.disjointCount());
   // Reset the alignment, mapping, and evaluation
   a = null;
   activeMapping = -1;
   evaluation = null;
   // Refresh the user interface
   if (userInterface != null) userInterface.refresh();
   defaultConfig();
   System.out.println("Finished!");
 }
Exemple #4
0
 /** @return whether there are properties of corresponding types in both active ontologies */
 public boolean hasProperties() {
   return hasOntologies()
       && ((source.dataPropertyCount() > 0 && target.dataPropertyCount() > 0)
           || (source.objectPropertyCount() > 0 && target.objectPropertyCount() > 0));
 }
Exemple #5
0
 /** @return whether there are classes in both active ontologies */
 public boolean hasClasses() {
   return hasOntologies() && source.classCount() > 0 && target.classCount() > 0;
 }
  public static Alignment tfIdfMainParse(String sourcePath, String targetPath)
      throws OWLOntologyCreationException {
    double sim = 0.0d;
    csMaps = new Alignment();
    source = new Ontology2Match(sourcePath);
    target = new Ontology2Match(targetPath);

    String sName, tName;
    List<double[]> docsrcVector, doctgtVector = new ArrayList<double[]>();

    // Get class Names of the source and target
    Set<Integer> sourceKeys = source.getClasses();
    Set<Integer> targetKeys = target.getClasses();

    // Parse Class Names of Source and Target
    for (Integer i : sourceKeys) {
      for (Integer j : targetKeys) {
        sName = source.getName(i);
        tName = target.getName(j);
        sim = calcCosSim(sName, tName);
        csMaps.add(new Mapping(i, j, sim));
      }
    }

    // Get Data Properties of the source and target
    Set<Integer> sDProp = source.getDataProperties();
    Set<Integer> tDProp = target.getDataProperties();

    // Parse Data Properties of Source and Target
    for (Integer i : sDProp) {
      for (Integer j : tDProp) {
        sName = source.getName(i);
        tName = target.getName(j);
        sim = calcCosSim(sName, tName);
        csMaps.add(new Mapping(i, j, sim));
      }
    }

    // Get Object Properties of the source and target
    Set<Integer> sOProp = source.getObjectProperties();
    Set<Integer> tOProp = target.getObjectProperties();

    // Parse Object Properties of Source and Target
    for (Integer i : sOProp) {
      for (Integer j : tOProp) {
        sName = source.getName(i);
        tName = target.getName(j);
        sim = calcCosSim(sName, tName);
        csMaps.add(new Mapping(i, j, sim));
      }
    }
    return csMaps;
  }