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

The following examples show how to use org.openrdf.model.vocabulary.RDFS#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: KnownURIsDictionaryTest.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Tests remove() method with managed URI.
 * 
 * @throws Exception never otherwise the test fails.
 */
@Test
public void removeManagedURI() throws Exception {
	final String[] managedNamespaces = {
			FOAF.NAMESPACE,
			RDFS.NAMESPACE,
			OWL.NAMESPACE };

	for (final String managedNamespace : managedNamespaces) {
		assertTrue(_cut.contains(managedNamespace));

		final Value uri = buildResource(managedNamespace + randomString());
		final String n3 = NTriplesUtil.toNTriplesString(uri);

		_cut.removeValue(uri, _isPredicate);
		verify(_dummyIndex).remove(n3);

		reset(_dummyIndex);
	}
}
 
Example 2
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 3
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 4
Source File: KnownURIsDictionaryTest.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * A request is received for a URI with a namespace that belongs to managed domains. 
 * 
 * @throws Exception never otherwise the test fails.
 */
@Test
public void getIdWithManagedURI() throws Exception {
	final String[] managedNamespaces = {
			FOAF.NAMESPACE,
			RDFS.NAMESPACE,
			OWL.NAMESPACE
	};

	for (final String managedNamespace : managedNamespaces) {
		assertTrue(_cut.contains(managedNamespace));

		final Value uri = buildResource(managedNamespace + randomString());

		final String n3 = NTriplesUtil.toNTriplesString(uri);

		// Make sure the mock index returns "Sorry, we don't have such value".
		when(_dummyIndex.get(n3)).thenReturn(ValueDictionaryBase.NOT_SET);

		// 1. ask for uri.
		byte[] id = _cut.getID(uri, _isPredicate);

		// 2. make sure the identifier is well-formed.
		assertEquals(KnownURIsDictionary.ID_LENGTH, id.length);
		assertEquals(KnownURIsDictionary.KNOWN_URI_MARKER, id[0]);
		assertEquals(ValueDictionaryBase.RESOURCE_BYTE_FLAG, id[1]);

		// 3. make sure the decoratee wasn't involved in identifier creation.
		verify(_decoratee, times(0)).getID(uri, _isPredicate);
		verify(_dummyIndex).putQuick(n3, id);

		reset(_decoratee, _dummyIndex);
	}
}
 
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();
        }

    }