Java Code Examples for org.eclipse.rdf4j.model.Model#filter()

The following examples show how to use org.eclipse.rdf4j.model.Model#filter() . 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: SPARQLGraphRepositoryInformation.java    From CostFed with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void initialize(Model graph, Resource repNode) {
	
	// name: the node's value
	setProperty("name", repNode.stringValue());
			
	// location		
	Model location = graph.filter(repNode, SimpleValueFactory.getInstance().createIRI("http://fluidops.org/config#SPARQLEndpoint"), null);
	String repoLocation = location.iterator().next().getObject().stringValue();;
	setProperty("location", repoLocation);
	
	// id: the name of the location
	String id = repNode.stringValue().replace("http://", "");
	id = "sparql_" + id.replace("/", "_");
	setProperty("id", id);
	
	// endpoint configuration (if specified)
	if (hasAdditionalSettings(graph, repNode)) {
		SparqlEndpointConfiguration c = new SparqlEndpointConfiguration();
		
		if (graph.contains(repNode, SimpleValueFactory.getInstance().createIRI("http://fluidops.org/config#supportsASKQueries"), SimpleValueFactory.getInstance().createLiteral("false")))
			c.setSupportsASKQueries(false);
		
		setEndpointConfiguration(c);
	}
}
 
Example 2
Source File: RemoteRepositoryGraphRepositoryInformation.java    From CostFed with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void initialize(Model graph, Resource repNode) {
	
	// name: the node's value
	setProperty("name", repNode.stringValue());

	// repositoryServer / location
	Model repositoryServer = graph.filter(repNode, SimpleValueFactory.getInstance().createIRI("http://fluidops.org/config#repositoryServer"), null);
	String repoLocation = repositoryServer.iterator().next().getObject().stringValue();
	setProperty("location", repoLocation);
	setProperty("repositoryServer", repoLocation);
	
	// repositoryName
	Model repositoryName = graph.filter(repNode, SimpleValueFactory.getInstance().createIRI("http://fluidops.org/config#repositoryName"), null);
	String repoName = repositoryName.iterator().next().getObject().stringValue();
	setProperty("repositoryName", repoName);
	
	// id: the name of the location
	String id = repNode.stringValue().replace("http://", "");
	id = "remote_" + id.replace("/", "_");
	setProperty("id", id);
}
 
Example 3
Source File: RemoteRepositoryRepositoryInformation.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void initialize(Model graph, Resource repNode) {

		// name: the node's value
		setProperty("name", repNode.stringValue());

		// repositoryServer / location
		Model repositoryServer = graph.filter(repNode, Vocabulary.FEDX.REPOSITORY_SERVER,
				null);
		String repoLocation = repositoryServer.iterator().next().getObject().stringValue();
		setProperty("location", repoLocation);
		setProperty("repositoryServer", repoLocation);

		// repositoryName
		Model repositoryName = graph.filter(repNode, Vocabulary.FEDX.REPOSITORY_NAME, null);
		String repoName = repositoryName.iterator().next().getObject().stringValue();
		setProperty("repositoryName", repoName);

		// id: the name of the location
		String id = repNode.stringValue().replace("http://", "");
		id = "remote_" + id.replace("/", "_");
		setProperty("id", id);
	}
 
Example 4
Source File: Models.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static List<Statement> findMatchingStatements(Statement st, Model model,
		Map<Resource, Resource> bNodeMapping) {
	Resource s = isBlank(st.getSubject()) ? null : st.getSubject();
	IRI p = st.getPredicate();
	Value o = isBlank(st.getObject()) ? null : st.getObject();
	Resource[] g = isBlank(st.getContext()) ? new Resource[0] : new Resource[] { st.getContext() };
	List<Statement> result = new ArrayList<>();

	for (Statement modelSt : model.filter(s, p, o, g)) {
		if (statementsMatch(st, modelSt, bNodeMapping)) {
			// All components possibly match
			result.add(modelSt);
		}
	}

	return Collections.unmodifiableList(result);
}
 
Example 5
Source File: RDFWriterTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testWriteOneStatementsObjectBNodeSinglePredicateSingleContextBNodeReusedWithNamespace()
		throws Exception {
	Model input = new LinkedHashModel();
	input.setNamespace("ex", exNs);
	input.add(vf.createStatement(uri1, uri1, bnode, bnode));
	ByteArrayOutputStream outputWriter = new ByteArrayOutputStream();
	write(input, outputWriter);
	ByteArrayInputStream inputReader = new ByteArrayInputStream(outputWriter.toByteArray());
	Model parsedOutput = parse(inputReader, "");
	assertEquals(1, parsedOutput.size());
	Model doubleBNodeStatement = parsedOutput.filter(uri1, uri1, null);
	assertEquals(1, doubleBNodeStatement.size());
	assertEquals(1, parsedOutput.contexts().size());
	if (rdfWriterFactory.getRDFFormat().supportsContexts()) {
		assertTrue(parsedOutput.contexts().iterator().next() instanceof BNode);
	}
	assertEquals(1, parsedOutput.objects().size());
	assertTrue(parsedOutput.objects().iterator().next() instanceof BNode);
	assertTrue(doubleBNodeStatement.objects().iterator().next() instanceof BNode);
	if (rdfWriterFactory.getRDFFormat().supportsContexts()) {
		assertEquals(doubleBNodeStatement.objects().iterator().next(),
				doubleBNodeStatement.contexts().iterator().next());
	}
}
 
Example 6
Source File: NativeGraphRepositoryInformation.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void initialize(Model graph, Resource repNode) {
	
	// name: the node's value
	setProperty("name", repNode.stringValue());
			
	// location
	Model location = graph.filter(repNode, SimpleValueFactory.getInstance().createIRI("http://fluidops.org/config#RepositoryLocation"), null);
	
	String repoLocation = location.iterator().next().getObject().stringValue();
	setProperty("location", repoLocation);
	
	// id: the name of the location
	setProperty("id", new File(repoLocation).getName());
}
 
Example 7
Source File: SPARQLRepositoryInformation.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void initialize(Model graph, Resource repNode) {

		// name: the node's value
		setProperty("name", repNode.stringValue());

		// location
		Model location = graph.filter(repNode, Vocabulary.SD.ENDPOINT, null);
		String repoLocation = location.iterator().next().getObject().stringValue();
		;
		setProperty("location", repoLocation);

		// id: the name of the location
		String id = repNode.stringValue().replace("http://", "");
		id = "sparql_" + id.replace("/", "_");
		setProperty("id", id);

		// endpoint configuration (if specified)
		if (hasAdditionalSettings(graph, repNode)) {
			SparqlEndpointConfiguration c = new SparqlEndpointConfiguration();

			if (graph.contains(repNode, Vocabulary.FEDX.SUPPORTS_ASK_QUERIES, FedXUtil.literal("false"))
					|| graph.contains(repNode, Vocabulary.FEDX.SUPPORTS_ASK_QUERIES,
							FedXUtil.valueFactory().createLiteral(false))) {
				c.setSupportsASKQueries(false);
			}

			setEndpointConfiguration(c);
		}
	}
 
Example 8
Source File: ResolvableRepositoryInformation.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void initialize(Model graph, Resource repNode) {

		// name: the node's value
		setProperty("name", repNode.stringValue());

		// location
		Model repositoryId = graph.filter(repNode, Vocabulary.FEDX.REPOSITORY_NAME, null);
		String repoId = repositoryId.iterator().next().getObject().stringValue();

		setProperty("location", location(repoId));

		// id: the name of the location
		String id = repoId;
		setProperty("id", id);
	}
 
Example 9
Source File: RepositoryConfigUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}
 
Example 10
Source File: RepositoryConfigUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Model getRepositoryConfigModel(Model model, String repositoryID) {
	Statement idStatement = getIDStatement(model, repositoryID);
	if (idStatement == null) {
		// No such config
		return null;
	}
	return model.filter(null, null, null, idStatement.getContext());
}
 
Example 11
Source File: RepositoryConfigUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Statement getIDStatement(Model model, String repositoryID) {
	Literal idLiteral = SimpleValueFactory.getInstance().createLiteral(repositoryID);
	Model idStatementList = model.filter(null, REPOSITORYID, idLiteral);

	if (idStatementList.size() == 1) {
		return idStatementList.iterator().next();
	} else if (idStatementList.isEmpty()) {
		return null;
	} else {
		throw new RepositoryConfigException("Multiple ID-statements for repository ID " + repositoryID);
	}
}
 
Example 12
Source File: RDFWriterTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testWriteTwoStatementsObjectBNodeSinglePredicateSingleContextBNodeReusedWithNamespace()
		throws Exception {
	Model input = new LinkedHashModel();
	input.setNamespace("ex", exNs);
	input.add(vf.createStatement(uri1, uri1, bnodeSingleUseObject, bnode));
	input.add(vf.createStatement(bnode, uri2, bnodeSingleUseObject, bnode));
	ByteArrayOutputStream outputWriter = new ByteArrayOutputStream();
	write(input, outputWriter);
	ByteArrayInputStream inputReader = new ByteArrayInputStream(outputWriter.toByteArray());
	Model parsedOutput = parse(inputReader, "");
	assertEquals(2, parsedOutput.size());
	Model doubleBNodeStatement = parsedOutput.filter(uri1, uri1, null);
	assertEquals(1, doubleBNodeStatement.size());
	Model tripleBNodeStatement = parsedOutput.filter(null, uri2, null);
	assertEquals(1, tripleBNodeStatement.size());
	assertEquals(1, parsedOutput.contexts().size());
	if (rdfWriterFactory.getRDFFormat().supportsContexts()) {
		assertTrue(parsedOutput.contexts().iterator().next() instanceof BNode);
	}
	assertEquals(1, parsedOutput.objects().size());
	assertTrue(parsedOutput.objects().iterator().next() instanceof BNode);
	assertTrue(tripleBNodeStatement.subjects().iterator().next() instanceof BNode);
	if (rdfWriterFactory.getRDFFormat().supportsContexts()) {
		assertEquals(tripleBNodeStatement.subjects().iterator().next(),
				doubleBNodeStatement.contexts().iterator().next());
	}
}