Java Code Examples for com.hp.hpl.jena.graph.Node#getURI()

The following examples show how to use com.hp.hpl.jena.graph.Node#getURI() . 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: IntegrationTestSupertypeLayer.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
/**
 * Executes a given update command both on remote and local model.
 * 
 * @param data the object holding test data (i.e. commands, queries, datafiles).
 * @throws Exception hopefully never otherwise the corresponding test fails.
 */
protected void executeUpdate(final MisteryGuest data) throws Exception {
	load(data);
	
	final String updateCommandString = readFile(data.query);
	UpdateExecutionFactory.createRemote(UpdateFactory.create(updateCommandString), SPARQL_ENDPOINT_URI).execute();

	SOLRDF_CLIENT.commit();

	UpdateAction.parseExecute(updateCommandString, memoryDataset.asDatasetGraph());
	
	final Iterator<Node> nodes = memoryDataset.asDatasetGraph().listGraphNodes();
	if (nodes != null) {
		while (nodes.hasNext()) {
			final Node graphNode = nodes.next();
			final String graphUri = graphNode.getURI();
			final Model inMemoryNamedModel = memoryDataset.getNamedModel(graphUri);
			assertIsomorphic(inMemoryNamedModel, SOLRDF_CLIENT.getNamedModel(graphUri), graphUri);		
		}
	}
	
	assertIsomorphic(memoryDataset.getDefaultModel(), SOLRDF_CLIENT.getDefaultModel(), null);			
}
 
Example 2
Source File: TypeConversion.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Transforms a Jena node into a java object. Possible node types: uri,
 * variable, literal (datatype, languageTag), blank node
 * 
 * @param n The node to transform
 * @return A specific java object
 * @throws ModelRuntimeException from the underlying model
 */
public static org.ontoware.rdf2go.model.node.Node toRDF2Go(Node n) throws ModelRuntimeException {
	// A return of null indicates that the variable is not present in this
	// solution.
	if(n == null)
		return null;
	
	if(n.isURI())
		return new URIImpl(n.getURI());
	
	if(n.isVariable())
		throw new RuntimeException("Cannot convert a Jena variable to an RDF2Go node");
	
	if(n.isLiteral()) {
		LiteralLabel lit = n.getLiteral();
		// datatype
		if(lit.getDatatypeURI() != null) {
			return new DatatypeLiteralImpl(lit.getLexicalForm(), new URIImpl(
			        lit.getDatatypeURI()));
		}
		
		// language tagged
		if(lit.language() != null && !lit.language().equals(""))
			return new LanguageTagLiteralImpl(lit.getLexicalForm(), lit.language());
		
		// plain
		return new PlainLiteralImpl(lit.getLexicalForm());
	}
	
	if(n.isBlank())
		return new JenaBlankNode(n);
	
	// none of the above - don't know how to transform that
	throw new RuntimeException("no transformation defined from " + n + " to java");
}
 
Example 3
Source File: IntegrationTestSupertypeLayer.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
/**
 * Loads all triples found in the datafile associated with the given name.
 * 
 * @param datafileName the name of the datafile.
 * @param graphs an optional set of target graph URIs. 
 * @throws Exception hopefully never, otherwise the test fails.
 */
protected void load(final MisteryGuest data) throws Exception {
	if (data.datasets == null || data.datasets.length == 0) {
		return;
	}
	
	final Model memoryModel = data.graphURI != null 
			? memoryDataset.getNamedModel(data.graphURI) 
			: memoryDataset.getDefaultModel();
			 
	for (final String datafileName : data.datasets) {
		final String dataURL = source(datafileName).toString();
		final String lang = datafileName.endsWith("ttl") 
				? "TTL" 
				: datafileName.endsWith("nt") 
					? "N-TRIPLES" 
					: null;
		memoryModel.read(dataURL, DUMMY_BASE_URI, lang);
	}  
 
	if (data.graphURI != null) {
		SOLRDF_CLIENT.add(data.graphURI, memoryModel.listStatements());
	} else {
		SOLRDF_CLIENT.add(memoryModel.listStatements());
	}
	
	SOLRDF_CLIENT.commit();
	
	final Iterator<Node> nodes = memoryDataset.asDatasetGraph().listGraphNodes();
	if (nodes != null) {
		while (nodes.hasNext()) {
			final Node graphNode = nodes.next();
			final String graphUri = graphNode.getURI();
			final Model inMemoryNamedModel = memoryDataset.getNamedModel(graphUri);
			assertIsomorphic(inMemoryNamedModel, SOLRDF_CLIENT.getNamedModel(graphUri), graphUri);		
		}
	}
	
	final Model model = (data.graphURI != null) ? SOLRDF_CLIENT.getNamedModel(data.graphURI) : SOLRDF_CLIENT.getDefaultModel();
	assertFalse(Arrays.toString(data.datasets) + ", " + data.query, model.isEmpty());
	assertIsomorphic(memoryModel, model, null);
}
 
Example 4
Source File: MisteryGuest.java    From SolRDF with Apache License 2.0 2 votes vote down vote up
/**
 * Factory method. 
 * 
 * @param datasetsFilenames one or more datafile that contains data.
 * @param graphURI the target graphURI.
 * @param queryFilename the name of the file containing the SPARQL query for a given test.
 * @return new {@link MisteryGuest} instance.
 */
public static MisteryGuest misteryGuest(final String queryFilename, final Node graphURI, final String ... datasetsFilenames) {
	return new MisteryGuest(queryFilename, graphURI.getURI(), datasetsFilenames);
}
 
Example 5
Source File: MisteryGuest.java    From SolRDF with Apache License 2.0 2 votes vote down vote up
/**
 * Factory method. 
 * 
 * @param datasetsFilenames one or more datafile that contains data.
 * @param graphURI the target graphURI.
 * @param queryFilename the name of the file containing the SPARQL query for a given test.
 * @return new {@link MisteryGuest} instance.
 */
public static MisteryGuest misteryGuest(final String queryFilename, final Node graphURI, final String ... datasetsFilenames) {
	return new MisteryGuest(queryFilename, graphURI.getURI(), datasetsFilenames);
}
 
Example 6
Source File: TypedNodeMaker.java    From GeoTriples with Apache License 2.0 votes vote down vote up
public String extractValue(Node node) { return node.getURI(); }