List of usage examples for java.util SortedSet remove
boolean remove(Object o);
From source file:org.dllearner.reasoning.SPARQLReasoner.java
@Override public OWLClassExpression getRangeImpl(OWLObjectProperty property) { return objectPropertyRanges.computeIfAbsent(property, k -> { String query = String.format("SELECT ?range WHERE {" + "<%s> <%s> ?range. FILTER(isIRI(?range))" + "}", property.toStringID(), RDFS.range.getURI()); try (QueryExecution qe = qef.createQueryExecution(query)) { ResultSet rs = qe.execSelect(); SortedSet<OWLClassExpression> ranges = new TreeSet<>(); while (rs.hasNext()) { QuerySolution qs = rs.next(); ranges.add(df.getOWLClass(IRI.create(qs.getResource("range").getURI()))); }/*from w ww. j a v a 2s.c o m*/ ranges.remove(df.getOWLThing()); if (ranges.size() == 1) { return ranges.first(); } else if (ranges.size() > 1) { return df.getOWLObjectIntersectionOf(ranges); } return df.getOWLThing(); } catch (Exception e) { logger.error("Failed to compute range for " + property, e); } return null; }); }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
@Override public SortedSet<OWLClassExpression> getSuperClassesImpl(OWLClassExpression description) { String query;/* www . j av a 2 s . c o m*/ if (description.isAnonymous()) { throw new IllegalArgumentException("Only named classes are supported."); } else if (description.isOWLThing()) { return Sets.newTreeSet(); } else if (description.isOWLNothing()) { query = SPARQLQueryUtils.SELECT_LEAF_CLASSES_OWL; } else { query = String.format(SPARQLQueryUtils.SELECT_DIRECT_SUPERCLASS_OF_QUERY, description.asOWLClass().toStringID()); } ResultSet rs = executeSelectQuery(query); SortedSet<OWLClass> superClasses = asOWLEntities(EntityType.CLASS, rs, "var1"); superClasses.remove(description); // System.out.println("Sup(" + description + "):" + superClasses); return new TreeSet<OWLClassExpression>(superClasses); }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
public SortedSet<OWLClassExpression> getSuperClasses(OWLClassExpression description, boolean direct) { if (description.isAnonymous()) { throw new IllegalArgumentException("Only named classes are supported."); }// www .j av a2 s. c om SortedSet<OWLClassExpression> superClasses = new TreeSet<>(); String query; if (direct) { query = String.format( "SELECT ?sup {<%s> <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?sup. FILTER(isIRI(?sup))}", description.asOWLClass().toStringID()); } else { query = String.format( "SELECT ?sup {<%s> <http://www.w3.org/2000/01/rdf-schema#subClassOf>* ?sup. FILTER(isIRI(?sup))}", description.asOWLClass().toStringID()); } ResultSet rs = executeSelectQuery(query); QuerySolution qs; while (rs.hasNext()) { qs = rs.next(); superClasses.add(df.getOWLClass(IRI.create(qs.getResource("sup").getURI()))); } superClasses.remove(description); System.out.println("Sup(" + description + "):" + superClasses); return superClasses; }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
public SortedSet<OWLClassExpression> getSubClasses(OWLClassExpression description, boolean direct) { if (description.isAnonymous()) { throw new IllegalArgumentException("Only named classes are supported."); }//w w w . ja v a2 s . c om SortedSet<OWLClassExpression> subClasses = new TreeSet<>(); String query; if (description.isOWLThing()) { query = SPARQLQueryUtils.SELECT_TOP_LEVEL_OWL_CLASSES; } else { query = String.format(SPARQLQueryUtils.SELECT_SUBCLASS_OF_QUERY, description.asOWLClass().toStringID()); if (direct) { } else { } } ResultSet rs = executeSelectQuery(query); subClasses.addAll(asOWLEntities(EntityType.CLASS, rs, "var1")); subClasses.remove(description); subClasses.remove(df.getOWLNothing()); // System.out.println("Sub(" + description + "):" + subClasses); return new TreeSet<>(subClasses); }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
@Override public SortedSet<OWLObjectProperty> getSuperPropertiesImpl(OWLObjectProperty objectProperty) { SortedSet<OWLObjectProperty> properties = new TreeSet<>(); String query = String.format(SPARQLQueryUtils.SELECT_SUPERPROPERTY_OF_QUERY, objectProperty.toStringID()); ResultSet rs = executeSelectQuery(query); QuerySolution qs;//from w w w . j a v a 2 s. c om while (rs.hasNext()) { qs = rs.next(); properties.add(df.getOWLObjectProperty(IRI.create(qs.getResource("var1").getURI()))); } properties.remove(objectProperty); properties.remove(df.getOWLTopObjectProperty()); return properties; }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
@Override public SortedSet<OWLObjectProperty> getSubPropertiesImpl(OWLObjectProperty objectProperty) { SortedSet<OWLObjectProperty> properties = new TreeSet<>(); String query = String.format(SPARQLQueryUtils.SELECT_SUBPROPERTY_OF_QUERY, objectProperty.toStringID()); ResultSet rs = executeSelectQuery(query); QuerySolution qs;/* w ww .j a va 2s . c o m*/ while (rs.hasNext()) { qs = rs.next(); properties.add(df.getOWLObjectProperty(IRI.create(qs.getResource("var1").getURI()))); } properties.remove(objectProperty); properties.remove(df.getOWLBottomObjectProperty()); return properties; }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
@Override public SortedSet<OWLDataProperty> getSuperPropertiesImpl(OWLDataProperty dataProperty) { SortedSet<OWLDataProperty> properties = new TreeSet<>(); String query = String.format(SPARQLQueryUtils.SELECT_SUPERPROPERTY_OF_QUERY, dataProperty.toStringID()); ResultSet rs = executeSelectQuery(query); QuerySolution qs;//www . j a va 2 s.c om while (rs.hasNext()) { qs = rs.next(); properties.add(df.getOWLDataProperty(IRI.create(qs.getResource("var1").getURI()))); } properties.remove(dataProperty); properties.remove(df.getOWLTopDataProperty()); return properties; }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
@Override public SortedSet<OWLDataProperty> getSubPropertiesImpl(OWLDataProperty dataProperty) { SortedSet<OWLDataProperty> properties = new TreeSet<>(); String query = String.format(SPARQLQueryUtils.SELECT_SUPERPROPERTY_OF_QUERY, dataProperty.toStringID()); ResultSet rs = executeSelectQuery(query); QuerySolution qs;//from w ww . j a v a 2s. c om while (rs.hasNext()) { qs = rs.next(); properties.add(df.getOWLDataProperty(IRI.create(qs.getResource("var1").getURI()))); } properties.remove(dataProperty); properties.remove(df.getOWLBottomDataProperty()); return properties; }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
public SortedSet<OWLDataProperty> getDisjointProperties(OWLDataProperty dataProperty) { SortedSet<OWLDataProperty> properties = new TreeSet<>(); String query = String.format(SPARQLQueryUtils.SELECT_DISJOINT_PROPERTIES_QUERY, dataProperty.toStringID(), dataProperty.toStringID());/*from w w w .j a va 2 s.co m*/ ResultSet rs = executeSelectQuery(query); QuerySolution qs; while (rs.hasNext()) { qs = rs.next(); properties.add(df.getOWLDataProperty(IRI.create(qs.getResource("var1").getURI()))); } properties.remove(dataProperty); return properties; }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
/** * Convert a collection of IRIs into OWL entities based on the given entity type. * @param entityType the entity type/*from w w w.j a v a2s.c om*/ * @param entityIRIs the entity IRIs * @return a set of entities of the given entity type */ private <E extends OWLEntity> SortedSet<E> asOWLEntities(EntityType<E> entityType, Collection<IRI> entityIRIs) { SortedSet<E> entities = new TreeSet<>(); for (IRI iri : entityIRIs) { if (!iri.isReservedVocabulary()) { entities.add(df.getOWLEntity(entityType, iri)); } } // remove top and bottom entities entities.remove(df.getOWLThing()); entities.remove(df.getOWLNothing()); entities.remove(df.getOWLTopObjectProperty()); entities.remove(df.getOWLBottomObjectProperty()); entities.remove(df.getOWLTopDataProperty()); entities.remove(df.getOWLBottomDataProperty()); return entities; }