Java Code Examples for org.openrdf.model.vocabulary.RDF#NAMESPACE

The following examples show how to use org.openrdf.model.vocabulary.RDF#NAMESPACE . 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: ForwardChainingRDFSInferencerConnection.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int applyRuleX1()
	throws SailException
{
	int nofInferred = 0;

	String prefix = RDF.NAMESPACE + "_";
	Iterator<Statement> iter = this.newThisIteration.match(null, null, null);

	while (iter.hasNext()) {
		Statement st = iter.next();

		URI predNode = st.getPredicate();
		String predURI = predNode.toString();

		if (predURI.startsWith(prefix) && isValidPredicateNumber(predURI.substring(prefix.length()))) {
			boolean added = addInferredStatement(predNode, RDF.TYPE, RDFS.CONTAINERMEMBERSHIPPROPERTY);
			if (added) {
				nofInferred++;
			}
		}
	}

	return nofInferred;
}
 
Example 2
Source File: RDFSContainer.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private URI getMemberPredicate(int index) {
	ObjectConnection conn = getObjectConnection();
	Repository repository;
	repository = conn.getRepository();
	String uri = RDF.NAMESPACE + '_' + (index + 1);
	return repository.getValueFactory().createURI(uri);
}
 
Example 3
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected void doConstructTest(final String method, final RDFFormat format)
            throws Exception {
        
        setupDataOnServer();
        final URI mike = new URIImpl(BD.NAMESPACE + "Mike");
        final URI bryan = new URIImpl(BD.NAMESPACE + "Bryan");
        final URI person = new URIImpl(BD.NAMESPACE + "Person");

        // The expected results.
        final Graph expected = new LinkedHashModel();
        {
//            expected.add(new StatementImpl(mike, likes, rdf));
            expected.add(new StatementImpl(mike, RDF.TYPE, person));
            expected.add(new StatementImpl(bryan, RDF.TYPE, person));
//            expected.add(new StatementImpl(mike, RDFS.LABEL, label1));
        }
        
        // Run the query and verify the results.
        {

            final String queryStr =
                "prefix bd: <"+BD.NAMESPACE+"> " +//
                "prefix rdf: <"+RDF.NAMESPACE+"> " +//
                "prefix rdfs: <"+RDFS.NAMESPACE+"> " +//
                "CONSTRUCT { ?x rdf:type bd:Person }" +//
                "WHERE { " +//
                "  ?x rdf:type bd:Person . " +//
//                "  ?x bd:likes bd:RDF " +//
                "}";

            final IPreparedGraphQuery query = m_repo.prepareGraphQuery(queryStr);

//            final Graph actual = asGraph(query.evaluate());

            assertSameGraph(expected, query);
            
        }
    
    }
 
Example 4
Source File: BigdataStoreTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected int countQueryResults(String query)
	throws Exception
{
	query = "PREFIX ex: <http://example.org/> PREFIX rdf: <"+RDF.NAMESPACE+"> PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + query;
	
	return countElements(evaluate(query, con));
}
 
Example 5
Source File: Test_REST_DESCRIBE.java    From database with GNU General Public License v2.0 4 votes vote down vote up
protected void doStressDescribeTest(final String method,
      final RDFFormat format, final int tasks, final int threads,
      final int statements) throws Exception {

   final URI person = new URIImpl(BD.NAMESPACE + "Person");
   final URI likes = new URIImpl(BD.NAMESPACE + "likes");
   final URI rdf = new URIImpl(BD.NAMESPACE + "RDF");
   final URI rdfs = new URIImpl(BD.NAMESPACE + "RDFS");

   {
      // create a large number of mikes and bryans
      final Graph g = new GraphImpl();
      for (int n = 0; n < statements; n++) {
         final URI miken = new URIImpl(BD.NAMESPACE + "Mike#" + n);
         final URI bryann = new URIImpl(BD.NAMESPACE + "Bryan#" + n);
         final Literal nameMiken = new LiteralImpl("Mike#" + n);
         final Literal nameBryann = new LiteralImpl("Bryan#" + n);
         g.add(miken, RDF.TYPE, person);
         g.add(miken, likes, rdf);
         g.add(miken, RDFS.LABEL, nameMiken);
         g.add(bryann, RDF.TYPE, person);
         g.add(bryann, likes, rdfs);
         g.add(bryann, RDFS.LABEL, nameBryann);
      }

      m_repo.add(new AddOp(g));

   }

   // Run the DESCRIBE query and verify the results (non-empty).
   {

      final String queryStr = "prefix bd: <" + BD.NAMESPACE + "> " + //
            "prefix rdf: <" + RDF.NAMESPACE + "> " + //
            "prefix rdfs: <" + RDFS.NAMESPACE + "> " + //
            "DESCRIBE ?x " + //
            "WHERE { " + //
            "  ?x rdf:type bd:Person . " + //
            "  ?x bd:likes bd:RDF " + //
            "}";

      final AtomicInteger errorCount = new AtomicInteger();
      final Callable<Void> task = new Callable<Void>() {

         @Override
         public Void call() throws Exception {
            try {

               final Graph actual = asGraph(m_repo
                     .prepareGraphQuery(queryStr));

               assertTrue(!actual.isEmpty());

               return null;
            } catch (Exception e) {
               log.warn("Call failure", e);

               errorCount.incrementAndGet();

               throw e;
            }
         }

      };

      final int threadCount = Thread.activeCount();

      final ExecutorService exec = Executors.newFixedThreadPool(threads);
      for (int r = 0; r < tasks; r++) {
         exec.submit(task);
      }
      exec.shutdown();
      exec.awaitTermination(2000, TimeUnit.SECONDS);
      // force shutdown
      exec.shutdownNow();

      int loops = 20;
      while (Thread.activeCount() > threadCount && --loops > 0) {
         Thread.sleep(500);
         if (log.isTraceEnabled())
            log.trace("Extra threads: "
                  + (Thread.activeCount() - threadCount));
      }

      if (log.isInfoEnabled())
         log.info("Return with extra threads: "
               + (Thread.activeCount() - threadCount));

      assertTrue(errorCount.get() == 0);
   }

}
 
Example 6
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Inserts some data into the KB and then issues a DESCRIBE query against
 * the REST API and verifies the expected results.
 * 
 * @param format
 *            The format is used to specify the Accept header.
 * 
 * @throws Exception
 */
protected void doDescribeTest(final String method, final RDFFormat format)
        throws Exception {
    
    final URI mike = new URIImpl(BD.NAMESPACE + "Mike");
    final URI bryan = new URIImpl(BD.NAMESPACE + "Bryan");
    final URI person = new URIImpl(BD.NAMESPACE + "Person");
    final URI likes = new URIImpl(BD.NAMESPACE + "likes");
    final URI rdf = new URIImpl(BD.NAMESPACE + "RDF");
    final URI rdfs = new URIImpl(BD.NAMESPACE + "RDFS");
    final Literal label1 = new LiteralImpl("Mike");
    final Literal label2 = new LiteralImpl("Bryan");

  {
     final Graph g = new LinkedHashModel();
     g.add(mike, RDF.TYPE, person);
     g.add(mike, likes, rdf);
     g.add(mike, RDFS.LABEL, label1);
     g.add(bryan, RDF.TYPE, person);
     g.add(bryan, likes, rdfs);
     g.add(bryan, RDFS.LABEL, label2);

     m_repo.add(new AddOp(g));
  }

    // The expected results.
    final Graph expected = new LinkedHashModel();
    {
        expected.add(new StatementImpl(mike, likes, rdf));
        expected.add(new StatementImpl(mike, RDF.TYPE, person));
        expected.add(new StatementImpl(mike, RDFS.LABEL, label1));
    }
    
    // Run the query and verify the results.
    {
        
    	final String queryStr =
            "prefix bd: <"+BD.NAMESPACE+"> " +//
            "prefix rdf: <"+RDF.NAMESPACE+"> " +//
            "prefix rdfs: <"+RDFS.NAMESPACE+"> " +//
            "DESCRIBE ?x " +//
            "WHERE { " +//
            "  ?x rdf:type bd:Person . " +//
            "  ?x bd:likes bd:RDF " +//
            "}";

    	assertSameGraph(expected, m_repo.prepareGraphQuery(queryStr));
        
    }

}
 
Example 7
Source File: TestSesameFilters.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testRegex() throws Exception {
    	
//        final Sail sail = new MemoryStore();
//        sail.initialize();
//        final Repository repo = new SailRepository(sail);

    	final BigdataSail sail = getSail();
    	sail.initialize();
    	final BigdataSailRepository repo = new BigdataSailRepository(sail);
    	
    	final RepositoryConnection cxn = repo.getConnection();
        cxn.setAutoCommit(false);
        
        try {
    
            final ValueFactory vf = sail.getValueFactory();

            /*
             * Create some terms.
             */
            final URI mike = vf.createURI(BD.NAMESPACE + "mike");
            final URI bryan = vf.createURI(BD.NAMESPACE + "bryan");
            final URI person = vf.createURI(BD.NAMESPACE + "Person");
            final Literal l1 = vf.createLiteral("mike personick");
            final Literal l2 = vf.createLiteral("bryan thompson");

            /*
             * Create some statements.
             */
            cxn.add(mike, RDF.TYPE, person);
            cxn.add(mike, RDFS.LABEL, l1);
            cxn.add(bryan, RDF.TYPE, person);
            cxn.add(bryan, RDFS.LABEL, l2);

            /*
             * Note: The either flush() or commit() is required to flush the
             * statement buffers to the database before executing any operations
             * that go around the sail.
             */
            cxn.commit();
            
            {
            	
	            String query =
	            	"prefix bd: <"+BD.NAMESPACE+"> " +
	            	"prefix rdf: <"+RDF.NAMESPACE+"> " +
	            	"prefix rdfs: <"+RDFS.NAMESPACE+"> " +
	                "select * " +
	                "where { " +
	                "  ?s rdf:type bd:Person . " +
	                "  ?s rdfs:label ?label . " +
	                "  FILTER regex(?label, \"mike\") . " +
	                "}"; 
	
	            final SailTupleQuery tupleQuery = (SailTupleQuery)
	                cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
	            tupleQuery.setIncludeInferred(false /* includeInferred */);
	           
	            final Collection<BindingSet> answer = new LinkedList<BindingSet>();
	            answer.add(createBindingSet(
	            		new BindingImpl("s", mike),
	            		new BindingImpl("label", l1)
	            		));

	            final TupleQueryResult result = tupleQuery.evaluate();
                compare(result, answer);

            }
            
        } finally {
            cxn.close();
            sail.shutDown();
        }

    }
 
Example 8
Source File: TestBOps.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testSimpleJoin() throws Exception {

        final BigdataSail sail = getSail();
        try {
        sail.initialize();
        final BigdataSailRepository repo = new BigdataSailRepository(sail);
        final BigdataSailRepositoryConnection cxn = 
            (BigdataSailRepositoryConnection) repo.getConnection();
        cxn.setAutoCommit(false);
        
        try {
    
//            final ValueFactory vf = sail.getValueFactory();
            
            final String ns = BD.NAMESPACE;
            
            final URI mike = new URIImpl(ns+"Mike");
            final URI bryan = new URIImpl(ns+"Bryan");
            final URI person = new URIImpl(ns+"Person");
            final URI likes = new URIImpl(ns+"likes");
            final URI rdf = new URIImpl(ns+"RDF");
            final Literal l1 = new LiteralImpl("Mike");
            final Literal l2 = new LiteralImpl("Bryan");
/**/
            cxn.setNamespace("ns", ns);
            
            cxn.add(mike, RDF.TYPE, person);
            cxn.add(mike, likes, rdf);
            cxn.add(mike, RDFS.LABEL, l1);
            cxn.add(bryan, RDF.TYPE, person);
            cxn.add(bryan, likes, rdf);
            cxn.add(bryan, RDFS.LABEL, l2);

            /*
             * Note: The either flush() or commit() is required to flush the
             * statement buffers to the database before executing any operations
             * that go around the sail.
             */
            cxn.flush();//commit();
            cxn.commit();//
            
            if (log.isInfoEnabled()) {
                log.info("\n" + cxn.getTripleStore().dumpStore());
            }

            {
                
                final String query = 
                    "PREFIX rdf: <"+RDF.NAMESPACE+"> " +
                    "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " +
                    "PREFIX ns: <"+ns+"> " +
                    
                    "select * " +
                    "WHERE { " +
                    "  ?s rdf:type ns:Person . " +
                    "  ?s ns:likes ?likes . " +
                    "  ?s rdfs:label ?label . " +
                    "}";
                
                final TupleQuery tupleQuery = 
                    cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
                final TupleQueryResult result = tupleQuery.evaluate();
                
//                while (result.hasNext()) {
//                    System.err.println(result.next());
//                }
 
                final Collection<BindingSet> solution = new LinkedList<BindingSet>();
                solution.add(createBindingSet(new Binding[] {
                    new BindingImpl("s", mike),
                    new BindingImpl("likes", rdf),
                    new BindingImpl("label", l1)
                }));
                solution.add(createBindingSet(new Binding[] {
                    new BindingImpl("s", bryan),
                    new BindingImpl("likes", rdf),
                    new BindingImpl("label", l2)
                }));
                
                compare(result, solution);
                
            }
        } finally { 
            cxn.close();
        }
        } finally {
            sail.__tearDownUnitTest();
        }

    }
 
Example 9
Source File: TestBOps.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testSimpleConstraint() throws Exception {

        final BigdataSail sail = getSail();
        try {
        sail.initialize();
        final BigdataSailRepository repo = new BigdataSailRepository(sail);
        final BigdataSailRepositoryConnection cxn = 
            (BigdataSailRepositoryConnection) repo.getConnection();
        cxn.setAutoCommit(false);
        
        try {
    
            final ValueFactory vf = sail.getValueFactory();
            
            final String ns = BD.NAMESPACE;
            
            final URI jill = new URIImpl(ns+"Jill");
            final URI jane = new URIImpl(ns+"Jane");
            final URI person = new URIImpl(ns+"Person");
            final URI age = new URIImpl(ns+"age");
            final URI IQ = new URIImpl(ns+"IQ");
            final Literal l1 = new LiteralImpl("Jill");
            final Literal l2 = new LiteralImpl("Jane");
            final Literal age1 = vf.createLiteral(20);
            final Literal age2 = vf.createLiteral(30);
            final Literal IQ1 = vf.createLiteral(130);
            final Literal IQ2 = vf.createLiteral(140);
/**/
            cxn.setNamespace("ns", ns);
            
            cxn.add(jill, RDF.TYPE, person);
            cxn.add(jill, RDFS.LABEL, l1);
            cxn.add(jill, age, age1);
            cxn.add(jill, IQ, IQ1);
            cxn.add(jane, RDF.TYPE, person);
            cxn.add(jane, RDFS.LABEL, l2);
            cxn.add(jane, age, age2);
            cxn.add(jane, IQ, IQ2);

            /*
             * Note: The either flush() or commit() is required to flush the
             * statement buffers to the database before executing any operations
             * that go around the sail.
             */
            cxn.flush();//commit();
            cxn.commit();//
            
            if (log.isInfoEnabled()) {
                log.info("\n" + cxn.getTripleStore().dumpStore());
            }

            {
                
                final String query = 
                    "PREFIX rdf: <"+RDF.NAMESPACE+"> " +
                    "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " +
                    "PREFIX ns: <"+ns+"> " +
                    
                    "select * " +
                    "WHERE { " +
                    "  ?s rdf:type ns:Person . " +
                    "  ?s ns:age ?age . " +
                    "  ?s ns:IQ ?iq . " +
                    "  ?s rdfs:label ?label . " +
                    "  FILTER( ?age < 25 && ?iq > 125 ) . " +
                    "}";
                
                final TupleQuery tupleQuery = 
                    cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
                final TupleQueryResult result = tupleQuery.evaluate();
                
//                while (result.hasNext()) {
//                    System.err.println(result.next());
//                }
 
                final Collection<BindingSet> solution = new LinkedList<BindingSet>();
                solution.add(createBindingSet(new Binding[] {
                    new BindingImpl("s", jill),
                    new BindingImpl("age", age1),
                    new BindingImpl("iq", IQ1),
                    new BindingImpl("label", l1)
                }));
                
                compare(result, solution);
                
            }
        } finally {
            cxn.close();
        }
        } finally {
            sail.__tearDownUnitTest();
        }

    }
 
Example 10
Source File: TestBOps.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testSimpleOptional() throws Exception {

        final BigdataSail sail = getSail();
        try {
        sail.initialize();
        final BigdataSailRepository repo = new BigdataSailRepository(sail);
        final BigdataSailRepositoryConnection cxn = 
            (BigdataSailRepositoryConnection) repo.getConnection();
        cxn.setAutoCommit(false);
        
        try {
    
//            final ValueFactory vf = sail.getValueFactory();
            
            final String ns = BD.NAMESPACE;
            
            final URI mike = new URIImpl(ns+"Mike");
            final URI bryan = new URIImpl(ns+"Bryan");
            final URI person = new URIImpl(ns+"Person");
            final URI likes = new URIImpl(ns+"likes");
            final URI rdf = new URIImpl(ns+"RDF");
            final Literal l1 = new LiteralImpl("Mike");
//            final Literal l2 = new LiteralImpl("Bryan");
/**/
            cxn.setNamespace("ns", ns);
            
            cxn.add(mike, RDF.TYPE, person);
            cxn.add(mike, likes, rdf);
            cxn.add(mike, RDFS.LABEL, l1);
            cxn.add(bryan, RDF.TYPE, person);
            cxn.add(bryan, likes, rdf);
//            cxn.add(bryan, RDFS.LABEL, l2);

            /*
             * Note: The either flush() or commit() is required to flush the
             * statement buffers to the database before executing any operations
             * that go around the sail.
             */
            cxn.flush();//commit();
            cxn.commit();//
            
            if (log.isInfoEnabled()) {
                log.info("\n" + cxn.getTripleStore().dumpStore());
            }

            {
                
                final String query = 
                    "PREFIX rdf: <"+RDF.NAMESPACE+"> " +
                    "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " +
                    "PREFIX ns: <"+ns+"> " +
                    
                    "select * " +
                    "WHERE { " +
                    "  ?s rdf:type ns:Person . " +
                    "  ?s ns:likes ?likes . " +
                    "  OPTIONAL { ?s rdfs:label ?label . } " +
                    "}";
                
                final TupleQuery tupleQuery = 
                    cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
                final TupleQueryResult result = tupleQuery.evaluate();
                
//                while (result.hasNext()) {
//                    System.err.println(result.next());
//                }
 
                final Collection<BindingSet> solution = new LinkedList<BindingSet>();
                solution.add(createBindingSet(new Binding[] {
                    new BindingImpl("s", mike),
                    new BindingImpl("likes", rdf),
                    new BindingImpl("label", l1)
                }));
                solution.add(createBindingSet(new Binding[] {
                    new BindingImpl("s", bryan),
                    new BindingImpl("likes", rdf),
//                    new BindingImpl("label", l2)
                }));
                
                compare(result, solution);
                
            }
        } finally {
            cxn.close();
        }
        } finally {
            sail.__tearDownUnitTest();
        }

    }
 
Example 11
Source File: TestBOps.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testOrEquals() throws Exception {

        final BigdataSail sail = getSail();
        try {
        sail.initialize();
        final BigdataSailRepository repo = new BigdataSailRepository(sail);
        final BigdataSailRepositoryConnection cxn = 
            (BigdataSailRepositoryConnection) repo.getConnection();
        cxn.setAutoCommit(false);
        
        try {
    
//            final ValueFactory vf = sail.getValueFactory();
//    
//            final LexiconRelation lex = sail.getDatabase().getLexiconRelation();
            
            final String ns = BD.NAMESPACE;
            
            final URI mike = new URIImpl(ns+"Mike");
            final URI bryan = new URIImpl(ns+"Bryan");
            final URI martyn = new URIImpl(ns+"Martyn");
            final URI person = new URIImpl(ns+"Person");
            final URI p = new URIImpl(ns+"p");
            final Literal l1 = new LiteralImpl("Mike");
            final Literal l2 = new LiteralImpl("Bryan");
            final Literal l3 = new LiteralImpl("Martyn");
/**/
            cxn.setNamespace("ns", ns);
            
            cxn.add(mike, RDF.TYPE, person);
            cxn.add(mike, RDFS.LABEL, l1);
            cxn.add(bryan, RDF.TYPE, person);
            cxn.add(bryan, RDFS.COMMENT, l2);
            cxn.add(martyn, RDF.TYPE, person);
            cxn.add(martyn, p, l3);

            /*
             * Note: The either flush() or commit() is required to flush the
             * statement buffers to the database before executing any operations
             * that go around the sail.
             */
            cxn.flush();//commit();
            cxn.commit();//
            
            if (log.isInfoEnabled()) {
                log.info("\n" + cxn.getTripleStore().dumpStore());
            }

            {
                
                String query = 
                    "PREFIX rdf: <"+RDF.NAMESPACE+"> " +
                    "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " +
                    "PREFIX ns: <"+ns+"> " +
                    
                    "select * " +
                    "WHERE { " +
                    "  ?s rdf:type ns:Person . " +
                    "  ?s ?p ?label . " +
                    "  FILTER ( ?p = rdfs:label || ?p = rdfs:comment ) . " +
                    "}";
                
                final TupleQuery tupleQuery = 
                    cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
                final TupleQueryResult result = tupleQuery.evaluate();
                
//                while (result.hasNext()) {
//                    System.err.println(result.next());
//                }
 
                final Collection<BindingSet> solution = new LinkedList<BindingSet>();
                solution.add(createBindingSet(new Binding[] {
                    new BindingImpl("s", mike),
                    new BindingImpl("p", RDFS.LABEL),
                    new BindingImpl("label", l1)
                }));
                solution.add(createBindingSet(new Binding[] {
                    new BindingImpl("s", bryan),
                    new BindingImpl("p", RDFS.COMMENT),
                    new BindingImpl("label", l2)
                }));
                
                compare(result, solution);
                
            }
        } finally {
            cxn.close();
        }
        } finally {
            sail.__tearDownUnitTest();
        }

    }