Refine search
/** * Retrieves all object {@link Resource} values from the statements in the given model. * * @param m * the model from which to retrieve all object {@link Resource} values. * @return a {@link Set} containing object {@link Resource} values from the given model, which will be * empty if no such value exists. * @see Model#objects() */ public static Set<Resource> objectResources(Model m) { return m.stream().map(st -> st.getObject()).filter(o -> o instanceof Resource).map( r -> (Resource)r).collect(Collectors.toSet()); }
/** * Retrieves a subject {@link Resource} from the statements in the given model. If more than one possible * resource value exists, any one resource value is picked and returned. * * @param m * the model from which to retrieve a subject Resource. * @return an {@link Optional} subject resource from the given model, which will be * {@link Optional#empty() empty} if no such value exists. */ public static Optional<Resource> subject(Model m) { return m.stream().map(st -> st.getSubject()).findAny(); }
/** * Retrieves a predicate from the statements in the given model. If more than one possible predicate value * exists, any one value is picked and returned. * * @param m * the model from which to retrieve a predicate value. * @return an {@link Optional} predicate value from the given model, which will be {@link Optional#empty() * empty} if no such value exists. */ public static Optional<IRI> predicate(Model m) { return m.stream().map(st -> st.getPredicate()).findAny(); }
@Override public void statementAdded(Statement st) { if (RDFS.SUBCLASSOF.equals(st.getPredicate()) && st.getObject() instanceof Resource) { resetClasses(); } }
@Override protected boolean accept(Statement st) { //de-duplicate triples if (st.getSubject().equals(lastSubj) && st.getPredicate().equals(lastPred) && st.getObject().equals(lastObj)) { return false; } else { lastSubj = st.getSubject(); lastPred = st.getPredicate(); lastObj = st.getObject(); return true; } }
private Statement createStatement(Assertion assertion) { Statement stm = RDF4JHelper.createStatement(assertion); if (stm.getSubject()!=null && stm.getPredicate()!=null && stm.getObject()!=null) return stm; else return null; }
/** * 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. */ public static Optional<Value> object(Model m) { return m.stream().map(st -> st.getObject()).findAny(); }
public ElementVerifier<?> getTypeVerifier() throws SepaParseException { List<Statement> typeDefinitions = getModel().stream().filter(stmt -> stmt.getPredicate().equals(RDF.TYPE)).collect(Collectors.toList()); typeDefinitions.forEach(typeDef -> typeDef.getObject()); return getTypeDef(typeDefinitions.stream().filter(stmt -> ((stmt.getObject().toString().equals(ec())) || (stmt.getObject().toString().equals(epa())) || (stmt.getObject().toString().equals(ep())))).findFirst()); }
@Override public void handleStatement(Statement st) throws RDFHandlerException { try { if (Thread.currentThread().isInterrupted()) { rdfProcessor.commit(); throw new RDFHandlerException("Interrupted"); } String graph = st.getContext() == null ? defaultGraph : st.getContext().stringValue(); rdfProcessor.onQuad( isAssertion(), handleNode(st.getSubject()), st.getPredicate().stringValue(), handleNode(st.getObject()), (st.getObject() instanceof Literal) ? ((Literal) st.getObject()).getDatatype().toString() : null, (st.getObject() instanceof Literal) ? ((Literal) st.getObject()).getLanguage().orElse(null) : null, graph ); } catch (RdfProcessingFailedException e) { throw new RDFHandlerException(e); } }
@Override public void handleStatement(Statement st) throws RDFHandlerException { Value object = st.getObject(); StreamedStatement statement = new StreamedStatement(st.getSubject().stringValue(), st.getPredicate().stringValue(), object.stringValue(), (object instanceof Literal), ((object instanceof Literal)? ((Literal) object).getDatatype().stringValue(): null), (object instanceof Literal ? ((Literal) object).getLanguage().orElse(null) : null)); statements.add(statement); }
public static Model withContext(Iterable<Statement> theGraph, Resource theResource) { Model aModel = newModel(); Iterator var3 = theGraph.iterator(); while(var3.hasNext()) { Statement aStmt = (Statement)var3.next(); aModel.add(SimpleValueFactory.getInstance().createStatement(aStmt.getSubject(), aStmt.getPredicate(), aStmt.getObject(), theResource)); } return aModel; }
@Override public void handleStatement(Statement st) throws RDFHandlerException { if (!writingStarted) { throw new RuntimeException("Document writing has not yet been started"); } try { Resource subj = st.getSubject(); IRI pred = st.getPredicate(); if (inlineBNodes && (pred.equals(RDF.FIRST) || pred.equals(RDF.REST))) { handleList(st); } else if (inlineBNodes && !subj.equals(lastWrittenSubject) && stack.contains(subj)) { handleInlineNode(st); } else { closeHangingResource(); handleStatementInternal(st, false, inlineBNodes, inlineBNodes); } } catch (IOException e) { throw new RDFHandlerException(e); } }
private Resource getResource(Model model) { Iterator<Statement> st = model.iterator(); while (st.hasNext()) { Statement s = st.next(); if ((s.getPredicate().equals(RDF.TYPE))) { if (isRootElement(s)) { return s.getSubject(); } } } return null; }
public static String writeSubjectPredicate(final Statement statement) { Validate.notNull(statement); Validate.notNull(statement.getSubject()); Validate.notNull(statement.getPredicate()); return statement.getSubject().toString() + SEP + statement.getPredicate().toString(); }
@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 void handleStatement(Statement st) throws RDFHandlerException { String predicateName = st.getPredicate().stringValue(); Value obj = st.getObject(); if (predicateName.equals(org.eclipse.rdf4j.model.vocabulary.RDF.TYPE.stringValue())) { vb.declareClass(obj.stringValue()); } else if (obj instanceof Literal) { vb.declareDataProperty(predicateName); } else { vb.declareObjectProperty(predicateName); } } }
@Override public void handleStatement(final Statement statement) throws RDFHandlerException { final Resource enumType = statement.getSubject(); // listHead will point to a type class of the enumeration. final IRI listHead = (IRI) statement.getObject(); if (!enumTypes.containsKey(enumType)) { enumTypes.put(enumType, new LinkedHashSet<Resource>()); } // listHead should point to a list of items that forms the // enumeration. try { final Set<Resource> enumeration = new LinkedHashSet<>(getList(listHead)); if (!enumeration.isEmpty()) { // Add this enumeration for this type. enumTypes.get(enumType).addAll(enumeration); } } catch (final QueryEvaluationException e) { throw new RDFHandlerException("Error getting enumeration list.", e); } } });
private void getUsedNamespaces(Set<Statement> stmts, Set<String> used) { for (Statement st : stmts) { used.add(st.getPredicate().getNamespace()); if (st.getObject() instanceof IRI) { IRI uri = (IRI)st.getObject(); used.add(uri.getNamespace()); } else if (st.getObject() instanceof Literal) { Literal lit = (Literal)st.getObject(); if (lit.getDatatype() != null) { used.add(lit.getDatatype().getNamespace()); } } } }
@Override public void statementRemoved(Statement st) { if (RDFS.SUBCLASSOF.equals(st.getPredicate())) { resetClasses(); } } }
public static RepositoryConfig getRepositoryConfig(Model model, String repositoryID) { Statement idStatement = getIDStatement(model, repositoryID); if (idStatement == null) { // No such config return null; } Resource repositoryNode = idStatement.getSubject(); Resource context = idStatement.getContext(); Model contextGraph = model.filter(null, null, null, context); return RepositoryConfig.create(contextGraph, repositoryNode); }