private void expandStatements(Model model, Statement statement) { IRI p = statement.getPredicate(); // add statements that are NOT shortcut properties // as-is to the result model if (!shortcutPredicates.contains(p)) { model.add(statement); return; } // 'p' is a shortcut predicate Resource context = statement.getContext(); BNode bNode = f.createBNode(); // TODO verify that 'context' works properly, even if it is null model.add(statement.getSubject(), getExpandedPredicate(p), bNode, context); model.add(bNode, constant, statement.getObject(), context); } }
@Override public void removeNamespace(String prefix) throws RepositoryException { added.removeNamespace(prefix); Optional<Namespace> ns = committed.getNamespace(prefix); if (ns.isPresent()) { removed.setNamespace(ns.get()); } }
@Override public void clearNamespaces() throws RepositoryException { added.getNamespaces().clear(); committed.getNamespaces().forEach(ns -> { removed.setNamespace(ns); }); }
@Override public Set<Type> decide(Model model, Resource resource) { Set<IRI> rdfTypes = model.filter(resource, RDF.TYPE, null).objects().stream() .map(v -> (IRI) v) .collect(Collectors.toSet()); Set<IRI> usedPredicates = model.filter(resource, null, null).predicates().stream() .filter(p -> !p.equals(RDF.TYPE)) .collect(Collectors.toSet()); usedPredicates.forEach(p -> { if (inferenceMap.containsKey(p)) { rdfTypes.add(inferenceMap.get(p)); } }); return rdfTypes.stream() .map(mapper::getDecidableType) .collect(Collectors.toSet()); }
if (aGraph.size() == 0) { return theObj; Set<IRI> aProps = Sets.newHashSet(); aGraph.filter(aTmpRes, null, null).stream() .map(Statement::getPredicate).forEach(aProps::add); Object aValue = aFunc.apply(aGraph.filter(aRes, aProp, null).stream().map(Statement::getObject).collect(Collectors.toSet())); aGraph.filter(aTmpRes, null, null) .stream() .filter(theStmt -> aUsedProps.contains(theStmt.getPredicate())) .forEach(aInstanceTriples::add);
@Test public void testGraphSerialization() throws Exception { testCon.add(bob, name, nameBob); testCon.add(alice, name, nameAlice); Model graph; try (RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, true)) { graph = new LinkedHashModel(statements.asList()); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(graph); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); Model deserializedGraph = (Model) in.readObject(); in.close(); assertFalse(deserializedGraph.isEmpty()); for (Statement st : deserializedGraph) { assertTrue(graph.contains(st)); assertTrue(testCon.hasStatement(st, true)); } }
private Class getClassByAnnotation(Model theGraph, Resource theResource, EmpireAnnotationProvider annotationProvider) { Model model = theGraph.filter(theResource, RDF.TYPE, null); for (Statement statement : model) { Optional<Class<?>> stringValue = annotationProvider.getClassesWithAnnotation(RdfsClass.class).stream().filter (c -> expand(c .getAnnotation (RdfsClass.class).value()).equals(statement.getObject().stringValue())).findFirst(); if (stringValue.isPresent()) { return stringValue.get(); } else { System.out.println("ERROR: " +statement.getObject().stringValue()); } } return null; }
/** * Test method for {@link org.eclipse.rdf4j.model.Model#setNamespace(java.lang.String, java.lang.String)}. */ @Test public final void testSetNamespaceSamePrefix() { testModel.setNamespace("r", RDF.NAMESPACE); testModel.setNamespace("r", RDFS.NAMESPACE); Set<Namespace> namespaces = testModel.getNamespaces(); assertNotNull("Namespaces set must not be null", namespaces); assertEquals(1, namespaces.size()); assertEquals(new SimpleNamespace("r", RDFS.NAMESPACE), testModel.getNamespace("r").orElse(null)); }
private static Optional<Literal> backCompatibilityFilterObjectLiteral(Model graph, Resource subject, IRI predicate) { Optional<Literal> value = Models.objectLiteral(graph.filter(subject, predicate, null)); return value.isPresent() ? value : Models.objectLiteral(graph.filter(subject, BACK_COMPATIBILITY_MAP.get(predicate), null)); } }
private IRI getFunctionIRI(Resource execution, Model model) { return Models.objectIRI( model.filter(execution, Rdf.Fno.executes, null) ) .orElseThrow(() -> new RuntimeException( "function execution does not have fno:executes value")); }
Objects.requireNonNull(m, "input model may not be null"); GetStatementOptional statementSupplier = (s, p, o, c) -> m.filter(s, p, o, c).stream().findAny(); Function<String, Supplier<ModelException>> exceptionSupplier = Models::modelException; if (RDF.FIRST.equals(st.getPredicate())) { consumer.accept(st.getObject());
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; }
private static boolean matchModels(Model model1, Model model2) { // Compare statements without blank nodes first, save the rest for later List<Statement> model1BNodes = new ArrayList<Statement>(model1.size()); for (Statement st : model1) { if (isBlank(st.getSubject()) || isBlank(st.getObject()) || isBlank(st.getContext())) { model1BNodes.add(st); } else { if (!model2.contains(st)) { return false; } } } return matchModels(model1BNodes, model2, new HashMap<Resource, Resource>(), 0); }
@Override public Resource export(Model m) { Resource implNode = super.export(m); ValueFactory vf = SimpleValueFactory.getInstance(); m.setNamespace("sl", LuceneSailConfigSchema.NAMESPACE); if (indexDir != null) { m.add(implNode, INDEX_DIR, SimpleValueFactory.getInstance().createLiteral(indexDir)); } for (String key : getParameterNames()) { m.add(implNode, vf.createIRI(LuceneSailConfigSchema.NAMESPACE, key), vf.createLiteral(getParameter(key))); } return implNode; }
@Override public Resource export(Model m) { Resource implNode = super.export(m); m.setNamespace("sparql", NAMESPACE); if (getQueryEndpointUrl() != null) { m.add(implNode, QUERY_ENDPOINT, vf.createIRI(getQueryEndpointUrl())); } if (getUpdateEndpointUrl() != null) { m.add(implNode, UPDATE_ENDPOINT, vf.createIRI(getUpdateEndpointUrl())); } return implNode; }
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); }
@Override public void addValue(String subject, String predicate, String value, String dataType, String graph) throws RdfProcessingFailedException { try { if (Objects.equals(subject, baseUri) && isDescriptionPredicate(predicate)) { ValueFactory vf = SimpleValueFactory.getInstance(); model.add(vf.createIRI(subject), vf.createIRI(predicate), vf.createLiteral(value)); } } catch (Exception e) { throw new RdfProcessingFailedException(e); } }