org.eclipse.rdf4j.model.util.Models Java Examples
The following examples show how to use
org.eclipse.rdf4j.model.util.Models.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DAWGTestResultSetParser.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void reportSolution(Resource solutionNode, List<String> bindingNames) throws RDFHandlerException { MapBindingSet bindingSet = new MapBindingSet(bindingNames.size()); for (Value bindingNode : Models.getProperties(graph, solutionNode, BINDING)) { if (bindingNode instanceof Resource) { Binding binding = getBinding((Resource) bindingNode); bindingSet.addBinding(binding); } else { throw new RDFHandlerException("Value for " + BINDING + " is not a resource: " + bindingNode); } } try { tqrHandler.handleSolution(bindingSet); } catch (TupleQueryResultHandlerException e) { throw new RDFHandlerException(e.getMessage(), e); } }
Example #2
Source File: AbstractParserHandlingTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public final void testSkolemization() throws Exception { Model expectedModel = new LinkedHashModel(); BNode subj = vf.createBNode(); expectedModel .add(vf.createStatement(subj, RDF.VALUE, vf.createLiteral(KNOWN_DATATYPE_VALUE, KNOWN_DATATYPE_URI))); expectedModel .add(vf.createStatement(subj, RDF.VALUE, vf.createLiteral(KNOWN_LANGUAGE_VALUE, KNOWN_LANGUAGE_TAG))); InputStream input = getKnownDatatypeStream(expectedModel); testParser.getParserConfig().set(BasicParserSettings.SKOLEMIZE_ORIGIN, "http://example.com"); testParser.parse(input, BASE_URI); assertErrorListener(0, 0, 0); assertModel(expectedModel); // isomorphic assertNotEquals(new HashSet<>(expectedModel), new HashSet<>(testStatements)); // blank nodes not preserved assertTrue(Models.subjectBNodes(testStatements).isEmpty()); // skolemized }
Example #3
Source File: AbstractModel.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressWarnings("unchecked") @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof Model) { Model model = (Model) o; return Models.isomorphic(this, model); } else if (o instanceof Set) { if (this.size() != ((Set<?>) o).size()) { return false; } try { return Models.isomorphic(this, (Iterable<? extends Statement>) o); } catch (ClassCastException e) { return false; } } return false; }
Example #4
Source File: DynamicModel.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof Model) { Model model = (Model) o; return Models.isomorphic(this, model); } else if (o instanceof Set) { if (this.size() != ((Set<?>) o).size()) { return false; } try { return Models.isomorphic(this, (Iterable<? extends Statement>) o); } catch (ClassCastException e) { return false; } } return false; }
Example #5
Source File: SailConfigUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static SailImplConfig parseRepositoryImpl(Model m, Resource implNode) throws SailConfigException { try { Optional<Literal> typeLit = Models .objectLiteral(m.getStatements(implNode, SailConfigSchema.SAILTYPE, null)); if (typeLit.isPresent()) { Optional<SailFactory> factory = SailRegistry.getInstance().get(typeLit.get().getLabel()); if (factory.isPresent()) { SailImplConfig implConfig = factory.get().getConfig(); implConfig.parse(m, implNode); return implConfig; } else { throw new SailConfigException("Unsupported Sail type: " + typeLit.get().getLabel()); } } return null; } catch (ModelException e) { throw new SailConfigException(e.getMessage(), e); } }
Example #6
Source File: HTTPRepositoryConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void parse(Model model, Resource implNode) throws RepositoryConfigException { super.parse(model, implNode); try { Models.objectIRI(model.getStatements(implNode, REPOSITORYURL, null)) .ifPresent(iri -> setURL(iri.stringValue())); Models.objectLiteral(model.getStatements(implNode, USERNAME, null)) .ifPresent(username -> setUsername(username.getLabel())); Models.objectLiteral(model.getStatements(implNode, PASSWORD, null)) .ifPresent(password -> setPassword(password.getLabel())); } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } }
Example #7
Source File: AbstractLuceneSailConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void parse(Model graph, Resource implNode) throws SailConfigException { super.parse(graph, implNode); Literal indexDirLit = Models.objectLiteral(graph.getStatements(implNode, INDEX_DIR, null)) .orElseThrow(() -> new SailConfigException("no value found for " + INDEX_DIR)); setIndexDir(indexDirLit.getLabel()); for (Statement stmt : graph.getStatements(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()); } } } }
Example #8
Source File: DAWGTestResultSetParser.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = Models.subject(graph.filter(null, RDF.TYPE, RESULTSET)) .orElseThrow(() -> new RDFHandlerException("no instance of type ResultSet")); List<String> bindingNames = getBindingNames(resultSetNode); tqrHandler.startQueryResult(bindingNames); for (Value solutionNode : Models.getProperties(graph, resultSetNode, SOLUTION)) { if (solutionNode instanceof Resource) { reportSolution((Resource) solutionNode, bindingNames); } else { throw new RDFHandlerException("Value for " + SOLUTION + " is not a resource: " + solutionNode); } } tqrHandler.endQueryResult(); } catch (TupleQueryResultHandlerException e) { throw new RDFHandlerException(e.getMessage(), e); } }
Example #9
Source File: NamedGraphTests.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testGetStatements() throws Exception { prepareTest(Arrays.asList("/tests/named-graphs/data1.trig", "/tests/named-graphs/data2.trig", "/tests/named-graphs/data3.trig", "/tests/named-graphs/data4.trig")); try (RepositoryConnection conn = fedxRule.getRepository().getConnection()) { // 1. named graph only present in single endpoint assertThat(Models.subjectIRIs(conn.getStatements(null, RDF.TYPE, FOAF.PERSON, NS_1.GRAPH_1))) .containsExactlyInAnyOrder(NS_1.iri("Person_1"), NS_1.iri("Person_2")); // 2. multiple graphs assertThat(Models.subjectIRIs(conn.getStatements(null, RDF.TYPE, FOAF.PERSON, NS_1.GRAPH_1, NS_2.GRAPH_1))) .containsExactlyInAnyOrder( NS_1.iri("Person_1"), NS_1.iri("Person_2"), NS_2.iri("Person_6"), NS_2.iri("Person_7")); // 3. graph is available in multiple endpoints assertThat(Models.subjectIRIs(conn.getStatements(null, RDF.TYPE, FOAF.PERSON, NS_3.SHARED_GRAPH))) .containsExactlyInAnyOrder(NS_1.iri("Person_5"), NS_2.iri("Person_10")); } }
Example #10
Source File: FedXRepositoryConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void parse(Model m, Resource implNode) throws RepositoryConfigException { super.parse(m, implNode); try { Models.objectLiteral(m.getStatements(implNode, DATA_CONFIG, null)) .ifPresent(value -> setDataConfig(value.stringValue())); Set<Value> memberNodes = m.filter(implNode, MEMBER, null).objects(); if (!memberNodes.isEmpty()) { Model members = new TreeModel(); // add all statements for the given member node for (Value memberNode : memberNodes) { if (!(memberNode instanceof Resource)) { throw new RepositoryConfigException("Member nodes must be of type resource, was " + memberNode); } members.addAll(m.filter((Resource) memberNode, null, null)); } this.members = members; } } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } }
Example #11
Source File: AbstractCommandTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/*** * Add a new repository to the manager. * * @param configStream input stream of the repository configuration * @return ID of the repository as string * @throws IOException * @throws RDF4JException */ protected String addRepository(InputStream configStream) throws IOException, RDF4JException { RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE, SimpleValueFactory.getInstance()); Model graph = new LinkedHashModel(); rdfParser.setRDFHandler(new StatementCollector(graph)); rdfParser.parse( new StringReader(IOUtil.readString(new InputStreamReader(configStream, StandardCharsets.UTF_8))), RepositoryConfigSchema.NAMESPACE); configStream.close(); Resource repositoryNode = Models.subject(graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY)) .orElseThrow(() -> new RepositoryConfigException("could not find subject resource")); RepositoryConfig repoConfig = RepositoryConfig.create(graph, repositoryNode); repoConfig.validate(); manager.addRepositoryConfig(repoConfig); String repId = Models.objectLiteral(graph.filter(repositoryNode, RepositoryConfigSchema.REPOSITORYID, null)) .orElseThrow(() -> new RepositoryConfigException("missing repository id")) .stringValue(); return repId; }
Example #12
Source File: AbstractRepositoryImplConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Utility method to create a new {@link RepositoryImplConfig} by reading data from the supplied {@link Model}. * * @param model the {@link Model} to read configuration data from. * @param resource the subject {@link Resource} identifying the configuration data in the Model. * @return a new {@link RepositoryImplConfig} initialized with the configuration from the input Model, or * {@code null} if no {@link RepositoryConfigSchema#REPOSITORYTYPE} property was found in the configuration * data.. * @throws RepositoryConfigException if an error occurred reading the configuration data from the model. */ public static RepositoryImplConfig create(Model model, Resource resource) throws RepositoryConfigException { try { // Literal typeLit = GraphUtil.getOptionalObjectLiteral(graph, // implNode, REPOSITORYTYPE); final Literal typeLit = Models.objectLiteral(model.getStatements(resource, REPOSITORYTYPE, null)) .orElse(null); if (typeLit != null) { RepositoryFactory factory = RepositoryRegistry.getInstance() .get(typeLit.getLabel()) .orElseThrow(() -> new RepositoryConfigException( "Unsupported repository type: " + typeLit.getLabel())); RepositoryImplConfig implConfig = factory.getConfig(); implConfig.parse(model, resource); return implConfig; } return null; } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } }
Example #13
Source File: SailRepositoryConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void parse(Model model, Resource repImplNode) throws RepositoryConfigException { try { Optional<Resource> sailImplNode = Models.objectResource(model.getStatements(repImplNode, SAILIMPL, null)); if (sailImplNode.isPresent()) { Models.objectLiteral(model.getStatements(sailImplNode.get(), SAILTYPE, null)).ifPresent(typeLit -> { SailFactory factory = SailRegistry.getInstance() .get(typeLit.getLabel()) .orElseThrow(() -> new RepositoryConfigException( "Unsupported Sail type: " + typeLit.getLabel())); sailImplConfig = factory.getConfig(); sailImplConfig.parse(model, sailImplNode.get()); }); } } catch (ModelException | SailConfigException e) { throw new RepositoryConfigException(e.getMessage(), e); } }
Example #14
Source File: SimpleOntology.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof SimpleOntology) { SimpleOntology simpleOntology = (SimpleOntology) obj; OntologyId ontologyId = simpleOntology.getOntologyId(); if (this.ontologyId.equals(ontologyId)) { org.eclipse.rdf4j.model.Model thisSesameModel = this.asSesameModel(); org.eclipse.rdf4j.model.Model otherSesameModel = simpleOntology.asSesameModel(); return Models.isomorphic(thisSesameModel, otherSesameModel); } } return false; }
Example #15
Source File: SimpleNamedGraph.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
/** * Compares two NamedGraphs, and returns true if they consist of isomorphic graphs and the isomorphic graph * identifiers map 1:1 to each other. RDF graphs are isomorphic graphs if statements from one graphs can be mapped * 1:1 on to statements in the other graphs. In this mapping, blank nodes are not considered mapped when having an * identical internal id, but are mapped from one graph to the other by looking at the statements in which the blank * nodes occur. * * Note: Depending on the size of the models, this can be an expensive operation. * * @return true if they are isomorphic graphs and the isomorphic graph identifiers map 1:1 to each other */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof SimpleNamedGraph) { SimpleNamedGraph graph = (SimpleNamedGraph) o; if (!getGraphID().equals(graph.getGraphID())) return false; SesameModelWrapper model1 = new SesameModelWrapper(new org.eclipse.rdf4j.model.impl.LinkedHashModel()); model1.addAll(this); SesameModelWrapper model2 = new SesameModelWrapper(new org.eclipse.rdf4j.model.impl.LinkedHashModel()); model2.addAll(graph); return Models.isomorphic(model1.getSesameModel(), model2.getSesameModel()); } return false; }
Example #16
Source File: TestProxyRepositoryFactory.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public final void testGetRepository() throws RDF4JException, IOException { Model graph = Rio.parse(this.getClass().getResourceAsStream("/proxy.ttl"), RepositoryConfigSchema.NAMESPACE, RDFFormat.TURTLE); RepositoryConfig config = RepositoryConfig.create(graph, Models.subject(graph.getStatements(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY)) .orElseThrow(() -> new RepositoryConfigException("missing Repository instance in config"))); config.validate(); assertThat(config.getID()).isEqualTo("proxy"); assertThat(config.getTitle()).isEqualTo("Test Proxy for 'memory'"); RepositoryImplConfig implConfig = config.getRepositoryImplConfig(); assertThat(implConfig.getType()).isEqualTo("openrdf:ProxyRepository"); assertThat(implConfig).isInstanceOf(ProxyRepositoryConfig.class); assertThat(((ProxyRepositoryConfig) implConfig).getProxiedRepositoryID()).isEqualTo("memory"); // Factory just needs a resolver instance to proceed with construction. // It doesn't actually invoke the resolver until the repository is // accessed. Normally LocalRepositoryManager is the caller of // getRepository(), and will have called this setter itself. ProxyRepository repository = (ProxyRepository) factory.getRepository(implConfig); repository.setRepositoryResolver(mock(RepositoryResolver.class)); assertThat(repository).isInstanceOf(ProxyRepository.class); }
Example #17
Source File: SemagrowRepositoryConfig.java From semagrow with Apache License 2.0 | 6 votes |
@Override public void parse(Model graph, Resource node) throws RepositoryConfigException { try { Optional<Resource> sailImplNode = Models.objectResource(graph.filter(node, SAILIMPL,null)); if (sailImplNode.isPresent()) { sailConfig = new SemagrowSailConfig(); sailConfig.parse(graph, sailImplNode.get()); } } catch (SailConfigException e) { throw new RepositoryConfigException(e.getMessage(), e); } }
Example #18
Source File: RDFQueryLogParser.java From semagrow with Apache License 2.0 | 6 votes |
private QueryLogRecord parseQueryRecord(Resource qr, Model model) { Optional<IRI> optionalEndpoint = Models.objectIRI(model.filter(qr, QFR.ENDPOINT, null)); Optional<IRI> optionalResults = Models.objectIRI(model.filter(qr, QFR.RESULTFILE, null)); Date startTime = parseDate(Models.objectLiteral(model.filter(qr, QFR.START, null)).get(), model); Date endTime = parseDate(Models.objectLiteral(model.filter(qr, QFR.END, null)).get(), model); long cardinality = parseCardinality(Models.objectLiteral(model.filter(qr, QFR.CARDINALITY, null)).get(), model); String expr = parseQuery(Models.object(model.filter(qr, QFR.QUERY, null)).get(), model).toString(); QueryLogRecord r = new QueryLogRecordImpl(null, optionalEndpoint.get(), expr , EmptyBindingSet.getInstance(), Collections.<String>emptyList()); //r.setDuration(startTime, endTime); r.setCardinality(cardinality); r.setDuration(startTime.getTime(), endTime.getTime()); r.setResults(optionalResults.get()); return r; }
Example #19
Source File: AbstractNTriplesParserUnitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEndOfLineEmptyCommentWithSpaceAfter() throws Exception { RDFParser ntriplesParser = createRDFParser(); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); ntriplesParser.parse(new StringReader("<urn:test:subject> <urn:test:predicate> <urn:test:object> .# \n"), "http://example/"); assertEquals(1, model.size()); assertEquals(Collections.singleton("urn:test:object"), Models.objectStrings(model)); }
Example #20
Source File: EtlIT.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void outputContentIsCorrect() throws Exception { org.eclipse.rdf4j.model.Model expected = Rio.parse(getBundleEntry(thisBundleContext, "/testOutput.ttl"), "", RDFFormat.TURTLE); org.eclipse.rdf4j.model.Model actual = Rio.parse(new FileInputStream(outputFile), "", RDFFormat.TURTLE); // TODO: I get around the UUID issue by setting the localname to values in the cells. We need to support IRI // isomorphism the same way bnode isomorphism is handled. assertTrue(Models.isomorphic(expected, actual)); }
Example #21
Source File: AbstractNTriplesParserUnitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEndOfLineCommentWithSpaceBoth() throws Exception { RDFParser ntriplesParser = createRDFParser(); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); ntriplesParser.parse( new StringReader("<urn:test:subject> <urn:test:predicate> <urn:test:object> . # endoflinecomment\n"), "http://example/"); assertEquals(1, model.size()); assertEquals(Collections.singleton("urn:test:object"), Models.objectStrings(model)); }
Example #22
Source File: AbstractNTriplesParserUnitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEndOfLineEmptyCommentWithSpaceBefore() throws Exception { RDFParser ntriplesParser = createRDFParser(); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); ntriplesParser.parse(new StringReader("<urn:test:subject> <urn:test:predicate> <urn:test:object> . #\n"), "http://example/"); assertEquals(1, model.size()); assertEquals(Collections.singleton("urn:test:object"), Models.objectStrings(model)); }
Example #23
Source File: AbstractNTriplesParserUnitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEndOfLineEmptyCommentNoSpace() throws Exception { RDFParser ntriplesParser = createRDFParser(); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); ntriplesParser.parse(new StringReader("<urn:test:subject> <urn:test:predicate> <urn:test:object> .#\n"), "http://example/"); assertEquals(1, model.size()); assertEquals(Collections.singleton("urn:test:object"), Models.objectStrings(model)); }
Example #24
Source File: RepositoryConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void parse(Model model, Resource repositoryNode) throws RepositoryConfigException { try { Models.objectLiteral(model.getStatements(repositoryNode, REPOSITORYID, null)) .ifPresent(lit -> setID(lit.getLabel())); Models.objectLiteral(model.getStatements(repositoryNode, RDFS.LABEL, null)) .ifPresent(lit -> setTitle(lit.getLabel())); Models.objectResource(model.getStatements(repositoryNode, REPOSITORYIMPL, null)) .ifPresent(res -> setRepositoryImplConfig(AbstractRepositoryImplConfig.create(model, res))); } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } }
Example #25
Source File: AbstractNTriplesParserUnitTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testEndOfLineEmptyCommentWithSpaceBoth() throws Exception { RDFParser ntriplesParser = createRDFParser(); Model model = new LinkedHashModel(); ntriplesParser.setRDFHandler(new StatementCollector(model)); ntriplesParser.parse(new StringReader("<urn:test:subject> <urn:test:predicate> <urn:test:object> . # \n"), "http://example/"); assertEquals(1, model.size()); assertEquals(Collections.singleton("urn:test:object"), Models.objectStrings(model)); }
Example #26
Source File: ContextAwareConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void parse(Model model, Resource resource) throws RepositoryConfigException { super.parse(model, resource); try { Models.objectLiteral(model.getStatements(resource, INCLUDE_INFERRED, null)) .ifPresent(lit -> setIncludeInferred(lit.booleanValue())); Models.objectLiteral(model.getStatements(resource, MAX_QUERY_TIME, null)) .ifPresent(lit -> setMaxQueryTime(lit.intValue())); Models.objectLiteral(model.getStatements(resource, QUERY_LANGUAGE, null)) .ifPresent(lit -> setQueryLanguage(QueryLanguage.valueOf(lit.getLabel()))); Models.objectIRI(model.getStatements(resource, QUERY_LANGUAGE, null)) .ifPresent(iri -> setBaseURI(iri.stringValue())); Set<Value> objects = model.filter(resource, READ_CONTEXT, null).objects(); setReadContexts(objects.toArray(new IRI[objects.size()])); objects = model.filter(resource, ADD_CONTEXT, null).objects(); setAddContexts(objects.toArray(new IRI[objects.size()])); objects = model.filter(resource, REMOVE_CONTEXT, null).objects(); setRemoveContexts(objects.toArray(new IRI[objects.size()])); objects = model.filter(resource, ARCHIVE_CONTEXT, null).objects(); setArchiveContexts(objects.toArray(new IRI[objects.size()])); Models.objectIRI(model.getStatements(resource, INSERT_CONTEXT, null)) .ifPresent(iri -> setInsertContext(iri)); } catch (ArrayStoreException e) { throw new RepositoryConfigException(e); } }
Example #27
Source File: RepositoryUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Compares the models of the default context of two repositories and returns true if rep1 is a subset of rep2. Note * that the method pulls the entire default context of both repositories into main memory. Use with caution. */ public static boolean isSubset(Repository rep1, Repository rep2) throws RepositoryException { Set<Statement> model1, model2; try (RepositoryConnection con1 = rep1.getConnection()) { model1 = Iterations.asSet(con1.getStatements(null, null, null, true)); } try (RepositoryConnection con2 = rep2.getConnection()) { model2 = Iterations.asSet(con2.getStatements(null, null, null, true)); } return Models.isSubset(model1, model2); }
Example #28
Source File: RepositoryUtil.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Compares the models in the default contexts of the two supplied repositories and returns true if they are equal. * Models are equal if they contain the same set of statements. bNodes IDs are not relevant for model equality, they * are mapped from one model to the other by using the attached properties. Note that the method pulls the entire * default context of both repositories into main memory. Use with caution. */ public static boolean equals(Repository rep1, Repository rep2) throws RepositoryException { // Fetch statements from rep1 and rep2 Set<Statement> model1, model2; try (RepositoryConnection con1 = rep1.getConnection()) { model1 = Iterations.asSet(con1.getStatements(null, null, null, true)); } try (RepositoryConnection con2 = rep2.getConnection()) { model2 = Iterations.asSet(con2.getStatements(null, null, null, true)); } return Models.isomorphic(model1, model2); }
Example #29
Source File: AbstractDelegatingRepositoryImplConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void parse(Model model, Resource resource) throws RepositoryConfigException { super.parse(model, resource); Models.objectResource(model.getStatements(resource, DELEGATE, null)) .ifPresent(delegate -> setDelegate(create(model, delegate))); }
Example #30
Source File: SPARQLRepositoryConfig.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void parse(Model m, Resource implNode) throws RepositoryConfigException { super.parse(m, implNode); try { Models.objectIRI(m.getStatements(implNode, QUERY_ENDPOINT, null)) .ifPresent(iri -> setQueryEndpointUrl(iri.stringValue())); Models.objectIRI(m.getStatements(implNode, UPDATE_ENDPOINT, null)) .ifPresent(iri -> setUpdateEndpointUrl(iri.stringValue())); } catch (ModelException e) { throw new RepositoryConfigException(e.getMessage(), e); } }