コード例 #1
0
 /** Creates an ontology factory. */
 public ParsableOWLOntologyFactory() {
   parsableSchemes = new HashSet<String>();
   parsableSchemes.add("http");
   parsableSchemes.add("https");
   parsableSchemes.add("file");
   parsableSchemes.add("ftp");
 }
コード例 #2
0
 private void addEdge(O d1, O d2) {
   Set<O> values = edgesByVertex.get(d1);
   if (values == null) {
     values = new HashSet<O>();
     edgesByVertex.put(d1, values);
   }
   values.add(d2);
 }
コード例 #3
0
 private void addChildParent(OWLObject child, OWLObject parent, OWLObject ax) {
   getIndexedSet(child, child2ParentMap, true).add(parent);
   getIndexedSet(parent, parent2ChildMap, true).add(parent);
   nodes.add(child);
   nodes.add(parent);
   edgeMap.put(new AxiomEdge(child, parent), ax);
   edgeMap.put(new AxiomEdge(parent, child), ax);
 }
コード例 #4
0
 public void visit(OWLDisjointClassesAxiom axiom) {
   Set<OWLClassExpression> added = new HashSet<OWLClassExpression>();
   for (OWLClassExpression descA : axiom.getClassExpressions()) {
     for (OWLClassExpression descB : axiom.getClassExpressions()) {
       if (!descA.equals(descB) && !added.contains(descA) && !added.contains(descB)) {
         addChildParent(descA, descB, axiom);
         added.add(descA);
         added.add(descB);
         descA.accept(this);
         descB.accept(this);
       }
     }
   }
 }
コード例 #5
0
 public boolean canLoad(OWLOntologyDocumentSource documentSource) {
   if (documentSource.isReaderAvailable()) {
     return true;
   }
   if (documentSource.isInputStreamAvailable()) {
     return true;
   }
   if (parsableSchemes.contains(documentSource.getDocumentIRI().getScheme())) {
     return true;
   }
   // If we can open an input stream then we can attempt to parse the ontology
   // TODO: Take into consideration the request type!
   try {
     InputStream is = documentSource.getDocumentIRI().toURI().toURL().openStream();
     is.close();
     return true;
   } catch (UnknownHostException e) {
     logger.info("Unknown host: " + e.getMessage());
   } catch (MalformedURLException e) {
     logger.info("Malformed URL: " + e.getMessage());
   } catch (FileNotFoundException e) {
     logger.info("File not found: " + e.getMessage());
   } catch (IOException e) {
     logger.info("IO Exception: " + e.getMessage());
   }
   return false;
 }
コード例 #6
0
  public void actionPerformed(ActionEvent actionEvent) {
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    int axiomsRemoved = 0;
    int axiomsAdded = 0;
    int numberOfDisjoints = 0;

    for (OWLOntology ont : getOWLModelManager().getActiveOntologies()) {

      // act on each ontology in turn
      CliqueFinder<OWLClassExpression> merger = new CliqueFinder<OWLClassExpression>();

      Set<OWLDisjointClassesAxiom> oldAxioms = ont.getAxioms(AxiomType.DISJOINT_CLASSES);
      numberOfDisjoints += oldAxioms.size();
      for (OWLDisjointClassesAxiom ax : oldAxioms) {
        merger.add(ax.getClassExpressions());
      }

      for (Set<OWLClassExpression> newAxioms : merger.getResults()) {
        OWLDisjointClassesAxiom newAxiom =
            getOWLModelManager().getOWLDataFactory().getOWLDisjointClassesAxiom(newAxioms);
        if (oldAxioms.contains(newAxiom)) {
          oldAxioms.remove(newAxiom);
        } else {
          changes.add(new AddAxiom(ont, newAxiom));
          axiomsAdded++;
        }
      }

      for (OWLDisjointClassesAxiom oldAxiom : oldAxioms) {
        changes.add(new RemoveAxiom(ont, oldAxiom));
        axiomsRemoved++;
      }
    }
    getOWLModelManager().applyChanges(changes);
    logger.info(
        axiomsRemoved
            + " (of "
            + numberOfDisjoints
            + " total) disjoint class axioms replaced with "
            + axiomsAdded);
  }
コード例 #7
0
 /** @return true if the two subgraphs can be merged because they form a complete graph */
 private boolean canMerge(Set<O> g1, Set<O> g2) {
   for (O vertexInG2 : g2) {
     if (!g1.contains(vertexInG2)) {
       for (O vertexInG1 : g1) {
         if (!isEdge(vertexInG2, vertexInG1)) {
           return false; // found a vertex in g2 that is not adjacent to a vertex in g1
         }
       }
     }
   }
   return true;
 }
コード例 #8
0
    public Set<Set<O>> getResults() {
      if (resultCliques == null) {
        resultCliques = new HashSet<Set<O>>();
        Set<Integer> skip = new HashSet<Integer>();

        List<Set<O>> workingCliques = new ArrayList<Set<O>>(originalCliques);
        for (int i = 0; i < workingCliques.size(); i++) {
          if (!skip.contains(i)) {
            Set<O> g1 = new HashSet<O>(workingCliques.get(i));
            for (int j = i + 1; j < workingCliques.size(); j++) {
              if (!skip.contains(j)) {
                Set<O> g2 = workingCliques.get(j);
                if (canMerge(g1, g2)) {
                  g1.addAll(g2);
                  skip.add(j);
                }
              }
            }
            resultCliques.add(g1);
          }
        }
      }
      return resultCliques;
    }
コード例 #9
0
  private AutocompleteResult exceptionToAutocomplete(
      final String expression,
      final ParserException e,
      final OWLEntityFinder finder,
      final ShortFormProvider sfp) {

    String lastToken;
    int pos;
    if (e.getCurrentToken().endsWith(ERROR_TOKEN)) {
      lastToken = e.getCurrentToken();
      lastToken =
          lastToken.substring(0, lastToken.length() - ERROR_TOKEN.length()); // remove the $$
      pos = e.getStartPos();
    } else {
      lastToken = e.getTokenSequence().get(e.getTokenSequence().size() - 1);
      if (lastToken.endsWith(ERROR_TOKEN)) {
        lastToken =
            lastToken.substring(0, lastToken.length() - ERROR_TOKEN.length()); // remove the $$
      } else if (lastToken.equals("<EOF>")) {
        lastToken = e.getTokenSequence().get(e.getTokenSequence().size() - 2); // EOF is last
        lastToken =
            lastToken.substring(0, lastToken.length() - ERROR_TOKEN.length()); // remove the $$
      } else if (!expression.endsWith(lastToken)) { // later invalid tokens are not in the list
        lastToken =
            expression.substring(
                expression.lastIndexOf(" ") + 1); // we just have to guess at the last word
      }
      pos = expression.length() - lastToken.length();
    }

    Map<String, List<String>> expected = new HashMap<String, List<String>>();

    String search = lastToken + ".*"; // starts with

    if (pos == e.getStartPos()) { // then the error is the last token and we can determine the type

      if (hasExpectedToken(e)) {
        final Set<String> keywords = e.getExpectedKeywords();
        if (!keywords.isEmpty()) {
          List<String> matchingKeywords = new ArrayList<String>();
          for (String keyword : keywords) {
            if (lastToken.length() == 0 || keyword.startsWith(lastToken)) {
              matchingKeywords.add(keyword);
            }
          }
          expected.put("keyword", matchingKeywords);
        }

        if (e.isClassNameExpected()) {
          addResults(expected, OWLClass.class, finder.getOWLClasses(search), sfp);
        }
        if (e.isObjectPropertyNameExpected()) {
          addResults(expected, OWLObjectProperty.class, finder.getOWLObjectProperties(search), sfp);
        }
        if (e.isDataPropertyNameExpected()) {
          addResults(expected, OWLDataProperty.class, finder.getOWLDataProperties(search), sfp);
        }
        if (e.isDatatypeNameExpected()) {
          addResults(expected, OWLDatatype.class, finder.getOWLDatatypes(search), sfp);
        }
        if (e.isAnnotationPropertyNameExpected()) {
          addResults(
              expected,
              OWLAnnotationProperty.class,
              finder.getOWLAnnotationProperties(search),
              sfp);
        }
        if (e.isIndividualNameExpected()) {
          addResults(expected, OWLNamedIndividual.class, finder.getOWLIndividuals(search), sfp);
        }
      } else {
        expected.put("literal", Collections.<String>emptyList());
      }
    } else {
      addKeywords(expected, lastToken);
      addResults(expected, OWLClass.class, finder.getOWLClasses(search), sfp);
      addResults(expected, OWLObjectProperty.class, finder.getOWLObjectProperties(search), sfp);
      addResults(expected, OWLDataProperty.class, finder.getOWLDataProperties(search), sfp);
      addResults(expected, OWLDatatype.class, finder.getOWLDatatypes(search), sfp);
      addResults(
          expected, OWLAnnotationProperty.class, finder.getOWLAnnotationProperties(search), sfp);
      addResults(expected, OWLNamedIndividual.class, finder.getOWLIndividuals(search), sfp);
    }

    return new AutocompleteResult(expression, pos, lastToken, expected);
  }
コード例 #10
0
 public boolean contains(Object obj) {
   return nodes.contains(obj);
 }
コード例 #11
0
 /** Resets the child2ParentMap, the parent2ChildMap, the nodes Set an the edge map */
 protected void clearMaps() {
   child2ParentMap.clear();
   parent2ChildMap.clear();
   nodes.clear();
   edgeMap.clear();
 }
コード例 #12
0
  public boolean retrieveSolutions(String siteNameHash) {
    // use the siteNameHash to access a certain Site individual in the ontology
    // retrieve each Solution individual of this site and use it to re-initialise the Solutions List
    OwlSolution tempSolution;
    OwlSolvedHouse tempSolvedHouse;
    OwlSolvedRoom tempSolvedRoom;

    // first clear the Solution List contents...
    this.solutionsList.clear();

    OWLIndividual tempSiteIndividual =
        OWLFactory.getOWLNamedIndividual(":" + siteNameHash, topIxPrefixManager);
    OWLClassExpression tempSolutionClassExpression =
        OWLFactory.getOWLClass(":Solution", topIxPrefixManager);
    Set<OWLObjectPropertyAssertionAxiom> tempSitePropertyAxioms =
        topIxOnt.getObjectPropertyAssertionAxioms(tempSiteIndividual);

    Set<OWLIndividual> tempSolutionIndividuals =
        new HashSet<>(); // Solution individuals for this particular site. will be filled below...
    Set<OWLIndividual> tempSolvedHouseIndividuals = new HashSet<>();
    Set<OWLIndividual> tempSolvedRoomIndividuals = new HashSet<>();

    // populate the tempSolutionIndividuals Set<OWLIndividual>
    // with the Solution individuals that are solutions of the current Site
    // this block runs through the set of all the object property axioms
    // that have this site as their subject
    // and filters out the ones that are of type "hasSolution"
    for (OWLObjectPropertyAssertionAxiom tempObjPropAssAx : tempSitePropertyAxioms) {
      OWLObjectProperty tempHasSolutionObjectProperty =
          OWLFactory.getOWLObjectProperty(
              IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasSolution"));
      if (tempObjPropAssAx.getProperty() == tempHasSolutionObjectProperty) {
        tempSolutionIndividuals.add(tempObjPropAssAx.getObject());
      }
    }
    // retrieving the site dimensions for this solution set
    // (the site remains the same throughout the plethos of solutions).
    int tempSiteLength = 0;
    int tempSiteWidth = 0;
    OWLDataProperty siteHasLengthProp = OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager);
    OWLDataProperty siteHasWidthProp = OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager);
    Set<OWLDataPropertyAssertionAxiom> tempSiteDataProperties = new HashSet<>();

    tempSiteDataProperties = topIxOnt.getDataPropertyAssertionAxioms(tempSiteIndividual);

    for (OWLDataPropertyAssertionAxiom tempSiteDataProperty : tempSiteDataProperties) {
      if (tempSiteDataProperty.getProperty() == siteHasLengthProp) {
        tempSiteLength = tempSiteDataProperty.getObject().parseInteger();
      }
      if (tempSiteDataProperty.getProperty() == siteHasWidthProp) {
        tempSiteWidth = tempSiteDataProperty.getObject().parseInteger();
      }
    }

    logger.info(tempSolutionIndividuals.size());

    // running every solution individual for/of that particular site in order
    // to extract the solvedHouse's and the solvedRoom's
    // via the hasSolvedHouse and hasSolvedRoom properties.
    int solutionCounter = 0;
    for (OWLIndividual tempSolutionIndividual : tempSolutionIndividuals) {
      tempSolution = new OwlSolution();
      tempSolution.setSolutionID(new Integer(++solutionCounter));

      tempSolution.setSiteLength(new Integer(tempSiteLength));
      tempSolution.setSiteWidth(new Integer(tempSiteWidth));

      // clearing the contents of these two structuresin order to accommodate the solved entities of
      // the next solution.
      tempSolvedHouseIndividuals.clear();
      tempSolvedRoomIndividuals.clear();

      for (OWLObjectPropertyAssertionAxiom tempObjPropAssAx :
          topIxOnt.getObjectPropertyAssertionAxioms(tempSolutionIndividual)) {
        OWLObjectProperty tempHasSolvedHouseObjectProperty =
            OWLFactory.getOWLObjectProperty(
                IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasSolvedHouse"));
        OWLObjectProperty tempHasSolvedRoomObjectProperty =
            OWLFactory.getOWLObjectProperty(
                IRI.create(topIxOnt.getOntologyID().getOntologyIRI() + "#hasSolvedRoom"));
        if (tempObjPropAssAx.getProperty() == tempHasSolvedHouseObjectProperty) {
          tempSolvedHouseIndividuals.add(tempObjPropAssAx.getObject());
        } else if (tempObjPropAssAx.getProperty() == tempHasSolvedRoomObjectProperty) {
          tempSolvedRoomIndividuals.add(tempObjPropAssAx.getObject());
        }
      }

      for (OWLIndividual tempSolvedHouseIndividual : tempSolvedHouseIndividuals) {
        tempSolvedHouse = new OwlSolvedHouse();
        for (OWLDataPropertyAssertionAxiom tempDatPropAssAx :
            topIxOnt.getDataPropertyAssertionAxioms(tempSolvedHouseIndividual)) {
          if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasL", topIxPrefixManager))) {
            // logger.info(tempDatPropAssAx.getObject().parseInteger());
            tempSolvedHouse.setSolvedHouseLength(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasW", topIxPrefixManager))) {
            tempSolvedHouse.setSolvedHouseWidth(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager))) {
            tempSolvedHouse.setSolvedHouseX(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager))) {
            tempSolvedHouse.setSolvedHouseY(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasLiteral", topIxPrefixManager))) {
            tempSolvedHouse.setSolvedHouseLiteral(tempDatPropAssAx.getObject().getLiteral());
          }
        }
        // logger.info(tempSolvedHouse.getSolvedHouseX()+" "+tempSolvedHouse.getSolvedHouseY());
        tempSolution.getSolvedHouses().add(tempSolvedHouse);
      }

      for (OWLIndividual tempSolvedRoomIndividual : tempSolvedRoomIndividuals) {
        tempSolvedRoom = new OwlSolvedRoom();
        for (OWLDataPropertyAssertionAxiom tempDatPropAssAx :
            topIxOnt.getDataPropertyAssertionAxioms(tempSolvedRoomIndividual)) {
          if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasL", topIxPrefixManager))) {
            tempSolvedRoom.setSolvedRoomLength(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasW", topIxPrefixManager))) {
            tempSolvedRoom.setSolvedRoomWidth(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasH", topIxPrefixManager))) {
            tempSolvedRoom.setSolvedRoomHeight(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasX", topIxPrefixManager))) {
            tempSolvedRoom.setSolvedRoomX(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasY", topIxPrefixManager))) {
            tempSolvedRoom.setSolvedRoomY(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasZ", topIxPrefixManager))) {
            tempSolvedRoom.setSolvedRoomZ(tempDatPropAssAx.getObject().parseInteger());
          } else if (tempDatPropAssAx.getProperty()
              == (OWLFactory.getOWLDataProperty(":hasLiteral", topIxPrefixManager))) {
            tempSolvedRoom.setSolvedRoomLiteral(tempDatPropAssAx.getObject().getLiteral());
          }
        }
        tempSolution.getSolvedRooms().add(tempSolvedRoom);
      }
      this.solutionsList.add(tempSolution);
    }

    return true;
  }