com.hp.hpl.jena.sparql.core.Quad Java Examples

The following examples show how to use com.hp.hpl.jena.sparql.core.Quad. 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: RDFReader.java    From marklogic-contentpump with Apache License 2.0 6 votes vote down vote up
protected boolean nextStreamingQuadKeyValueIgnoreCollections() throws IOException, InterruptedException {
    if(rdfIter == null) return false;
    setKey();
    write("<sem:triples xmlns:sem='http://marklogic.com/semantics'>");
    int max = MAXTRIPLESPERDOCUMENT;
    while (max > 0 && rdfIter.hasNext()) {
        Quad quad = (Quad) rdfIter.next();
        write("<sem:triple>");
        write(subject(quad.getSubject()));
        write(predicate(quad.getPredicate()));
        write(object(quad.getObject()));
        write("</sem:triple>");
        notifyUser();
        max--;
    }
    write("</sem:triples>\n");

    if (!rdfIter.hasNext()) {
        pos = 1;
    }

    writeValue();
    return true;
}
 
Example #2
Source File: RdfBulkUpdateRequestHandler.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
@Override
public void load( 
		final SolrQueryRequest request, 
		final SolrQueryResponse response,
		final ContentStream stream, 
		final UpdateRequestProcessor processor) throws Exception {
	
	final PipedRDFIterator<Quad> iterator = new PipedRDFIterator<Quad>();
	final StreamRDF inputStream = new PipedQuadsStream(iterator);
	
	executor.submit(new Runnable() {
		@Override
		public void run() {
			try {
				RDFDataMgr.parse(
						inputStream, 
						stream.getStream(), 
						RDFLanguages.contentTypeToLang(stream.getContentType()));
			} catch (final IOException exception) {
				throw new SolrException(ErrorCode.SERVER_ERROR, exception);
			}					
		}
	});
	
	final DatasetGraph dataset = new LocalDatasetGraph(request, response);
	while (iterator.hasNext()) {
		dataset.add(iterator.next());
	}									
}
 
Example #3
Source File: ProcessEventObjectsStream.java    From EventCoreference with Apache License 2.0 5 votes vote down vote up
static public String matchSingleTmx(Node tmx, DatasetGraph g, Model m){
    String sq="";
    if (g.contains(null, tmx, typeNode, instantNode)) { // One Instant
        sq += "?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Instant> . ";
        for (Iterator<Quad> iter = g.find(null, tmx, specificTimeNode, null); iter.hasNext(); ) {
            Quad q = iter.next();
            sq += "?t <http://www.w3.org/TR/owl-time#inDateTime> <" + q.asTriple().getObject() + "> . ";
        }
    } else { // One Interval

        String intervalQuery = "SELECT ?begin ?end WHERE { <" + tmx + ">  <http://www.w3.org/TR/owl-time#hasBeginning> ?begin ; <http://www.w3.org/TR/owl-time#hasEnd> ?end . }";

        Query inQuery = QueryFactory.create(intervalQuery);

        // Create a single execution of this query, apply to a model
        // which is wrapped up as a Dataset
        QueryExecution inQexec = QueryExecutionFactory.create(inQuery, m);

        try {
            // Assumption: it’s a SELECT query.
            ResultSet inrs = inQexec.execSelect();
            // The order of results is undefined.
            for (; inrs.hasNext(); ) {
                QuerySolution evrb = inrs.nextSolution();
                // Get title - variable names do not include the ’?’
                String begin = evrb.get("begin").toString();
                String end = evrb.get("end").toString();

                String unionQuery = "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Interval> . ?t <http://www.w3.org/TR/owl-time#hasBeginning> <" + begin + "> ; <http://www.w3.org/TR/owl-time#hasEnd> <" + end + "> . } ";
                unionQuery += "UNION ";
                unionQuery += "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestBeginTimeStamp> ?t1 . ?t1 a <http://www.w3.org/TR/owl-time#Instant> . ?t1 <http://www.w3.org/TR/owl-time#inDateTime> <" + begin + "> . ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestEndTimeStamp> ?t2 . ?t2 a <http://www.w3.org/TR/owl-time#Instant> . ?t2 <http://www.w3.org/TR/owl-time#inDateTime> <" + end + "> . } ";
                sq += unionQuery;
            }
        } finally {
            inQexec.close();
        }
    }
    return sq;
}
 
Example #4
Source File: DatasetGraphSupertypeLayer.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
@Override
protected Iterator<Quad> findInDftGraph(final Node s, final Node p, final Node o) {
	return triples2quads(Quad.tripleInQuad, getDefaultGraph().find(s, p, o));
}
 
Example #5
Source File: DatasetGraphSupertypeLayer.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
@Override
protected Iterator<Quad> findInSpecificNamedGraph(final Node g, final Node s, final Node p, final Node o) {
	return triples2quads(g, getGraph(g).find(s, p, o));
}
 
Example #6
Source File: DatasetGraphSupertypeLayer.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
@Override
protected Iterator<Quad> findInAnyNamedGraphs(final Node s, final Node p, final Node o) {
	return triples2quads(Quad.tripleInQuad, getDefaultGraph().find(s, p, o));
}