Java Code Examples for org.openrdf.model.Statement#getContext()

The following examples show how to use org.openrdf.model.Statement#getContext() . 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: AbstractDataAndSPARQLTestCase.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@Override
            public void handleStatement(final Statement stmt)
                    throws RDFHandlerException {

                final Resource s = stmt.getSubject();
                final URI p = stmt.getPredicate();
                final Value o = stmt.getObject();
                final Resource c = stmt.getContext() == null ? this.context
                        : stmt.getContext();

//                if (log.isDebugEnabled())
//                    log.debug("<" + s + "," + p + "," + o + "," + c + ">");

                buffer.add(s, p, o, c, StatementEnum.Explicit);

                n++;

            }
 
Example 2
Source File: DeleteServlet.java    From database with GNU General Public License v2.0 6 votes vote down vote up
private void doRemoveStatement(final Statement stmt) throws SailException {

         final Resource[] c = (Resource[]) (stmt.getContext() == null ? defaultContext
               : new Resource[] { stmt.getContext() });

         conn.removeStatements(//
               stmt.getSubject(), //
               stmt.getPredicate(), //
               stmt.getObject(), //
               c);

         if (c.length >= 2) {
            // removed from more than one context
            nmodified.addAndGet(c.length);
         } else {
            nmodified.incrementAndGet();
         }

      }
 
Example 3
Source File: HTMLWriter.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
public void handleStatement(Statement arg0) throws RDFHandlerException {

	try {

		_writer.write("<p>");
		NTriplesUtil.append(arg0.getSubject(), _writer);
		_writer.write(" ");
		NTriplesUtil.append(arg0.getPredicate(), _writer);
		_writer.write(" ");
		NTriplesUtil.append(arg0.getObject(), _writer);

		if (arg0.getContext() != null) {
			_writer.write(" ");
			NTriplesUtil.append(arg0.getContext(), _writer);
		}

		_writer.write(" .");
		_writer.write("<p/>");

	} catch (IOException e) {
		throw new RDFHandlerException(e);
	}
}
 
Example 4
Source File: GraphLoader.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleStatement(final Statement stmt)
        throws RDFHandlerException {

    final Resource[] c = (Resource[]) 
            (stmt.getContext() == null 
            ?  defaultContext
            : new Resource[] { stmt.getContext() }); 
    
    addStatement(stmt, c);

}
 
Example 5
Source File: InsertServlet.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleStatement(final Statement stmt)
        throws RDFHandlerException {

	final Resource[] c = (Resource[]) 
			(stmt.getContext() == null 
			?  defaultContext
            : new Resource[] { stmt.getContext() }); 
	
    try {

        conn.addStatement(//
                stmt.getSubject(), //
                stmt.getPredicate(), //
                stmt.getObject(), //
                c
                );

    } catch (SailException e) {

        throw new RDFHandlerException(e);

    }

    if (c.length >= 2) {
        // added to more than one context
        nmodified.addAndGet(c.length);
    } else {
        nmodified.incrementAndGet();
    }

}
 
Example 6
Source File: DeleteServlet.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleStatement(final Statement stmt)
        throws RDFHandlerException {

	final Resource[] c = (Resource[]) 
			(stmt.getContext() == null 
			?  defaultContext
            : new Resource[] { stmt.getContext() }); 
	
    try {

        conn.removeStatements(//
                stmt.getSubject(), //
                stmt.getPredicate(), //
                stmt.getObject(), //
                c
                );

    } catch (SailException e) {

        throw new RDFHandlerException(e);

    }

    if (c.length >= 2) {
        // removed from more than one context
        nmodified.addAndGet(c.length);
    } else {
        nmodified.incrementAndGet();
    }

}
 
Example 7
Source File: BigdataSPARQLResultsJSONWriterForConstruct.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("subject", st.getSubject());
    bs.addBinding("predicate", st.getPredicate());
    bs.addBinding("object", st.getObject());
    if (st.getContext() != null)
        bs.addBinding("context", st.getContext());
    try {
        writer.handleSolution(bs);
    } catch (TupleQueryResultHandlerException e) {
        throw new RDFHandlerException(e);
    }
}
 
Example 8
Source File: Util.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a statement to an array of its RDF values.
 * 
 * @param stmt - statement to be converted
 * @return array containing the RDF values comprised in the statement.
 */
public static Value[] toValueArray(Statement stmt) {

	Value[] out = new Value[stmt.getContext() == null ? 3 : 4];
	out[0] = stmt.getSubject();
	out[1] = stmt.getPredicate();
	out[2] = stmt.getObject();

	if (stmt.getContext() != null) {
		out[3] = stmt.getContext();
	}

	return out;
}
 
Example 9
Source File: RangeEvaluationStrategy.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(RangeStatementPattern sp, final BindingSet bindings)
		throws QueryEvaluationException {

	CloseableIteration<? extends Statement, QueryEvaluationException> stIter = null;

	if (tripleSource instanceof CumulusRDFSailConnection.CumulusRDFTripleSource) {

		final Var subjVar = sp.getSubjectVar();
		final Var predVar = sp.getPredicateVar();
		final Var objVar = sp.getObjectVar();
		final Var conVar = sp.getContextVar();

		final boolean upper_equals = sp.getUpperBoundEquals(), lower_equals = sp.getLowerBoundEquals();

		final Value subjValue = getVarValue(subjVar, bindings);
		final Value predValue = getVarValue(predVar, bindings);

		final boolean reverse = !sp.isAscending();

		stIter = ((CumulusRDFSailConnection.CumulusRDFTripleSource) tripleSource).getRangeStatements((Resource) subjValue, (URI) predValue,
				sp.getLowerBound(), lower_equals, sp.getUpperBound(), upper_equals, sp.getEquals(), reverse);

		return new ConvertingIteration<Statement, BindingSet, QueryEvaluationException>(stIter) {

			@Override
			protected BindingSet convert(Statement st) {
				QueryBindingSet result = new QueryBindingSet(bindings);

				if (subjVar != null && !result.hasBinding(subjVar.getName())) {
					result.addBinding(subjVar.getName(), st.getSubject());
				}
				if (predVar != null && !result.hasBinding(predVar.getName())) {
					result.addBinding(predVar.getName(), st.getPredicate());
				}
				if (objVar != null && !result.hasBinding(objVar.getName())) {
					result.addBinding(objVar.getName(), st.getObject());
				}
				if (conVar != null && !result.hasBinding(conVar.getName()) && st.getContext() != null) {
					result.addBinding(conVar.getName(), st.getContext());
				}

				return result;
			}
		};

	} else {
		throw new UnsupportedOperationException("RangeEvaluationStrategy can only be used with CumulusRdfStore!");
	}

}
 
Example 10
Source File: HashCollisionUtility.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public void handleStatement(final Statement stmt)
		throws RDFHandlerException {

	if (!parsing.get()) {
		// Either shutdown or never started.
		throw new IllegalStateException();
	}

	try {

		bufferValue((BigdataValue) stmt.getSubject());

		bufferValue((BigdataValue) stmt.getPredicate());

		bufferValue((BigdataValue) stmt.getObject());

		if (stmt.getContext() != null) {

			bufferValue((BigdataValue) stmt.getContext());

		}

	} catch (InterruptedException ex) {
		
		// Interrupted while blocked on the valueQueue
		throw new RDFHandlerException(ex);
		
	}

	c.nstmts.incrementAndGet();

}
 
Example 11
Source File: PresortRioLoader.java    From database with GNU General Public License v2.0 3 votes vote down vote up
@Override
public void handleStatement(final Statement stmt) {

    if (log.isDebugEnabled()) {

        log.debug(stmt);
        
    }

    Resource graph = stmt.getContext() ;
    
    if (null == graph && null != defaultGraphURI) {
        
        /*
         * Only true when we know we are loading a quad store.
         */

        graph = defaultGraphURI;
        
    }

    // buffer the write (handles overflow).
    buffer.add(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(),
            graph);

    stmtsAdded++;
    
    if ( stmtsAdded % 100000 == 0 ) {
        
        notifyListeners();
        
    }
    
}
 
Example 12
Source File: ParseOp.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public void handleStatement(final Statement stmt)
        throws RDFHandlerException {

    final ListBindingSet bset = new ListBindingSet();
    
    bset.set(s, asConst(stmt.getSubject()));
    
    bset.set(p, asConst(stmt.getPredicate()));
    
    bset.set(o, asConst(stmt.getObject()));

    Resource context = stmt.getContext();
    
    if (stripContext) {
        
        // Strip off the context position.
        context = null;
    }

    if (quads && context == null) {

        // Use the default context.
        context = targetUri;
        
    }

    if (quads && context == null) {

        throw new RuntimeException(
                "Quads mode, but data are triples and the target graph was not specified: "
                        + uriStr);

    }

    if (context != null) {

        /*
         * Bind [c] if available regardless of the database mode.
         * This stops people from loading quads data into a triples
         * or SIDs database in a way which throws away the context
         * when they are not expecting that.
         */

        bset.set(c, asConst(context));

    }

    unsyncBuffer.add(bset);

    stats.toldTriples.increment();

}