protected DimensionSet getGroupDimSet(Resource groupResource) throws EmptyDimensionException, NotFoundException { Selector selector = new SimpleSelector(groupResource, Datatype.hasDimension, (RDFNode) null); StmtIterator iter = model.listStatements( selector ); DimensionSet dimSet = new DimensionSet(); if (iter.hasNext()) { while (iter.hasNext()) { Statement s = iter.nextStatement(); Resource dimensionResource = s.getObject().asResource(); Dimension dim = CarbonOntology.getInstance().getDimension(getId(dimensionResource)); dimSet.add(dim); if (groupResource.hasProperty(Datatype.hasHorizontalDimension, dimensionResource)) { dimSet.setDimensionOrientation(dim, Orientation.HORIZONTAL); } else if (groupResource.hasProperty(Datatype.hasVerticalDimension, dimensionResource)) { dimSet.setDimensionOrientation(dim, Orientation.VERTICAL); } } } return dimSet; }
protected TreeSet<Keyword> getElementKeywords(Resource elementResource) throws MalformedOntologyException { Selector selector = new SimpleSelector(elementResource, Datatype.hasTag, (RDFNode) null); StmtIterator iter = model.listStatements(selector); TreeSet<Keyword> keywords = new TreeSet<>(); if (iter.hasNext()) { while (iter.hasNext()) { Statement s = iter.nextStatement(); keywords.add(RepoFactory.getKeywordRepo().getKeyword(s.getObject().asResource())); } } else { throw new MalformedOntologyException("The element " + elementResource + " has no keyword"); } return keywords; }
private Model runInference(Model data, URL rules, int lineLength, int maxLineLength) throws IOException { Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(rules.toString())); InfModel inf = ModelFactory.createInfModel(reasoner, data); // Break long literals (more than lineLength chars) using carriage returns Model remove = ModelFactory.createDefaultModel(); Model add = ModelFactory.createDefaultModel(); Selector sel = new SimpleSelector(null, null, (String)null); for(StmtIterator sIt = inf.listStatements(sel); sIt.hasNext();) { Statement s = sIt.nextStatement(); if(!s.getObject().isLiteral()) continue; String l = s.getString(); String lp = paginate(l, lineLength, maxLineLength); if (lp.length() != l.length()) { remove.add(s); add.add(s.getSubject(), s.getPredicate(), lp, s.getLanguage()); } } inf.remove(remove); inf.add(add); return inf; }
protected TreeSet<Keyword> getGroupCommonKeywords(Resource groupResource) { Selector selector = new SimpleSelector(groupResource, Datatype.hasCommonTag, (RDFNode) null); StmtIterator iter = model.listStatements( selector ); TreeSet<Keyword> keywords = new TreeSet<>(); if (iter.hasNext()) { while (iter.hasNext()) { Statement s = iter.nextStatement(); keywords.add(RepoFactory.getKeywordRepo().getKeyword(s.getObject().asResource())); } } return keywords; }
public HashSet<RelationType> getRelationTypes() { Selector selector = new SimpleSelector(null, RDF.type, Datatype.RelationType); StmtIterator iter = model.listStatements(selector); HashSet<RelationType> types = new HashSet<>(); if (iter.hasNext()) { while (iter.hasNext()) { Statement s = iter.nextStatement(); types.add(getRelationType(s.getSubject())); } } return types; }
public HashMap<String, Reference> getReferences() { Selector selector = new SimpleSelector(null, RDF.type, Datatype.Reference); StmtIterator iter = model.listStatements(selector); if (iter.hasNext()) { while (iter.hasNext()) { getReference(iter.next().getSubject()); } } return refCache; }
@Override public void update(Set<Statement> stmts) throws IllegalStatementException, InconsistentOntologyException, OntologyServerException { Set<Statement> stmtsToRemove = new HashSet<Statement>(); for (Statement stmt : stmts) { if(functionalProperties.contains(stmt.getPredicate())) { Selector selector = new SimpleSelector(stmt.getSubject(), stmt.getPredicate(), (RDFNode)null); StmtIterator stmtsToRemoveIt = null; try { stmtsToRemoveIt = onto.listStatements(selector); stmtsToRemove.addAll(stmtsToRemoveIt.toSet()); } catch (org.mindswap.pellet.exceptions.InconsistentOntologyException ioe) { Logger.log("The ontology is in an inconsistent state! I couldn't " + "update any statements.\n ", VerboseLevel.WARNING); throw new InconsistentOntologyException("The ontology is in an inconsistent state! I couldn't " + "update any statements."); } } } remove(stmtsToRemove); add(stmts, MemoryProfile.DEFAULT, false); }
@Override public void clear(PartialStatement partialStmt) throws OntologyServerException { Logger.log("Clearing statements matching ["+ partialStmt + "]\n"); Selector selector = new SimpleSelector(partialStmt.getSubject(), partialStmt.getPredicate(), partialStmt.getObject()); StmtIterator stmtsToRemove = null; Set<Statement> setToRemove = new HashSet<Statement>(); stmtsToRemove = onto.listStatements(selector); if (stmtsToRemove != null) setToRemove = stmtsToRemove.toSet(); remove(setToRemove); }