Java Code Examples for com.bigdata.rdf.model.StatementEnum#Explicit
The following examples show how to use
com.bigdata.rdf.model.StatementEnum#Explicit .
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: SPO.java From database with GNU General Public License v2.0 | 6 votes |
/** * Statement type is hiding in the 0 and 1 bits of the flags. */ private StatementEnum type() { // get just the 0 and 1 and 2 bits // final byte b = Bits.mask(flags, 0, 1, 2); byte b = 0; b |= (0x1 << TYPE_BIT); b |= (0x1 << (TYPE_BIT+1)); b |= (0x1 << (TYPE_BIT+2)); b &= flags; switch (b) { case 0: return null; case 1: return StatementEnum.Explicit; case 2: return StatementEnum.Axiom; case 3: return StatementEnum.Inferred; case 4: return StatementEnum.History; } throw new IllegalStateException(); }
Example 2
Source File: TestReificationDoneRightEval.java From database with GNU General Public License v2.0 | 4 votes |
/** * Bootstrap test. The data are explicitly entered into the KB by hand. This * makes it possible to test evaluation without having to fix the RDF data * loader. The query is based on <code>rdf-02a</code>. */ public void test_reificationDoneRight_00a() throws Exception { final BigdataValueFactory vf = store.getValueFactory(); final BigdataURI SAP = vf.createURI("http://example.com/SAP"); final BigdataURI bought = vf.createURI("http://example.com/bought"); final BigdataURI sybase = vf.createURI("http://example.com/sybase"); final BigdataURI dcSource = vf.createURI(DCTermsVocabularyDecl.NAMESPACE+"source"); final BigdataURI dcCreated = vf.createURI(DCTermsVocabularyDecl.NAMESPACE+"created"); final BigdataURI newsSybase = vf.createURI("http://example.com/news/us-sybase"); final BigdataLiteral createdDate = vf.createLiteral("2011-04-05T12:00:00Z",XSD.DATETIME); final BigdataURI g1 = vf.createURI("http://example.com/g1"); // Add/resolve the terms against the lexicon. final BigdataValue[] terms = new BigdataValue[] { SAP, bought, sybase, dcSource, dcCreated, newsSybase, createdDate, g1 }; final BigdataURI context = store.isQuads() ? g1 : null; store.addTerms(terms); // ground statement. final BigdataStatement s0 = vf.createStatement(SAP, bought, sybase, context, StatementEnum.Explicit); // Setup blank node with SidIV for that Statement. final BigdataBNode s1 = vf.createBNode("s1"); s1.setStatementIdentifier(true); final ISPO spo = new SPO(SAP.getIV(), bought.getIV(), sybase.getIV(), null/* NO CONTEXT */, StatementEnum.Explicit); s1.setIV(new SidIV<BigdataBNode>(spo)); // metadata statements. final BigdataStatement mds1 = vf.createStatement(s1, dcSource, newsSybase, context, StatementEnum.Explicit); final BigdataStatement mds2 = vf.createStatement(s1, dcCreated, createdDate, context, StatementEnum.Explicit); final ISPO[] stmts = new ISPO[] { new SPO(s0), new SPO(mds1), new SPO(mds2) }; store.addStatements(stmts, stmts.length); /* * Now that we have populated the database, we can go ahead and compile * the query. (If we compile the query first then it will not find any * matching lexical items.) */ new TestHelper(TEST_RESOURCE_PREFIX + "rdr-00a", // testURI, TEST_RESOURCE_PREFIX + "rdr-02a.rq",// queryFileURL TEST_RESOURCE_PREFIX + "empty.ttl",// dataFileURL TEST_RESOURCE_PREFIX + "rdr-02a.srx"// resultFileURL ).runTest(); }
Example 3
Source File: TestRuleFastClosure_11_13.java From database with GNU General Public License v2.0 | 4 votes |
/** * Tests {@link RuleFastClosure11} with the minimum data required to compute * a single entailment. */ public void test_RuleFastForwardClosure11() throws Exception { AbstractTripleStore store = getStore(); try { final BigdataValueFactory f = store.getValueFactory(); final IV a = store.addTerm(f.createURI("http://www.bigdata.com/a")); final IV b = store.addTerm(f.createURI("http://www.bigdata.com/b")); final IV y = store.addTerm(f.createURI("http://www.bigdata.com/y")); final IV x = store.addTerm(f.createURI("http://www.bigdata.com/x")); final IV z = store.addTerm(f.createURI("http://www.bigdata.com/z")); final Vocabulary vocab = store.getVocabulary(); // told: { SPO[] told = new SPO[] { // new SPO(x, y, z, StatementEnum.Explicit), // new SPO(y, vocab.get(RDFS.SUBPROPERTYOF), a, StatementEnum.Explicit), // new SPO(a, vocab.get(RDFS.DOMAIN), b, StatementEnum.Explicit) }; store.addStatements(told, told.length); } // entails: // store.addStatement(x, inf.rdfType.get(), b); // store.commit(); if (log.isInfoEnabled()) log.info("\n" + store.dumpStore()); /* * (?x, ?y, ?z), (?y, rdfs:subPropertyOf, ?a), (?a, rdfs:domain, ?b) -> * (?x, rdf:type, ?b). */ RuleFastClosure11 rule = new RuleFastClosure11(store .getSPORelation().getNamespace(), vocab); /* * Test run the rule. */ applyRule(store, rule, 1/*solutionCount*/, 1/*mutationCount*/); // check entailments. assertTrue(store.hasStatement(x, vocab.get(RDF.TYPE), b)); // store.commit(); } finally { store.__tearDownUnitTest(); } }
Example 4
Source File: TestRuleFastClosure_11_13.java From database with GNU General Public License v2.0 | 4 votes |
/** * Tests {@link RuleFastClosure13} with the minimum data required to compute * a single entailment. * @throws Exception */ public void test_RuleFastForwardClosure13() throws Exception { AbstractTripleStore store = getStore(); try { final BigdataValueFactory f = store.getValueFactory(); final IV a = store.addTerm(f.createURI("http://www.bigdata.com/a")); final IV b = store.addTerm(f.createURI("http://www.bigdata.com/b")); final IV y = store.addTerm(f.createURI("http://www.bigdata.com/y")); final IV x = store.addTerm(f.createURI("http://www.bigdata.com/x")); final IV z = store.addTerm(f.createURI("http://www.bigdata.com/z")); final Vocabulary vocab = store.getVocabulary(); // told: { SPO[] told = new SPO[] { // new SPO(x, y, z, StatementEnum.Explicit), // new SPO(y, vocab.get(RDFS.SUBPROPERTYOF), a, StatementEnum.Explicit), // new SPO(a, vocab.get(RDFS.RANGE), b, StatementEnum.Explicit) }; store.addStatements(told, told.length); } // entails: // store.addStatement(z, inf.rdfType.get(), b); // store.commit(); if (log.isInfoEnabled()) log.info("\n" + store.dumpStore()); /* * (?x, ?y, ?z), (?y, rdfs:subPropertyOf, ?a), (?a, rdfs:domain, ?b) -> * (?z, rdf:type, ?b). */ RuleFastClosure13 rule = new RuleFastClosure13(store .getSPORelation().getNamespace(), vocab); /* * Test run the rule. */ applyRule(store, rule, 1/*solutionCount*/, 1/*mutationCount*/); // check entailments. assertTrue(store.hasStatement(z, vocab.get(RDF.TYPE), b)); // store.commit(); } finally { store.__tearDownUnitTest(); } }
Example 5
Source File: TestEncodeDecodeKeys.java From database with GNU General Public License v2.0 | 4 votes |
/** * Unit test for {@link SidIV}. */ public void test_encodeDecode_sids() { final IV<?,?> s1 = newTermId(VTE.URI); final IV<?,?> s2 = newTermId(VTE.URI); final IV<?,?> p1 = newTermId(VTE.URI); final IV<?,?> p2 = newTermId(VTE.URI); final IV<?,?> o1 = newTermId(VTE.URI); final IV<?,?> o2 = newTermId(VTE.BNODE); final IV<?,?> o3 = newTermId(VTE.LITERAL); final SPO spo1 = new SPO(s1, p1, o1, StatementEnum.Explicit); final SPO spo2 = new SPO(s1, p1, o2, StatementEnum.Explicit); final SPO spo3 = new SPO(s1, p1, o3, StatementEnum.Explicit); final SPO spo4 = new SPO(s1, p2, o1, StatementEnum.Explicit); final SPO spo5 = new SPO(s1, p2, o2, StatementEnum.Explicit); final SPO spo6 = new SPO(s1, p2, o3, StatementEnum.Explicit); final SPO spo7 = new SPO(s2, p1, o1, StatementEnum.Explicit); final SPO spo8 = new SPO(s2, p1, o2, StatementEnum.Explicit); final SPO spo9 = new SPO(s2, p1, o3, StatementEnum.Explicit); final SPO spo10 = new SPO(s2, p2, o1, StatementEnum.Explicit); final SPO spo11 = new SPO(s2, p2, o2, StatementEnum.Explicit); final SPO spo12 = new SPO(s2, p2, o3, StatementEnum.Explicit); // spo1.setStatementIdentifier(true); // spo2.setStatementIdentifier(true); // spo3.setStatementIdentifier(true); // spo6.setStatementIdentifier(true); final SPO spo13 = new SPO(spo1.getStatementIdentifier(), p1, o1, StatementEnum.Explicit); final SPO spo14 = new SPO(spo2.getStatementIdentifier(), p2, o2, StatementEnum.Explicit); final SPO spo15 = new SPO(s1, p1, spo3.getStatementIdentifier(), StatementEnum.Explicit); // spo15.setStatementIdentifier(true); final SPO spo16 = new SPO(s1, p1, spo6.getStatementIdentifier(), StatementEnum.Explicit); final SPO spo17 = new SPO(spo1.getStatementIdentifier(), p1, spo15 .getStatementIdentifier(), StatementEnum.Explicit); final IV<?, ?>[] e = {// new SidIV<BigdataBNode>(spo1),// new SidIV<BigdataBNode>(spo2),// new SidIV<BigdataBNode>(spo3),// new SidIV<BigdataBNode>(spo4),// new SidIV<BigdataBNode>(spo5),// new SidIV<BigdataBNode>(spo6),// new SidIV<BigdataBNode>(spo7),// new SidIV<BigdataBNode>(spo8),// new SidIV<BigdataBNode>(spo9),// new SidIV<BigdataBNode>(spo10),// new SidIV<BigdataBNode>(spo11),// new SidIV<BigdataBNode>(spo12),// new SidIV<BigdataBNode>(spo13),// new SidIV<BigdataBNode>(spo14),// new SidIV<BigdataBNode>(spo15),// new SidIV<BigdataBNode>(spo16),// new SidIV<BigdataBNode>(spo17),// }; doEncodeDecodeTest(e); doComparatorTest(e); }
Example 6
Source File: TestSPO.java From database with GNU General Public License v2.0 | 4 votes |
public void test_serializable_sidIV() { final IV<?,?> s = new TermId<BigdataURI>(VTE.URI, 1); final IV<?,?> p = new TermId<BigdataURI>(VTE.URI, 2); final IV<?,?> o = new TermId<BigdataURI>(VTE.URI, 3); final SPO expected = new SPO(s, p, o, StatementEnum.Explicit); doRoundTripTest(expected); // expected.setStatementIdentifier(true); doRoundTripTest(expected); final IV<?,?> p1 = new TermId<BigdataURI>(VTE.URI, 4); final IV<?,?> o1 = new TermId<BigdataURI>(VTE.URI, 5); final SPO expected2 = new SPO(expected.c(), p1, o1, StatementEnum.Explicit); doRoundTripTest(expected2); }
Example 7
Source File: TestSPOValueCoders.java From database with GNU General Public License v2.0 | 4 votes |
/** * Return an array of {@link SPO}s. * * @param n * The #of elements in the array. * @param SIDs * If statement identifiers should be generated. * @param inference * if {@link StatementEnum}s should be assigned. * * @return The array. */ protected SPO[] getData(final int n, final boolean SIDs, final boolean inference) { final SPO[] a = new SPO[n]; for (int i = 0; i < n; i++) { /* * Note: Only the {s,p,o} are assigned. The statement type and the * statement identifier are not part of the key for the statement * indices. */ final SPO spo; if (SIDs && !inference) { // only explicit statements can have SIDs. spo = new SPO(getTermId(), getTermId(), getTermId(), StatementEnum.Explicit); // spo.setStatementIdentifier(getSID()); // spo.setStatementIdentifier(true); } else if (inference) { final int tmp = r.nextInt(100); final StatementEnum type; if (tmp < 4) { type = StatementEnum.Axiom; } else if (tmp < 60) { type = StatementEnum.Explicit; } else { type = StatementEnum.Inferred; } spo = new SPO(getTermId(), getTermId(), getTermId(), type); if (SIDs && type == StatementEnum.Explicit && r.nextInt(100) < 20) { // explicit statement with SID. // spo.setStatementIdentifier(getSID()); // spo.setStatementIdentifier(true); } } else { // Explicit statement (no inference, no SIDs). spo = new SPO(getTermId(), getTermId(), getTermId(), StatementEnum.Explicit); } a[i] = spo; } return a; }
Example 8
Source File: TestBulkFilter.java From database with GNU General Public License v2.0 | 4 votes |
/** * Simple test of bulk SPO completion (value lookup). */ public void testCompletion() { AbstractTripleStore store = getStore(); try { final URI A = new URIImpl("http://www.bigdata.com/A"); // final URI B = new URIImpl("http://www.bigdata.com/B"); // final URI C = new URIImpl("http://www.bigdata.com/C"); // final URI D = new URIImpl("http://www.bigdata.com/D"); // final URI E = new URIImpl("http://www.bigdata.com/E"); final URI V = new URIImpl("http://www.bigdata.com/V"); final URI W = new URIImpl("http://www.bigdata.com/W"); final URI X = new URIImpl("http://www.bigdata.com/X"); final URI Y = new URIImpl("http://www.bigdata.com/Y"); final URI Z = new URIImpl("http://www.bigdata.com/Z"); final IV a = store.addTerm(A); // final IV b = store.addTerm(B); // final IV c = store.addTerm(C); // final IV d = store.addTerm(D); // final IV e = store.addTerm(E); final IV v = store.addTerm(V); final IV w = store.addTerm(W); final IV x = store.addTerm(X); final IV y = store.addTerm(Y); final IV z = store.addTerm(Z); SPO[] stmts = new SPO[] { new SPO(x,a,y,StatementEnum.Explicit), new SPO(x,a,z,StatementEnum.Inferred) }; int numStmts = stmts.length; store.addStatements(stmts, numStmts); // store.commit(); if (log.isInfoEnabled()) log.info("\n" + store.dumpStore(true, true, false)); stmts = new SPO[] { new SPO(x,a,y), new SPO(x,a,z), new SPO(x,a,v), new SPO(x,a,w) }; numStmts = stmts.length; { // filter out and complete final IChunkedOrderedIterator<ISPO> itr = store .bulkCompleteStatements(stmts, numStmts); assertSameSPOsAnyOrder(store, new SPO[]{ new SPO(x,a,y, StatementEnum.Explicit), new SPO(x,a,z, StatementEnum.Inferred), new SPO(x,a,v, StatementEnum.Inferred), new SPO(x,a,w, StatementEnum.Inferred) }, itr, true // ignore axioms ); /* while(itr.hasNext()) { SPO spo = itr.next(); System.err.println(spo.toString(store)); } */ } } finally { store.__tearDownUnitTest(); } }
Example 9
Source File: SPO.java From database with GNU General Public License v2.0 | 3 votes |
@SuppressWarnings("rawtypes") public final IV getStatementIdentifier() { // lazy instantiate the sid if necessary if (sid == null && type() == StatementEnum.Explicit) { sid = new SidIV(this); } return sid; }
Example 10
Source File: SPO.java From database with GNU General Public License v2.0 | 3 votes |
/** * Return <code>true</code> IFF the {@link SPO} is marked as {@link StatementEnum#Explicit}. */ @Override public final boolean isExplicit() { return type() == StatementEnum.Explicit; }
Example 11
Source File: ExplicitSPOFilter.java From database with GNU General Public License v2.0 | 3 votes |
private boolean accept(final ISPO o) { final ISPO spo = (ISPO) o; return spo.getStatementType() == StatementEnum.Explicit; }
Example 12
Source File: DoNotAddFilter.java From database with GNU General Public License v2.0 | 2 votes |
private boolean accept(final ISPO o) { final ISPO spo = (ISPO) o; if(spo.s().isLiteral()) { /* * Note: Explicitly toss out entailments that would place a * literal into the subject position. These statements can enter * the database via rdfs3 and rdfs4b. */ return false; } if (spo.getStatementType() == StatementEnum.Explicit ) { // Accept all explicit statements. return true; } // if (spo.isOverride()) { // // // Accept all statements with the override flag set. // // return true; // // } if( axioms.isAxiom(spo.s(), spo.p(), spo.o())) { /* * Reject all statements which correspond to axioms. * * Note: This will let in explicit statements that correspond to * axioms since we let in all explicit statements above. The main * thing that this does is keep axioms generated by the rules from * showing up in the database, where they convert statements from * Axiom to Inferred. */ return false; } if (!forwardChainRdfTypeRdfsResource && IVUtility.equals(spo.p(), rdfType) && IVUtility.equals(spo.o(), rdfsResource)) { // reject (?x, rdf:type, rdfs:Resource ) return false; } // Accept everything else. return true; }
Example 13
Source File: SPO.java From database with GNU General Public License v2.0 | 2 votes |
@Override final public boolean hasStatementIdentifier() { return type() == StatementEnum.Explicit; }