org.openrdf.model.Value Java Examples
The following examples show how to use
org.openrdf.model.Value.
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: RepositoryModel.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
@Override public ClosableIterator<org.ontoware.rdf2go.model.Statement> findStatements( ResourceOrVariable subject, UriOrVariable predicate, NodeOrVariable object) throws ModelRuntimeException { assertModel(); // convert parameters to OpenRDF data types org.openrdf.model.Resource openRdfSubject = (org.openrdf.model.Resource)ConversionUtil .toOpenRDF(subject, this.valueFactory); org.openrdf.model.URI openRdfPredicate = (org.openrdf.model.URI)ConversionUtil.toOpenRDF( predicate, this.valueFactory); Value openRdfObject = ConversionUtil.toOpenRDF(object, this.valueFactory); try { // find the matching statements CloseableIteration<? extends org.openrdf.model.Statement,? extends OpenRDFException> statements = this.connection .getStatements(openRdfSubject, openRdfPredicate, openRdfObject, true, this.openRdfContext); // wrap them in a StatementIterable return new StatementIterator(statements, this); } catch(RepositoryException e) { throw new ModelRuntimeException(e); } }
Example #2
Source File: TripleStore.java From cumulusrdf with Apache License 2.0 | 6 votes |
@Override public Iterator<byte[][]> rangeDateTimeAsIDs( final Value[] query, final Literal lower, final boolean equalsLower, final Literal upper, final boolean equalsUpper, final boolean reverse, final int limit) throws DataAccessLayerException { if (query == null || query.length != 2 || isVariable(query[1])) { return Iterators.emptyIterator(); } final long lowerBound = lower == null ? Long.MIN_VALUE : Util.parseXMLSchemaDateTimeAsMSecs(lower), upperBound = upper == null ? Long.MAX_VALUE : Util.parseXMLSchemaDateTimeAsMSecs(upper); return _rdfIndexDAO.dateRangeQuery(query, lowerBound, equalsLower, upperBound, equalsUpper, reverse, limit); }
Example #3
Source File: GPO.java From database with GNU General Public License v2.0 | 6 votes |
/** * A new value is only added if it does not already exist, ensuring the * GPO maintains semantics with the underlying TripleStore. * * @return true if value was added */ public boolean add(final GPO owner, final Value value) { final Iterator<Value> values = values(); while (values.hasNext()) { if (values.next().equals(value)) { return false; } } final LinkValue nv = new LinkValue(value); nv.m_next = m_addedValues; m_addedValues = nv; m_size++; return true; }
Example #4
Source File: AbstractRMLProcessor.java From GeoTriples with Apache License 2.0 | 6 votes |
@Override public Collection<Statement> processSubjectTypeMap(SesameDataSet dataset, Resource subject, SubjectMap subjectMap, Object node) { List<Statement> statements=new LinkedList<>(); ValueFactory myFactory = ValueFactoryImpl.getInstance(); // Add the type triples Set<org.openrdf.model.URI> classIRIs = subjectMap.getClassIRIs(); if (subject != null) for (org.openrdf.model.URI classIRI : classIRIs) { Statement st = myFactory.createStatement((Resource) subject, RDF.TYPE, (Value) classIRI); //dataset.add(subject, predicate, object); dataset.addStatement(st); statements.add(st); //dataset.add(subject, RDF.TYPE, classIRI); } return statements; }
Example #5
Source File: TestBigdataSailRemoteRepository.java From database with GNU General Public License v2.0 | 6 votes |
@Override protected long doDeleteWithAccessPath(// // final String servlet,// final URI s,// final URI p,// final Value o,// final URI... c// ) throws Exception { final long start = getExactSize(); cxn.remove(s, p, o, c); return start - getExactSize(); }
Example #6
Source File: LDPathWrapper.java From fcrepo-camel-toolbox with Apache License 2.0 | 6 votes |
/** * Create an LDPathWrapper Object * @param backend the linkeddata backend */ public LDPathWrapper(final LDCacheBackend backend) { // Register the Sesame RDF Parsers manually // TODO: use the OSGi service registry as described in: // http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html RDFParserRegistry.getInstance().add(new RDFXMLParserFactory()); RDFParserRegistry.getInstance().add(new NTriplesParserFactory()); RDFParserRegistry.getInstance().add(new TurtleParserFactory()); RDFParserRegistry.getInstance().add(new N3ParserFactory()); RDFParserRegistry.getInstance().add(new SesameJSONLDParserFactory()); RDFParserRegistry.getInstance().add(new RDFJSONParserFactory()); RDFParserRegistry.getInstance().add(new SesameRDFaParserFactory()); RDFParserRegistry.getInstance().add(new TriGParserFactory()); BooleanQueryResultParserRegistry.getInstance().add(new SPARQLBooleanXMLParserFactory()); TupleQueryResultParserRegistry.getInstance().add(new SPARQLResultsXMLParserFactory()); ldpath = new LDPath<Value>(backend); }
Example #7
Source File: DeletionTest.java From cumulusrdf with Apache License 2.0 | 6 votes |
/** * Adds and then removes triples. * * @throws Exception never, otherwise the tests fail. */ @Test public void testAddAndRemove() throws Exception { _tripleStore.addData(parseNX( "<http://izeus1.scc.kit.edu/id/i1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://gridpedia.org/id/TestType> . ") .iterator()); _tripleStore.addData(parseNX( "<http://izeus1.scc.kit.edu/id/i2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://gridpedia.org/id/TestType> . ") .iterator()); assertEquals(2, numOfRes(_tripleStore.query(new Value[] { null, RDF.TYPE, buildResource("http://gridpedia.org/id/TestType") }))); _tripleStore.removeData(_tripleStore.query(new Value[] { buildResource("http://izeus1.scc.kit.edu/id/i1"), null, null })); assertEquals(1, numOfRes(_tripleStore.query(new Value[] { null, RDF.TYPE, buildResource("http://gridpedia.org/id/TestType") }))); }
Example #8
Source File: RDFList.java From anno4j with Apache License 2.0 | 6 votes |
Value getFirst(Resource list) { if (list == null) return null; try { CloseableIteration<Value, RepositoryException> stmts; stmts = getValues(list, RDF.FIRST, null); try { if (stmts.hasNext()) return stmts.next(); return null; } finally { stmts.close(); } } catch (RepositoryException e) { throw new ObjectStoreException(e); } }
Example #9
Source File: BasicTripleHandler.java From anthelion with Apache License 2.0 | 6 votes |
public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context) throws TripleHandlerException { // if uri is in negative namespace which has to be filtered out and not // in the positive list - return directly for (String negativeFilterNamespace : negativeFilterNamespaces) { if (p.toString().startsWith(negativeFilterNamespace)) { for (String positiveFilterNamespace : positiveFilterNamespaces) { if (!p.toString().startsWith(positiveFilterNamespace)) { // log.debug("Namespace filtered: " // + s.toString() + " , " + p.toString() + ", " // + o.toString()); return; } } } } extractorNames.add(context.getExtractorName()); totalTriples++; wrapped.receiveTriple(s, p, o, g, context); }
Example #10
Source File: TransientValueDictionary.java From cumulusrdf with Apache License 2.0 | 6 votes |
@Override public Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { switch (id[0]) { case THRESHOLD_EXCEEDED: RUNTIME_CONTEXTS.get().isFirstLevelResult = false; return _longLiteralsDictionary.getValue(subarray(id, 1, id.length - 1), p); default: RUNTIME_CONTEXTS.get().isFirstLevelResult = true; final String n3 = new String(id, 2, id.length - 2, CHARSET_UTF8); if (id[1] == RESOURCE_BYTE_FLAG) { return NTriplesUtil.parseResource(n3, SESAME_VALUE_FACTORY); } else if (id[1] == LITERAL_BYTE_FLAG) { return NTriplesUtil.parseLiteral(n3, SESAME_VALUE_FACTORY); } else { return NTriplesUtil.parseBNode(n3, SESAME_VALUE_FACTORY); } } }
Example #11
Source File: AsynchronousStatementBufferFactory.java From database with GNU General Public License v2.0 | 6 votes |
/** * Wrap a {@link BigdataValue}[] with a chunked iterator. * <p> * Note: This resolves inline {@link IV}s and filters them out of the * visited {@link BigdataValue}s as a side-effect. */ @SuppressWarnings({ "unchecked", "rawtypes" }) static <V extends BigdataValue> IChunkedIterator<V> newValuesIterator( final LexiconRelation r, final Iterator<V> itr, final int chunkSize) { return new ChunkedWrappedIterator(new Striterator(itr) .addFilter(new Filter() { private static final long serialVersionUID = 1L; @Override public boolean isValid(final Object obj) { /* * Assigns the IV as a side effect iff the RDF Value can * be inlined according to the governing lexicon * configuration and returns true iff the value CAN NOT * be inlined. Thus, inlining is done as a side effect * while the caller sees only those Values which need to * be written onto the TERM2ID/BLOBS index. */ return r.getInlineIV((Value) obj) == null; } }), chunkSize, BigdataValue.class); }
Example #12
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testValuesInOptional() throws Exception { loadTestData("/testdata-query/dataset-ses1692.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/>\n"); query.append(" SELECT DISTINCT ?a ?name ?isX WHERE { ?b :p1 ?a . ?a :name ?name. OPTIONAL { ?a a :X . VALUES(?isX) { (:X) } } } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertTrue(result.hasNext()); int count = 0; while (result.hasNext()) { count++; BindingSet bs = result.next(); System.out.println(bs); URI a = (URI)bs.getValue("a"); assertNotNull(a); Value isX = bs.getValue("isX"); Literal name = (Literal)bs.getValue("name"); assertNotNull(name); if (a.stringValue().endsWith("a1")) { assertNotNull(isX); } else if (a.stringValue().endsWith(("a2"))) { assertNull(isX); } } assertEquals(2, count); }
Example #13
Source File: RDFSingleDataSet.java From mustard with MIT License | 5 votes |
@Override public List<Statement> getStatements(Resource subject, URI predicate, Value object, boolean allowInference) { List<Statement> resGraph = new ArrayList<Statement>(); try { RepositoryConnection repCon = rdfRep.getConnection(); try { RepositoryResult<Statement> statements = repCon.getStatements(subject, predicate, object, allowInference); try { while (statements.hasNext()) { resGraph.add(statements.next()); } } finally { statements.close(); } } finally { repCon.close(); } } catch (Exception e) { e.printStackTrace(); } return resGraph; }
Example #14
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
/** * aaa xxx bbb * xxx nrl:inverseProperty yyy * --> * bbb yyy aaa * @return * @throws SailException */ private int applyRuleN1b() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, null, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource xxx = nt.getPredicate(); CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(xxx,NRL_InverseProperty, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Value yyy = t1.getObject(); if (yyy instanceof URI) { Resource aaa = nt.getSubject(); Value bbb = nt.getObject(); boolean added = addInferredStatement((Resource)bbb, (URI) yyy, aaa); if (added) { nofInferred++; } } } t1Iter.close(); } return nofInferred; }
Example #15
Source File: BasicSkin.java From database with GNU General Public License v2.0 | 5 votes |
public int getIntValue(final URI key) { final Value v = m_gpo.getValue(key); if (v instanceof Literal) { return ((Literal) v).intValue(); } else { return 0; } }
Example #16
Source File: TupleQueryExecutor.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private Map<String, Value> getBindings(Map<String, Object> variables) { Map<String, Value> bindings = new HashMap<>(); for (Map.Entry<String, Object> stringObjectEntry : variables.entrySet()) { if (!stringObjectEntry.getValue().getClass().equals(Object.class)) bindings.put(stringObjectEntry.getKey(), ValueFactoryImpl.getInstance().createLiteral(stringObjectEntry.getValue().toString())); } return bindings; }
Example #17
Source File: BigdataSailRemoteRepositoryConnection.java From database with GNU General Public License v2.0 | 5 votes |
@Override public void exportStatements(final Resource s, final URI p, final Value o, final boolean includeInferred, final RDFHandler handler, final Resource... c) throws RepositoryException, RDFHandlerException { try { final RemoteRepository remote = repo.getRemoteRepository(); final GraphQueryResult src = remote.getStatements(s, p, o, includeInferred, c); try { handler.startRDF(); while (src.hasNext()) { handler.handleStatement(src.next()); } handler.endRDF(); } finally { src.close(); } } catch (Exception ex) { throw new RepositoryException(ex); } }
Example #18
Source File: QuadsDeletionTest.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Tests if the deletion of queries using the triple indexes works. * @throws CumulusStoreException If the deletion fails. */ @Test // different triple indexes public void testDeleteTripleIndexes() throws CumulusStoreException { /* * s ?p ?o ?c */ Value[] query = new Value[] {buildResource("a5"), null, null, null}; assertEquals(Arrays.toString(query), 2, TestUtils.numOfRes(_quadStore.query(query))); _quadStore.removeData(query); assertEmptyIterator(Arrays.toString(query), _quadStore.query(query)); query = new Value[] {buildResource("a1"), null, null, null}; assertEquals(Arrays.toString(query), 3, TestUtils.numOfRes(_quadStore.query(query))); _quadStore.removeData(query); assertEmptyIterator(Arrays.toString(query), _quadStore.query(query)); TestUtils.numOfRes(_quadStore.query(SELECT_ALL_QUADS_PATTERN)); /* * ?s p ?o ?c */ query = new Value[] {null, buildResource("b2"), null, null}; assertEquals(Arrays.toString(query), 1, TestUtils.numOfRes(_quadStore.query(query))); _quadStore.removeData(query); assertEmptyIterator(Arrays.toString(query), _quadStore.query(query)); /* * ?s ?p o ?c */ query = new Value[] {null, null, buildResource("c1"), null}; assertEquals(Arrays.toString(query), 1, TestUtils.numOfRes(_quadStore.query(query))); _quadStore.removeData(query); assertEmptyIterator(Arrays.toString(query), _quadStore.query(query)); }
Example #19
Source File: SparqlGenerator.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
private String sparql(final Value val) { if (val instanceof Literal) { return val.toString(); } else if (val instanceof URI) { return '<' + val.stringValue() + '>'; } else { throw new IllegalArgumentException(); } }
Example #20
Source File: ObjectMgrModel.java From database with GNU General Public License v2.0 | 5 votes |
@Deprecated // no need for explicit recall. public IGPO recallAsGPO(final URI key) { final Value val = recall(key); if (val instanceof Resource) { return getGPO((Resource) val); } else { return null; } }
Example #21
Source File: RDFClass.java From anno4j with Apache License 2.0 | 5 votes |
private boolean isRDFSOrOWL(Value sup) { if (self instanceof URI && sup instanceof URI) { String ns = ((URI) self).getNamespace(); return ns.equals(RDF.NAMESPACE) || ns.equals(RDFS.NAMESPACE) || ns.equals(OWL.NAMESPACE); } return false; }
Example #22
Source File: CumulusRDFValueFactory.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Creates a CumulusRDF native value from a given {@link Value}. * * @param value the incoming {@link Value}. * @return a CumulusRDF native value. */ public static Value makeNativeValue(final Value value) { if (value == null || value instanceof INativeCumulusValue) { return value; } if (value instanceof URI) { return new NativeCumulusURI(value.stringValue()); } else if (value instanceof Literal) { final Literal lit = (Literal) value; final String label = lit.getLabel(), language = lit.getLanguage(); final URI datatype = lit.getDatatype(); if (language != null) { return new NativeCumulusLiteral(label, language); } else if (datatype != null) { return new NativeCumulusLiteral(label, datatype); } else { return new NativeCumulusLiteral(label); } } else if (value instanceof BNode) { return new NativeCumulusBNode(value.stringValue()); } return value; }
Example #23
Source File: GPO.java From database with GNU General Public License v2.0 | 5 votes |
/** * initValue is called by ObjectManager materialize and resets the GPO * to its read state. Therefore the value is added to the m_values list * and not m_addedValues. */ public void initValue(final GPO owner, final Value value) { final LinkValue newValue = new LinkValue(value); newValue.m_next = m_values; m_values = newValue; m_size++; }
Example #24
Source File: RDFSContainer.java From anno4j with Apache License 2.0 | 5 votes |
private Object[] loadBlock(int b) throws RepositoryException, QueryEvaluationException { TupleQuery query = createBlockQuery(b); TupleQueryResult result = query.evaluate(); BindingSet bindings = result.next(); ObjectConnection con = getObjectConnection(); Object[] list = new Object[BSIZE]; while (bindings != null) { URI pred = (URI) bindings.getValue("pred"); int idx = getIndex(pred); Value value = bindings.getValue("value"); Set<URI> types = new HashSet<URI>(4); do { Value c = bindings.getValue("value_class"); if (c instanceof URI) { types.add((URI) c); } bindings = result.hasNext() ? result.next() : null; } while (bindings != null && pred.equals(bindings.getValue("pred"))); int i = idx % BSIZE; if (value instanceof Literal) { list[i] = con.getObject((Literal) value); } else { list[i] = con.getObject(types, (Resource) value); } } return list; }
Example #25
Source File: QuadStore.java From cumulusrdf with Apache License 2.0 | 5 votes |
@Override protected Iterator<byte[][]> queryAsIDs(final Value[] query, final int limit) throws CumulusStoreException { try { return queryWithIDs(_dictionary.getIDs(query[0], query[1], query[2], query.length > 3 ? query[3] : null), limit); } catch (final DataAccessLayerException exception) { _log.error(MessageCatalog._00093_DATA_ACCESS_LAYER_FAILURE, exception); throw new CumulusStoreException(exception); } }
Example #26
Source File: AbstractHashJoinUtilityTestCase.java From database with GNU General Public License v2.0 | 5 votes |
/** * Return a (Mock) IV for a Value. * * @param v * The value. * * @return The Mock IV. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private IV makeIV(final Value v) { final BigdataValueFactory valueFactory = BigdataValueFactoryImpl .getInstance(namespace); final BigdataValue bv = valueFactory.asValue(v); final IV iv = new TermId(VTE.valueOf(v), nextId++); iv.setValue(bv); return iv; }
Example #27
Source File: GraphRenderer.java From ldp4j with Apache License 2.0 | 5 votes |
private boolean tryRenderingFolded(Resource subject, Value object) { boolean result=false; if(!disableFolding && object instanceof Resource) { Individual individual=graph.findIndividual((Resource)object); if(individual!=null && individual.canBeFoldedBy(subject)) { renderFoldedBlankNode(individual); result=true; } } return result; }
Example #28
Source File: BasicSkin.java From database with GNU General Public License v2.0 | 5 votes |
public double getDoubleValue(final URI key) { final Value v = m_gpo.getValue(key); if (v instanceof Literal) { return ((Literal) v).doubleValue(); } else { return 0; } }
Example #29
Source File: ComplexSPARQLQueryTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testDescribeWhere() throws Exception { loadTestData("/testdata-query/dataset-describe.trig"); StringBuilder query = new StringBuilder(); query.append(getNamespaceDeclarations()); query.append("DESCRIBE ?x WHERE {?x rdfs:label ?y . } "); GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString()); ValueFactory vf = conn.getValueFactory(); URI a = vf.createURI("http://example.org/a"); URI b = vf.createURI("http://example.org/b"); URI c = vf.createURI("http://example.org/c"); URI e = vf.createURI("http://example.org/e"); URI f = vf.createURI("http://example.org/f"); URI p = vf.createURI("http://example.org/p"); Model result = QueryResults.asModel(gq.evaluate()); assertTrue(result.contains(a, p, null)); assertTrue(result.contains(b, RDFS.LABEL, null)); assertTrue(result.contains(c, RDFS.LABEL, null)); assertTrue(result.contains(null, p, b)); assertTrue(result.contains(e, RDFS.LABEL, null)); assertTrue(result.contains(null, p, e)); assertFalse(result.contains(f, null, null)); Set<Value> objects = result.filter(a, p, null).objects(); assertNotNull(objects); for (Value object : objects) { if (object instanceof BNode) { assertTrue(result.contains((Resource)object, null, null)); assertEquals(2, result.filter((Resource)object, null, null).size()); } } }
Example #30
Source File: StdObjectMap.java From GeoTriples with Apache License 2.0 | 5 votes |
protected void checkConstantValue(Value constantValue) throws R2RMLDataError { if (!RDFDataValidator.isValidURI(constantValue.stringValue()) && !RDFDataValidator .isValidLiteral(constantValue.stringValue())) throw new R2RMLDataError( "[StdObjectMap:checkConstantValue] Not a valid URI or literal : " + constantValue); }