本文整理汇总了Java中org.openrdf.model.Statement.getContext方法的典型用法代码示例。如果您正苦于以下问题:Java Statement.getContext方法的具体用法?Java Statement.getContext怎么用?Java Statement.getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.model.Statement
的用法示例。
在下文中一共展示了Statement.getContext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeStatement
import org.openrdf.model.Statement; //导入方法依赖的package包/类
/**
* Write a {@link Statement} to a {@link String}
*
* @param statement
* the {@link Statement} to write
* @return a {@link String} representation of the statement
*/
public static String writeStatement(Statement statement) {
Resource subject = statement.getSubject();
Resource context = statement.getContext();
URI predicate = statement.getPredicate();
Value object = statement.getObject();
Validate.notNull(subject);
Validate.notNull(predicate);
Validate.notNull(object);
String s = "";
if (context == null) {
s = SEP + subject.toString() + SEP + predicate.toString() + SEP + object.toString();
} else {
s = context.toString() + SEP + subject.toString() + SEP + predicate.toString() + SEP + object.toString();
}
return s;
}
示例2: rewriteStatement
import org.openrdf.model.Statement; //导入方法依赖的package包/类
@Nullable
Statement rewriteStatement(@Nullable final Statement statement) {
if (statement == null) {
return null;
}
final Resource oldSubj = statement.getSubject();
final URI oldPred = statement.getPredicate();
final Value oldObj = statement.getObject();
final Resource oldCtx = statement.getContext();
final Resource newSubj = rewriteValue(oldSubj);
final URI newPred = rewriteValue(oldPred);
final Value newObj = rewriteValue(oldObj);
final Resource newCtx = rewriteValue(oldCtx);
if (oldSubj == newSubj && oldPred == newPred && oldObj == newObj && oldCtx == newCtx) {
return statement;
} else if (newCtx != null) {
return Data.getValueFactory().createStatement(newSubj, newPred, newObj, newCtx);
} else {
return Data.getValueFactory().createStatement(newSubj, newPred, newObj);
}
}
示例3: handleStatement
import org.openrdf.model.Statement; //导入方法依赖的package包/类
@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);
}
}
示例4: map
import org.openrdf.model.Statement; //导入方法依赖的package包/类
@Override
public Value[] map(final Statement statement) throws RDFHandlerException {
final String message = "Multiple annotation IDs in same statement";
Value key = null;
if (match(statement.getSubject())) {
key = statement.getSubject();
}
if (match(statement.getContext())) {
Preconditions.checkArgument(key == null, message);
key = statement.getContext();
}
if (match(statement.getObject())) {
Preconditions.checkArgument(key == null, message);
key = statement.getObject();
}
if (match(statement.getPredicate())) {
Preconditions.checkArgument(key == null, message);
key = statement.getPredicate();
}
if (key == null) {
key = Mapper.BYPASS_KEY;
}
return new Value[] { key };
}
示例5: getSparqlUpdate
import org.openrdf.model.Statement; //导入方法依赖的package包/类
private static String getSparqlUpdate() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
Model m = Rio.parse(stream, "", RDFFormat.TRIG);
StringBuffer updateStr = new StringBuffer();
updateStr.append("INSERT DATA {\n");
for (Statement s : m){
if (s.getContext() != null) {
updateStr.append("graph ");
updateStr.append(escape(s.getContext()));
updateStr.append("{ ");
}
updateStr.append(escape(s.getSubject()));
updateStr.append(" ");
updateStr.append(escape(s.getPredicate()));
updateStr.append(" ");
updateStr.append(escape(s.getObject()));
if (s.getContext() != null){
updateStr.append("}");
}
updateStr.append(" . \n");
}
updateStr.append("}");
return updateStr.toString();
}
示例6: queryAll
import org.openrdf.model.Statement; //导入方法依赖的package包/类
/**
* Handles all results of a query. Closes the query iterator when done.
* @param statement the {@link Statement} to query for. (not {@code null})
* @param rdfStatementHandler the {@link RDFHandler} to use for handling
* each statement returned. (not {@code null})
* @throws QueryEvaluationException
*/
public void queryAll(final Statement statement, final RDFHandler rdfStatementHandler) throws QueryEvaluationException {
final Resource subject = statement.getSubject();
final URI predicate = statement.getPredicate();
final Value object = statement.getObject();
final Resource context = statement.getContext();
queryAll(subject, predicate, object, rdfStatementHandler, context);
}
示例7: queryFirst
import org.openrdf.model.Statement; //导入方法依赖的package包/类
/**
* Handles only the first result of a query. Closes the query iterator when
* done.
* @param statement the {@link Statement} to query for. (not {@code null})
* @param rdfStatementHandler the {@link RDFHandler} to use for handling the
* first statement returned. (not {@code null})
* @throws QueryEvaluationException
*/
public void queryFirst(final Statement statement, final RDFHandler rdfStatementHandler) throws QueryEvaluationException {
checkNotNull(statement);
final Resource subject = statement.getSubject();
final URI predicate = statement.getPredicate();
final Value object = statement.getObject();
final Resource context = statement.getContext();
queryFirst(subject, predicate, object, rdfStatementHandler, context);
}
示例8: accept
import org.openrdf.model.Statement; //导入方法依赖的package包/类
/**
* Return whether a concrete statement satisfies a condition.
* @param stmt A statement from the input
* @param condition The condition to test. Expects variables expressed using the standard variable
* names used by this class, so it must be a rule's condition or derived from rules' conditions.
* @param strategy The evaluation strategy to apply
* @return True if the statement matches the condition
* @throws ValueExprEvaluationException
* @throws QueryEvaluationException
*/
public static boolean accept(final Statement stmt, final ValueExpr condition, final EvaluationStrategy strategy)
throws ValueExprEvaluationException, QueryEvaluationException {
final QueryBindingSet bindings = new QueryBindingSet();
bindings.addBinding(SUBJ_VAR.getName(), stmt.getSubject());
bindings.addBinding(PRED_VAR.getName(), stmt.getPredicate());
bindings.addBinding(OBJ_VAR.getName(), stmt.getObject());
if (stmt.getContext() != null) {
bindings.addBinding(CON_VAR.getName(), stmt.getContext());
}
return strategy.isTrue(condition, bindings);
}
示例9: normalize
import org.openrdf.model.Statement; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Nullable
public <T> T normalize(@Nullable final T object) {
if (object instanceof Statement) {
if (!(object instanceof StatementImpl) && !(object instanceof ContextStatementImpl)) {
final Statement s = (Statement) object;
return s.getContext() == null ? (T) createStatement(s.getSubject(),
s.getPredicate(), s.getObject()) : (T) createStatement(s.getSubject(),
s.getPredicate(), s.getObject(), s.getContext());
}
} else if (object instanceof URI) {
if (!(object instanceof URIImpl)) {
return (T) createURI(((URI) object).stringValue());
}
} else if (object instanceof BNode) {
if (!(object instanceof BNodeImpl)) {
return (T) createBNode(((BNode) object).getID());
}
} else if (object instanceof Literal) {
if (!(object instanceof StringLiteral) && !(object instanceof NumberLiteral)
&& !(object instanceof BooleanLiteralImpl)
&& !(object instanceof CalendarLiteralImpl)) {
final Literal l = (Literal) object;
return l.getLanguage() != null ? (T) createLiteral(l.getLabel(), l.getLanguage())
: (T) createLiteral(l.getLabel(), l.getDatatype());
}
}
return object;
}
示例10: toValueArray
import org.openrdf.model.Statement; //导入方法依赖的package包/类
/**
* 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;
}
示例11: renderTriplesTable
import org.openrdf.model.Statement; //导入方法依赖的package包/类
public void renderTriplesTable(final Appendable out, final Model model) throws IOException {
out.append("<table class=\"table table-condensed datatable\">\n<thead>\n");
out.append("<tr><th width='25%' class='col-ts'>");
out.append(shorten(RDF.SUBJECT));
out.append("</th><th width='25%' class='col-tp'>");
out.append(shorten(RDF.PREDICATE));
out.append("</th><th width='25%' class='col-to'>");
out.append(shorten(RDF.OBJECT));
out.append("</th><th width='25%' class='col-te'>");
out.append(shorten(KS.EXPRESSED_BY));
out.append("</th></tr>\n");
out.append("</thead>\n<tbody>\n");
for (final Statement statement : this.statementComparator.sortedCopy(model)) {
if (statement.getContext() != null) {
out.append("<tr><td>");
renderObject(out, statement.getSubject(), model);
out.append("</td><td>");
renderObject(out, statement.getPredicate(), model);
out.append("</td><td>");
renderObject(out, statement.getObject(), model);
out.append("</td><td>");
String separator = "";
for (final Value mentionID : model.filter(statement.getContext(), KS.EXPRESSED_BY,
null).objects()) {
final String extent = model.filter((Resource) mentionID, NIF.ANCHOR_OF, null)
.objectLiteral().stringValue();
out.append(separator);
renderObject(out, mentionID, model);
out.append(" '").append(escape(extent)).append("'");
separator = "<br/>";
}
out.append("</ol></td></tr>\n");
}
}
out.append("</tbody>\n</table>\n");
}
示例12: writeContext
import org.openrdf.model.Statement; //导入方法依赖的package包/类
public static String writeContext(Statement statement) {
if (statement.getContext() == null) {
return "";
}
return statement.getContext().toString();
}
示例13: update
import org.openrdf.model.Statement; //导入方法依赖的package包/类
private void update(final boolean insert, final Iterable<? extends Statement> statements)
throws IOException, IllegalStateException {
// try {
// VirtuosoTransaction.this.connection.prepareCall("log_enable(2)").execute();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// Check arguments and state
Preconditions.checkNotNull(statements);
checkWritable();
try {
String command = "DB.DBA.rdf_insert_triple_c (?,?,?,?,?,?)";
if (!insert) {
command = "DB.DBA.rdf_delete_triple_c (?,?,?,?,?,?)";
}
PreparedStatement insertStmt;
insertStmt = this.connection.prepareStatement(command);
for (Statement stmt : statements) {
insertStmt.setString(1, stmt.getSubject().toString());
insertStmt.setString(2, stmt.getPredicate().toString());
if (stmt.getObject() instanceof Resource) {
insertStmt.setString(3, stmt.getObject().toString());
insertStmt.setNull(4, 12);
insertStmt.setInt(5, 0);
}
else if (stmt.getObject() instanceof Literal) {
Literal lit = (Literal) stmt.getObject();
insertStmt.setString(3, lit.getLabel());
if (lit.getLanguage() != null) { // NOTA: LANGUAGE VA CONTROLLATO ***PRIMA*** DI DATATYPE
insertStmt.setString(4, lit.getLanguage());
insertStmt.setInt(5, 2);
}
else if (lit.getDatatype() != null) {
insertStmt.setString(4, lit.getDatatype().toString());
insertStmt.setInt(5, 3);
}
else {
insertStmt.setNull(4, 12);
insertStmt.setInt(5, 1);
}
}
Resource context = stmt.getContext();
if (context == null) {
context = SESAME.NIL;
}
insertStmt.setString(6, context.toString());
insertStmt.addBatch();
}
LOGGER.info("Starting Virtuoso ingestion");
insertStmt.executeBatch();
LOGGER.info("Finishing Virtuoso ingestion (burp!)");
insertStmt.clearBatch();
insertStmt.close();
// LOGGER.info("Starting checkpoint");
// try {
// VirtuosoTransaction.this.connection.prepareCall("checkpoint").execute();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// LOGGER.info("Ending checkpoint");
} catch (final SQLException ex) {
throw new IOException(ex);
}
}
示例14: evaluate
import org.openrdf.model.Statement; //导入方法依赖的package包/类
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!");
}
}