org.openrdf.model.vocabulary.RDF Java Examples
The following examples show how to use
org.openrdf.model.vocabulary.RDF.
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: 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 #2
Source File: TestBigdataSailRemoteRepository.java From database with GNU General Public License v2.0 | 6 votes |
/** * Get everything with a specific predicate and object (a URI). */ public void test_GET_accessPath_delete_p_o_URI() throws Exception { doInsertbyURL("POST", packagePath + "test_delete_by_access_path.ttl"); final long result = countResults(doGetWithAccessPath(// // requestPath,// null,// s RDF.TYPE,// p new URIImpl("http://xmlns.com/foaf/0.1/Person")// o )); assertEquals(3, result); }
Example #3
Source File: TestBlobsWriteTask.java From database with GNU General Public License v2.0 | 6 votes |
public void test_add_various_toldBNodes() { // The values that we will be testing with. final Value[] valuesIn = new Value[] {// new LiteralImpl("abc"), // RDF.TYPE,// RDF.PROPERTY,// new LiteralImpl("test"),// new LiteralImpl("test", "en"),// new LiteralImpl("10", new URIImpl("http://www.w3.org/2001/XMLSchema#int")), new LiteralImpl("12", new URIImpl("http://www.w3.org/2001/XMLSchema#float")), new LiteralImpl("12.", new URIImpl("http://www.w3.org/2001/XMLSchema#float")), new LiteralImpl("12.0", new URIImpl("http://www.w3.org/2001/XMLSchema#float")), new LiteralImpl("12.00", new URIImpl("http://www.w3.org/2001/XMLSchema#float")), new BNodeImpl("a"),// new BNodeImpl("12"),// }; doAddTermsTest(valuesIn, true/* toldBNodes */); }
Example #4
Source File: TestEncodeDecodeUnicodeIVs.java From database with GNU General Public License v2.0 | 6 votes |
/** * Unit test for inlining an entire URI using {@link FullyInlineURIIV}. The URI * is inlined as a Unicode component using {@link DTE#XSDString}. The * extension bit is NOT set since we are not factoring out the namespace * component of the URI. */ public void test_encodeDecode_Inline_URI() { final IV<?, ?>[] e = {// new FullyInlineURIIV<BigdataURI>(new URIImpl("http://www.bigdata.com")),// new FullyInlineURIIV<BigdataURI>(RDF.TYPE),// new FullyInlineURIIV<BigdataURI>(RDF.SUBJECT),// new FullyInlineURIIV<BigdataURI>(RDF.BAG),// new FullyInlineURIIV<BigdataURI>(RDF.OBJECT),// }; doEncodeDecodeTest(e); doComparatorTest(e); }
Example #5
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
private int applyRuleRdfs4b() throws SailException { int nofInferred = 0; Iterator<Statement> iter = this.newThisIteration.match(null, null, null); while (iter.hasNext()) { Statement st = iter.next(); Value uuu = st.getObject(); if (uuu instanceof Resource) { boolean added = addInferredStatement((Resource)uuu, RDF.TYPE, RDFS.RESOURCE); if (added) { nofInferred++; } } } return nofInferred; }
Example #6
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
private int applyRuleRdfs4a() throws SailException { int nofInferred = 0; Iterator<Statement> iter = this.newThisIteration.match(null, null, null); while (iter.hasNext()) { Statement st = iter.next(); boolean added = addInferredStatement(st.getSubject(), RDF.TYPE, RDFS.RESOURCE); if (added) { nofInferred++; } } return nofInferred; }
Example #7
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
private int applyRuleRdfs10() throws SailException { int nofInferred = 0; Iterator<Statement> iter = this.newThisIteration.match(null, RDF.TYPE, RDFS.CLASS); while (iter.hasNext()) { Statement st = iter.next(); Resource xxx = st.getSubject(); boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, xxx); if (added) { nofInferred++; } } return nofInferred; }
Example #8
Source File: OwlNormalizer.java From anno4j with Apache License 2.0 | 6 votes |
private void checkPropertyDomains() { loop: for (Statement st : ds.match(null, RDF.TYPE, RDF.PROPERTY)) { Resource p = st.getSubject(); if (!ds.contains(p, RDFS.DOMAIN, null)) { for (Value sup : ds.match(p, RDFS.SUBPROPERTYOF, null).objects()) { for (Value obj : ds.match(sup, RDFS.DOMAIN, null).objects()) { ds.add(p, RDFS.DOMAIN, obj); continue loop; } } ds.add(p, RDFS.DOMAIN, RDFS.RESOURCE); if (!ds.contains(RDFS.RESOURCE, RDF.TYPE, OWL.CLASS)) { ds.add(RDFS.RESOURCE, RDF.TYPE, OWL.CLASS); } } } }
Example #9
Source File: Test_REST_HASSTMT.java From database with GNU General Public License v2.0 | 6 votes |
public void test_HASSTMT_p() throws Exception { doInsertbyURL("POST", packagePath + "test_estcard.ttl"); assertTrue(m_repo.hasStatement(null,// s RDF.TYPE,// p null,// o false// includeInferred // c )); assertFalse(m_repo.hasStatement(null,// s RDF.BAG,// p null,// o false// includeInferred // c )); }
Example #10
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
private int applyRuleRdf1() throws SailException { int nofInferred = 0; Iterator<Statement> iter = this.newThisIteration.match(null, null, null); while (iter.hasNext()) { Statement st = iter.next(); boolean added = addInferredStatement(st.getPredicate(), RDF.TYPE, RDF.PROPERTY); if (added) { nofInferred++; } } return nofInferred; }
Example #11
Source File: RDFEntity.java From anno4j with Apache License 2.0 | 6 votes |
public Collection<RDFClass> getRDFClasses(URI pred) { final Collection<RDFClass> set = new ArrayList<RDFClass>(); for (Value value : getValues(pred)) { if (value instanceof Resource) { Resource subj = (Resource) value; if (model.contains(subj, RDF.TYPE, RDF.LIST)) { for (Value v : new RDFList(model, subj).asList()) { if (v instanceof Resource) { set.add(new RDFClass(model, (Resource) v)); } } } else { set.add(new RDFClass(model, subj)); } } } return set; }
Example #12
Source File: RDFList.java From anno4j with Apache License 2.0 | 6 votes |
Resource getRest(Resource list) { if (list == null) return null; try { CloseableIteration<Value, RepositoryException> stmts; stmts = getValues(list, RDF.REST, null); try { if (stmts.hasNext()) return (Resource) stmts.next(); return null; } finally { stmts.close(); } } catch (RepositoryException e) { throw new ObjectStoreException(e); } }
Example #13
Source File: RDFStoreTest.java From database with GNU General Public License v2.0 | 6 votes |
@Test public void testStatementSerialization() throws Exception { Statement st = vf.createStatement(picasso, RDF.TYPE, painter); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(st); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); Statement deserializedStatement = (Statement)in.readObject(); in.close(); assertTrue(st.equals(deserializedStatement)); }
Example #14
Source File: JavaNameResolver.java From anno4j with Apache License 2.0 | 6 votes |
public void setModel(Model model) { this.model = model; if (nouns != null) { Set<String> localNames = new HashSet<String>(); for (Resource subj : model.filter(null, RDF.TYPE, null).subjects()) { if (subj instanceof URI) { localNames.add(((URI) subj).getLocalName()); } } for (String name : localNames) { if (name.matches("^[a-zA-Z][a-z]+$")) { nouns.add(name.toLowerCase()); } } } }
Example #15
Source File: AugurTest.java From anno4j with Apache License 2.0 | 6 votes |
public void test_naive() throws Exception { ValueFactory vf = con.getValueFactory(); final URI Bean = vf.createURI(NS, "Bean"); final URI name = vf.createURI(NS, "name"); final URI parent = vf.createURI(NS, "parent"); final URI friend = vf.createURI(NS, "friend"); long start = System.currentTimeMillis(); RepositoryResult<Statement> beans = con.getStatements(null, RDF.TYPE, Bean); while (beans.hasNext()) { Statement st = beans.next(); Resource bean = st.getSubject(); QueryResults.asList(con.getStatements(bean, name, null)); RepositoryResult<Statement> match; match = con.getStatements(bean, parent, null); while (match.hasNext()) { QueryResults.asList(con.getStatements((Resource)match.next().getObject(), name, null)); } match = con.getStatements(bean, friend, null); while (match.hasNext()) { QueryResults.asList(con.getStatements((Resource)match.next().getObject(), name, null)); } } long end = System.currentTimeMillis(); System.out.println((end - start) / 1000.0); }
Example #16
Source File: RuleOwlHasValue.java From database with GNU General Public License v2.0 | 6 votes |
/** * @param vocab */ public RuleOwlHasValue(String relationName, Vocabulary vocab) { super( "owl:hasValue",// new SPOPredicate(relationName, var("x"), var("p"), var("v")), // new SPOPredicate[] { // new SPOPredicate(relationName,var("x"), vocab.getConstant(RDF.TYPE), var("a")),// new SPOPredicate(relationName,var("a"), vocab.getConstant(RDF.TYPE), vocab.getConstant(OWL.RESTRICTION)),// new SPOPredicate(relationName,var("a"), vocab.getConstant(OWL.ONPROPERTY), var("p")),// new SPOPredicate(relationName,var("a"), vocab.getConstant(OWL.HASVALUE), var("v"))// },// null//constraints ); }
Example #17
Source File: Test_REST_HASSTMT.java From database with GNU General Public License v2.0 | 5 votes |
public void test_HASSTMT_so() throws Exception { doInsertbyURL("POST", packagePath + "test_estcard.ttl"); assertTrue( m_repo.hasStatement(new URIImpl( "http://www.bigdata.com/Mike"),// s, RDF.TYPE,// p null,// o false // includeInferred // null // c )); assertFalse( m_repo.hasStatement(new URIImpl( "http://www.bigdata.com/Fred"),// s, RDF.TYPE,// p null,// o false // includeInferred // null // c )); assertFalse( m_repo.hasStatement(new URIImpl( "http://www.bigdata.com/Mike"),// s, RDF.BAG,// p null,// o false // includeInferred // null // c )); }
Example #18
Source File: MatchRule.java From database with GNU General Public License v2.0 | 5 votes |
public MatchRule(String relationName, Vocabulary vocab, IVariable<IV> lit, IConstant<IV>[] preds, IConstant<IV> cls) { super( "matchRule", // new SPOPredicate(relationName, var("s"), var("t"), lit), // new SPOPredicate[] { // new SPOPredicate(relationName, var("s"), var("p"), lit), // new SPOPredicate( new BOp[] { var("s"), // vocab.getConstant(RDF.TYPE),// var("t") }, // new NV(IPredicate.Annotations.RELATION_NAME, new String[] { relationName }), new NV( IPredicate.Annotations.INDEX_LOCAL_FILTER, ElementFilter .newInstance(ExplicitSPOFilter.INSTANCE))), // new SPOPredicate(relationName, var("t"), vocab .getConstant(RDFS.SUBCLASSOF), cls) // }, new IConstraint[] { Constraint.wrap(new INBinarySearch(var("p"), preds)) // p IN preds }); }
Example #19
Source File: OwlNormalizer.java From anno4j with Apache License 2.0 | 5 votes |
private void setObjectType(URI pred, URI type) { for (Statement st : ds.match(null, pred, null)) { if (st.getObject() instanceof Resource) { Resource subj = (Resource) st.getObject(); ds.add(subj, RDF.TYPE, type); } else { logger.warn("Invalid statement {}", st); } } }
Example #20
Source File: OwlNormalizer.java From anno4j with Apache License 2.0 | 5 votes |
private void setMemberType(URI pred, URI type) { for (Value list : ds.match(null, pred, null).objects()) { if (list instanceof Resource) { RDFList members = new RDFList(ds, (Resource) list); for (Value member : members.asList()) { if (member instanceof Resource) { ds.add((Resource) member, RDF.TYPE, type); } } } } }
Example #21
Source File: RuleRdfs02.java From database with GNU General Public License v2.0 | 5 votes |
public RuleRdfs02(String relationName, Vocabulary vocab) { super( "rdfs02",// new SPOPredicate(relationName,var("u"), vocab.getConstant(RDF.TYPE), var("x")), new SPOPredicate[] { new SPOPredicate(relationName,var("a"), vocab.getConstant(RDFS.DOMAIN), var("x")), new SPOPredicate(relationName,var("u"), var("a"), var("y")) },// null//constraints ); }
Example #22
Source File: RepositoryConnectionTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testInferredStatementCount() throws Exception { assertThat(testCon.isEmpty(), is(equalTo(true))); int inferred = getTotalStatementCount(testCon); URI root = vf.createURI("urn:root"); testCon.add(root, RDF.TYPE, RDF.LIST); testCon.remove(root, RDF.TYPE, RDF.LIST); assertThat(testCon.isEmpty(), is(equalTo(true))); assertThat(getTotalStatementCount(testCon), is(equalTo(inferred))); }
Example #23
Source File: RuleRdfs12.java From database with GNU General Public License v2.0 | 5 votes |
public RuleRdfs12(String relationName, Vocabulary vocab) { super( "rdfs12",// new SPOPredicate(relationName,var("u"), vocab.getConstant(RDFS.SUBPROPERTYOF), vocab.getConstant(RDFS.MEMBER)),// new SPOPredicate[] { new SPOPredicate(relationName,var("u"), vocab.getConstant(RDF.TYPE), vocab.getConstant(RDFS.CONTAINERMEMBERSHIPPROPERTY))// },// null // constraints ); }
Example #24
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs2_2() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.DOMAIN, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource aaa = nt.getSubject(); Value zzz = nt.getObject(); if (aaa instanceof URI && zzz instanceof Resource) { CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(null, (URI)aaa, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Resource xxx = t1.getSubject(); boolean added = addInferredStatement(xxx, RDF.TYPE, zzz); if (added) { nofInferred++; } } t1Iter.close(); } } return nofInferred; }
Example #25
Source File: RuleRdfs03.java From database with GNU General Public License v2.0 | 5 votes |
public RuleRdfs03( String relationName, Vocabulary vocab) { super( "rdfs03", // new SPOPredicate(relationName,var("v"), vocab.getConstant(RDF.TYPE), var("x")),// new SPOPredicate[] {// new SPOPredicate(relationName,var("a"), vocab.getConstant(RDFS.RANGE), var("x")),// new SPOPredicate(relationName,var("u"), var("a"), var("v"))// }, null // constraints ); }
Example #26
Source File: ObjectFactory.java From anno4j with Apache License 2.0 | 5 votes |
private Map<String, String> findEagerProperties(Class<?> type) { Map<String, String> result = resolver.getPropertyMapper().findEagerProperties(type); if (result == null && resolver.getRoleMapper().isNamedTypePresent()) return Collections.singletonMap("class", RDF.TYPE.stringValue()); if (result == null) return Collections.emptyMap(); return result; }
Example #27
Source File: AbstractRAMGraphTestCase.java From database with GNU General Public License v2.0 | 5 votes |
/** * The data: * * <pre> * @prefix : <http://www.bigdata.com/> . * @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . * @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . * @prefix foaf: <http://xmlns.com/foaf/0.1/> . * * #: { * :Mike rdf:type foaf:Person . * :Bryan rdf:type foaf:Person . * :Martyn rdf:type foaf:Person . * * :Mike rdfs:label "Mike" . * :Bryan rdfs:label "Bryan" . * :DC rdfs:label "DC" . * * :Mike foaf:knows :Bryan . * :Bryan foaf:knows :Mike . * :Bryan foaf:knows :Martyn . * :Martyn foaf:knows :Bryan . * #} * </pre> */ public SmallGraphProblem() throws Exception { final RAMGraph g = getGraphFixture().getGraph(); final ValueFactory vf = g.getValueFactory(); rdfType = vf.createURI(RDF.TYPE.stringValue()); rdfsLabel = vf.createURI(RDFS.LABEL.stringValue()); foafKnows = vf.createURI("http://xmlns.com/foaf/0.1/knows"); foafPerson = vf.createURI("http://xmlns.com/foaf/0.1/Person"); mike = vf.createURI("http://www.bigdata.com/Mike"); bryan = vf.createURI("http://www.bigdata.com/Bryan"); martyn = vf.createURI("http://www.bigdata.com/Martyn"); dc = vf.createURI("http://www.bigdata.com/DC"); g.add(vf.createStatement(mike, rdfType, foafPerson)); g.add(vf.createStatement(bryan, rdfType, foafPerson)); g.add(vf.createStatement(martyn, rdfType, foafPerson)); g.add(vf.createStatement(mike, rdfsLabel, vf.createLiteral("Mike"))); g.add(vf.createStatement(bryan, rdfsLabel, vf.createLiteral("Bryan"))); g.add(vf.createStatement(dc, rdfsLabel, vf.createLiteral("DC"))); g.add(vf.createStatement(mike, foafKnows, bryan)); g.add(vf.createStatement(bryan, foafKnows, mike)); g.add(vf.createStatement(bryan, foafKnows, martyn)); g.add(vf.createStatement(martyn, foafKnows, bryan)); }
Example #28
Source File: TestUpdateExprBuilder.java From database with GNU General Public License v2.0 | 5 votes |
/** * <pre> * INSERT DATA { _:bnode a <http://example/Foo> . } * </pre> * @throws MalformedQueryException * * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/573"> * NullPointerException when attempting to INSERT DATA containing a * blank node </a> */ public void test_insert_data_ticket573() throws MalformedQueryException { final String sparql = "INSERT DATA { _:bnode a <http://example/Foo> . }"; final UpdateRoot expected = new UpdateRoot(); { final InsertData op = new InsertData(); expected.addChild(op); final BigdataBNode bnode = valueFactory.createBNode("-anon-1"); // final BigdataBNode bnode = valueFactory.createBNode("bnode"); final BigdataURI rdfType = valueFactory.createURI(RDF.TYPE.toString()); final BigdataURI foo = valueFactory.createURI("http://example/Foo"); final BigdataStatement[] data = new BigdataStatement[] { // valueFactory.createStatement(// bnode,// rdfType,// foo, // null,// c StatementEnum.Explicit),// }; op.setData(data); } final UpdateRoot actual = parseUpdate(sparql, baseURI); // no null pointer exception, but Sesame 2.7 Sparql parser will // not respect the bnode id, so we cannot assert same AST // assertSameAST(sparql, expected, actual); }
Example #29
Source File: Test_REST_DELETE_BY_ACCESS_PATH.java From database with GNU General Public License v2.0 | 5 votes |
/** * Delete everything with a specific predicate and object (a URI). */ public void test_DELETE_accessPath_delete_p_o_URI() throws Exception { doInsertbyURL("POST", packagePath + "test_delete_by_access_path.ttl"); final long mutationResult = doDeleteWithAccessPath(// // requestPath,// null,// s RDF.TYPE,// p new URIImpl("http://xmlns.com/foaf/0.1/Person")// o ); assertEquals(3, mutationResult); }
Example #30
Source File: BigdataStoreTest.java From database with GNU General Public License v2.0 | 5 votes |
/** * Modified to test SPARQL instead of Serql. */ @Override public void testRemoveAndClear() throws Exception { // Add some data to the repository con.addStatement(painter, RDF.TYPE, RDFS.CLASS); con.addStatement(painting, RDF.TYPE, RDFS.CLASS); con.addStatement(picasso, RDF.TYPE, painter, context1); con.addStatement(guernica, RDF.TYPE, painting, context1); con.addStatement(picasso, paints, guernica, context1); con.commit(); // Test removal of statements con.removeStatements(painting, RDF.TYPE, RDFS.CLASS); con.commit(); assertEquals("Repository should contain 4 statements in total", 4, countAllElements()); assertEquals("Named context should contain 3 statements", 3, countContext1Elements()); assertEquals("Statement (Painting, type, Class) should no longer be in the repository", 0, countQueryResults("select * where {ex:Painting rdf:type rdfs:Class}")); con.removeStatements(null, null, null, context1); con.commit(); assertEquals("Repository should contain 1 statement in total", 1, countAllElements()); assertEquals("Named context should be empty", 0, countContext1Elements()); con.clear(); con.commit(); assertEquals("Repository should no longer contain any statements", 0, countAllElements()); }