protected void removeWithoutCommit(Statement st, Resource... contexts) throws RepositoryException { if (contexts.length == 0 && st.getContext() != null) { contexts = new Resource[] { st.getContext() }; } removeWithoutCommit(st.getSubject(), st.getPredicate(), st.getObject(), contexts); }
@Override public void statementAdded(Statement st) { if (RDFS.SUBCLASSOF.equals(st.getPredicate()) && st.getObject() instanceof Resource) { resetClasses(); } }
/** * Convert a unit of RDF data to an atomic unit of PG data. */ protected BigdataGraphAtom toGraphAtom(final Statement stmt) { final URI s = (URI) stmt.getSubject(); final URI p = (URI) stmt.getPredicate(); final Value o = stmt.getObject(); return toGraphAtom(s, p, o); }
private void refreshInverseOf() throws QueryEvaluationException { final CloseableIteration<Statement, QueryEvaluationException> iter = RyaDAOHelper.query(ryaDAO, null, OWL.INVERSEOF, null, conf); final Map<URI, URI> invProp = new HashMap<>(); try { while (iter.hasNext()) { final Statement st = iter.next(); invProp.put((URI) st.getSubject(), (URI) st.getObject()); invProp.put((URI) st.getObject(), (URI) st.getSubject()); } } finally { if (iter != null) { iter.close(); } } synchronized(inverseOfMap) { inverseOfMap.clear(); inverseOfMap.putAll(invProp); } }
@Override public String getMimeType(RepositoryConnection connection, URI uri) throws RepositoryException { final RepositoryResult<Statement> formats = connection.getStatements(uri, DCTERMS.format, null, false, ldpContext); try { if (formats.hasNext()) return formats.next().getObject().stringValue(); } finally { formats.close(); } return null; } @Override
@Override public boolean contains(Object o) { if (o instanceof Statement) { Statement st = (Statement) o; try { try (RepositoryResult result = rc.getStatements( st.getSubject(), st.getPredicate(), st.getObject(), INFER, st.getContext())) { return result.hasNext(); } } catch (Exception e) { throw new RepositoryGraphRuntimeException(e); } } else { return false; } }
/** * Return the all objects of type C that are can reach the entity by rdf_property. Returns empty * set if there is no such object or if the type of the object does not match the type passed as * argument. * */ private <C> Set<C> queryIncomingAll(Resource entity, String rdf_property, Class<C> returnType) throws RepositoryException { URI property = connection.getValueFactory().createURI(rdf_property); RepositoryResult<Statement> triples = connection.getStatements(null, property, entity, false); Set<C> dupSet = new LinkedHashSet<C>(); while (triples.hasNext()) { Statement triple = triples.next(); if (returnType.isInstance(triple.getSubject())) { dupSet.add(returnType.cast(triple.getSubject())); } } triples.close(); return dupSet; }
@Test public void testGetStatementsMalformedTypedLiteral() throws Exception { Literal invalidIntegerLiteral = vf.createLiteral("the number four", XMLSchema.INTEGER); try { URI pred = vf.createURI(URN_PRED); testCon.add(bob, pred, invalidIntegerLiteral); RepositoryResult<Statement> statements = testCon.getStatements(bob, pred, null, true); assertNotNull(statements); assertTrue(statements.hasNext()); Statement st = statements.next(); assertTrue(st.getObject() instanceof Literal); assertTrue(st.getObject().equals(invalidIntegerLiteral)); } catch (RepositoryException e) { // shouldn't happen fail(e.getMessage()); } }
private int findSize() throws RepositoryException { CloseableIteration<? extends Statement, RepositoryException> iter; HashSet<URI> set = new HashSet<URI>(); ObjectConnection conn = getObjectConnection(); iter = conn.getStatements(getResource(), null, null); try { while (iter.hasNext()) { set.add(iter.next().getPredicate()); } } finally { iter.close(); } int index = 0; while (set.contains(getMemberPredicate(index))) index++; return index; }
private int applyRuleRdfs4a() throws SailException { int nofInferred = 0; Model iter = newThisIteration.filter(null, null, null); for(Statement st : iter) { boolean added = addInferredStatement(st.getSubject(), RDF.TYPE, RDFS.RESOURCE); if (added) { nofInferred++; } } return nofInferred; }
@Override public void parse(Model graph, Resource implNode) throws SailConfigException { super.parse(graph, implNode); Literal indexDirLit = Models.objectLiteral(graph.filter(implNode, INDEX_DIR, null)).orElseThrow( () -> new SailConfigException("no value found for " + INDEX_DIR)); setIndexDir(indexDirLit.getLabel()); for (Statement stmt : graph.filter(implNode, null, null)) { if (stmt.getPredicate().getNamespace().equals(LuceneSailConfigSchema.NAMESPACE)) { if (stmt.getObject() instanceof Literal) { String key = stmt.getPredicate().getLocalName(); setParameter(key, stmt.getObject().stringValue()); } } } } }
@Override public OWLAxiom next() throws RepositoryException { Statement stmt = stmts.next(); org.openrdf.model.URI axiomResource = (org.openrdf.model.URI) stmt.getSubject(); RepositoryConnection connection = repository.getConnection(); try { return anonymousHandler.removeSurrogates(parseAxiom(connection, axiomResource)); } catch (RepositoryException re) { throw re; } catch (Exception e) { throw new RepositoryException(e); } finally { connection.close(); } }
for (StmtIterator i = title2.listProperties(); i.hasNext(); ) { Statement s = i.next(); System.out.println( "title2 has property " + s.getPredicate() + " with value " + s.getObject() ); }
private void addAll(final Collection<Statement> addTo, final Set<Value> alreadyDescribed, final Set<Value> toDescribe, final CloseableIteration<? extends Statement, SailException> iter) throws SailException { try { while (iter.hasNext()) { Statement st = iter.next(); addTo.add(st); Resource context = st.getContext(); if (null != context && !alreadyDescribed.contains(context)) { toDescribe.add(context); } } } finally { iter.close(); } }
public void apply(final RippleList arg, final Sink<RippleList> solutions, final ModelConnection mc) throws RippleException { Model model = mc.getModel(); if (model instanceof SesameModel) { Object head = arg.getFirst(); final RippleList rest = arg.getRest(); final Sink<Object> pushSink = v -> solutions.accept(rest.push(v)); Sink<Statement> stSink = st -> { if ('_' == st.getPredicate().getLocalName().charAt(0)) { pushSink.accept(st.getObject()); } }; mc.getStatements(mc.toRDF(head), null, null, stSink); } else { logger.warn("primitive is compatible only with the Sesame model: " + this); } } }
/** * Retrieves an object {@link Value} from the statements in the given model. * If more than one possible object value exists, any one value is picked and * returned. * * @param m * the model from which to retrieve an object value. * @return an object value from the given model, or {@link Optional#empty()} * if no such value exists. * @since 4.0 */ public static Optional<Value> object(Model m) { return m.stream().map(st -> st.getObject()).findAny(); }
@Override public JSONArray loadHistory(String filename) throws Exception { File file = new File(filename); // String encoding = EncodingDetector.detect(file); // String contents = EncodingDetector.getString(file, encoding); SailRepository myRepository = new SailRepository(new MemoryStore()); myRepository.initialize(); SailRepositoryConnection con = myRepository.getConnection(); con.add(file, "", RDFFormat.TURTLE); RepositoryResult<Statement> result = con.getStatements(null, new URIImpl("http://isi.edu/integration/karma/dev#hasWorksheetHistory"), null, false); if(result.hasNext()) { Statement stmt = result.next(); String history = stmt.getObject().stringValue(); return new JSONArray(history); } return new JSONArray(); }
@Override protected boolean accept(Statement statement) throws RepositoryException { return statement.getObject() instanceof URI && connection.hasStatement((URI) statement.getObject(), RDF.TYPE, LDP.NonRDFSource, true, ldpContext); } };
private int applyRuleX1() throws SailException { int nofInferred = 0; String prefix = RDF.NAMESPACE + "_"; Model iter = newThisIteration.filter(null, null, null); for(Statement st : iter) { IRI predNode = st.getPredicate(); String predURI = predNode.toString(); if (predURI.startsWith(prefix) && isValidPredicateNumber(predURI.substring(prefix.length()))) { boolean added = addInferredStatement(predNode, RDF.TYPE, RDFS.CONTAINERMEMBERSHIPPROPERTY); if (added) { nofInferred++; } } } return nofInferred; }
@Override public void addStatement(Statement statement) throws ModelRuntimeException { this.assertModel(); try { org.openrdf.model.Statement s = ConversionUtil.toOpenRDF(statement, this.valueFactory); this.connection.add(s, s.getContext()); } catch(RepositoryException e) { throw new ModelRuntimeException(e); } }