org.openrdf.model.URI Java Examples
The following examples show how to use
org.openrdf.model.URI.
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: ObjectRepositoryConfig.java From anno4j with Apache License 2.0 | 6 votes |
private Class<?> loadClass(Value base) throws ObjectStoreConfigException { if (base instanceof URI) { URI uri = (URI) base; if (JAVA_NS.equals(uri.getNamespace())) { String name = uri.getLocalName(); try { synchronized (cl) { return Class.forName(name, true, cl); } } catch (ClassNotFoundException e) { throw new ObjectStoreConfigException(e); } } } throw new ObjectStoreConfigException("Invalid java URI: " + base); }
Example #2
Source File: FileSesameDataset.java From GeoTriples with Apache License 2.0 | 6 votes |
/** * Insert Triple/Statement into graph * * @param s subject uriref * @param p predicate uriref * @param o value object (URIref or Literal) * @param contexts varArgs context objects (use default graph if null) */ @Override public void add(Resource s, URI p, Value o, Resource... contexts) { if (log.isDebugEnabled()) { log.debug("[FileSesameDataSet:add] Add triple (" + s.stringValue() + ", " + p.stringValue() + ", " + o.stringValue() + ")."); } Statement st = new StatementImpl(s, p, o); try { writer.handleStatement(st); size++; } catch (RDFHandlerException ex) { log.error(o.toString()); } }
Example #3
Source File: SpecificResourceSupport.java From anno4j with Apache License 2.0 | 6 votes |
@Override public void delete() { try { ObjectConnection connection = getObjectConnection(); // deleting an existing selector if(getSelector() != null) { getSelector().delete(); setSelector(null); } connection.removeDesignation(this, (URI) getResource()); // explicitly removing the rdf type triple from the repository connection.remove(getResource(), null, null); connection.remove(null, null, getResource(), null); } catch (RepositoryException e) { e.printStackTrace(); } }
Example #4
Source File: BigdataSparqlTest.java From database with GNU General Public License v2.0 | 6 votes |
@Override protected void uploadDataset(Dataset dataset) throws Exception { // RepositoryConnection con = dataRep.getConnection(); // try { // Merge default and named graphs to filter duplicates Set<URI> graphURIs = new HashSet<URI>(); graphURIs.addAll(dataset.getDefaultGraphs()); graphURIs.addAll(dataset.getNamedGraphs()); for (Resource graphURI : graphURIs) { upload(((URI)graphURI), graphURI); } // } // finally { // con.close(); // } }
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: SmokeTest.java From anno4j with Apache License 2.0 | 6 votes |
public void testMethodQuery() throws Exception { // create a Document Document doc = new Document(); doc.setTitle("Getting Started"); // add a Document to the repository ValueFactory vf = con.getValueFactory(); URI id = vf .createURI("http://meta.leighnet.ca/data/2009/getting-started"); con.addObject(id, doc); // retrieve a Document by id doc = con.getObject(Document.class, id); assertEquals("Getting Started", doc.getTitle()); doc = doc.findDocumentByTitle("Getting Started"); assertEquals("Getting Started", doc.getTitle()); }
Example #7
Source File: SPARQLQueryTest.java From database with GNU General Public License v2.0 | 6 votes |
protected void uploadDataset(Dataset dataset) throws Exception { RepositoryConnection con = dataRep.getConnection(); try { // Merge default and named graphs to filter duplicates Set<URI> graphURIs = new HashSet<URI>(); graphURIs.addAll(dataset.getDefaultGraphs()); graphURIs.addAll(dataset.getNamedGraphs()); for (Resource graphURI : graphURIs) { upload(((URI)graphURI), graphURI); } } finally { con.close(); } }
Example #8
Source File: RDFSingleDataSet.java From mustard with MIT License | 6 votes |
@Override public void removeStatementsFromStrings(String subject, String predicate, String object) { URI querySub = null; URI queryPred = null; URI queryObj = null; if (subject != null) { querySub = rdfRep.getValueFactory().createURI(subject); } if (predicate != null) { queryPred = rdfRep.getValueFactory().createURI(predicate); } if (object != null) { queryObj = rdfRep.getValueFactory().createURI(object); } removeStatements(querySub, queryPred, queryObj); }
Example #9
Source File: BigdataSPARQLUpdateConformanceTest.java From database with GNU General Public License v2.0 | 5 votes |
public BigdataSPARQLUpdateConformanceTest(String testURI, String name, String requestFile, URI defaultGraphURI, Map<String, URI> inputNamedGraphs, URI resultDefaultGraphURI, Map<String, URI> resultNamedGraphs) { super(testURI, name, requestFile, defaultGraphURI, inputNamedGraphs, resultDefaultGraphURI, resultNamedGraphs); }
Example #10
Source File: TestGOM.java From database with GNU General Public License v2.0 | 5 votes |
/** * Simple test loads data from a file and navigates around */ public void testSimpleDirectData() throws IOException, RDFParseException, RepositoryException { final URL n3 = TestGOM.class.getResource("testgom.n3"); // print(n3); ((IGOMProxy) m_delegate).load(n3, RDFFormat.N3); final ValueFactory vf = om.getValueFactory(); final URI s = vf.createURI("gpo:#root"); final URI rootAttr = vf.createURI("attr:/root"); om.getGPO(s).getValue(rootAttr); final URI rootId = (URI) om.getGPO(s).getValue(rootAttr); final IGPO rootGPO = om.getGPO(rootId); if (log.isInfoEnabled()) { log.info("--------\n" + rootGPO.pp() + "\n" + rootGPO.getType().pp() + "\n" + rootGPO.getType().getStatements()); } final URI typeName = vf.createURI("attr:/type#name"); assertTrue("Company".equals(rootGPO.getType().getValue(typeName) .stringValue())); // find set of workers for the Company final URI worksFor = vf.createURI("attr:/employee#worksFor"); final ILinkSet linksIn = rootGPO.getLinksIn(worksFor); final Iterator<IGPO> workers = linksIn.iterator(); while (workers.hasNext()) { final IGPO tmp = workers.next(); if (log.isInfoEnabled()) log.info("Returned: " + tmp.pp()); } }
Example #11
Source File: JavaNameResolver.java From anno4j with Apache License 2.0 | 5 votes |
public boolean isAnnotationOfClasses(URI name) { Method m = roles.findAnnotationMethod(name); if (m == null) return false; Class<?> type = m.getReturnType(); return type.equals(Class.class) || type.getComponentType() != null && type.getComponentType().equals(Class.class); }
Example #12
Source File: AbstractBigdataRemoteQuery.java From database with GNU General Public License v2.0 | 5 votes |
/** * @see org.openrdf.http.client.HTTPClient#getQueryMethodParameters(QueryLanguage, String, String, Dataset, boolean, int, Binding...) */ protected void configureConnectOptions(IPreparedQuery q) { if (baseURI != null) { q.addRequestParam(RemoteRepositoryDecls.BASE_URI, baseURI); } q.addRequestParam(RemoteRepositoryDecls.INCLUDE_INFERRED, Boolean.toString(includeInferred)); if (maxQueryTime > 0) { q.addRequestParam(RemoteRepositoryDecls.MAX_QUERY_TIME_MILLIS, Long.toString(1000L*maxQueryTime)); } if (dataset != null) { String[] defaultGraphs = new String[dataset.getDefaultGraphs().size()]; int i=0; for (URI defaultGraphURI : dataset.getDefaultGraphs()) { defaultGraphs[i++] = String.valueOf(defaultGraphURI); } q.addRequestParam(q.isUpdate() ? RemoteRepositoryDecls.USING_GRAPH_URI : RemoteRepositoryDecls.DEFAULT_GRAPH_URI, defaultGraphs); String[] namedGraphs = new String[dataset.getNamedGraphs().size()]; i=0; for (URI namedGraphURI : dataset.getNamedGraphs()) { namedGraphs[i++] = String.valueOf(String.valueOf(namedGraphURI)); } q.addRequestParam(q.isUpdate() ? RemoteRepositoryDecls.USING_NAMED_GRAPH_URI : RemoteRepositoryDecls.NAMED_GRAPH_URI, namedGraphs); } for (Binding binding: bindings) { String paramName = RemoteRepositoryDecls.BINDING_PREFIX + binding.getName(); String paramValue = EncodeDecodeValue.encodeValue(binding.getValue()); q.addRequestParam(paramName, paramValue); } }
Example #13
Source File: RDFStoreTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testValueRoundTrip5() throws Exception { URI subj = new URIImpl(EXAMPLE_NS + PICASSO); URI pred = new URIImpl(EXAMPLE_NS + PAINTS); Literal obj = new NumericLiteralImpl(3); testValueRoundTrip(subj, pred, obj); }
Example #14
Source File: RdfIndexerService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private void indexEntityState( final EntityState entityState, final RepositoryConnection connection ) throws RepositoryException { if( entityState.entityDescriptor().queryable() ) { EntityReference reference = entityState.entityReference(); final URI entityURI = stateSerializer.createEntityURI( getValueFactory(), reference); Graph graph = new GraphImpl(); stateSerializer.serialize( entityState, false, graph ); connection.add( graph, entityURI ); } }
Example #15
Source File: RDFStoreTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testValueRoundTrip3() throws Exception { URI subj = new URIImpl(EXAMPLE_NS + PICASSO); URI pred = new URIImpl(EXAMPLE_NS + PAINTS); Literal obj = new LiteralImpl("guernica"); testValueRoundTrip(subj, pred, obj); }
Example #16
Source File: RepositoryConnectionTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testURISerialization() throws Exception { testCon.add(bob, name, nameBob); Statement st; RepositoryResult<Statement> statements = testCon.getStatements(null, null, null, false); try { st = statements.next(); } finally { statements.close(); } URI uri = st.getPredicate(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(uri); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream in = new ObjectInputStream(bais); URI deserializedURI = (URI)in.readObject(); in.close(); assertThat(deserializedURI, is(equalTo(uri))); assertThat(testCon.hasStatement(bob, uri, nameBob, true), is(equalTo(true))); assertThat(testCon.hasStatement(bob, deserializedURI, nameBob, true), is(equalTo(true))); }
Example #17
Source File: TestFullyInlineTypedLiteralIV.java From database with GNU General Public License v2.0 | 5 votes |
public void test_encodeDecode_comparator() { final List<IV<?,?>> ivs = new LinkedList<IV<?,?>>(); { final URI datatype = new URIImpl("http://www.bigdata.com"); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("")); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>(" ")); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("1")); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("12")); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("123")); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("","en",null/*datatype*/)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>(" ","en",null/*datatype*/)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("1","en",null/*datatype*/)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("12","fr",null/*datatype*/)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("123","de",null/*datatype*/)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("", null, datatype)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>(" ", null, datatype)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("1", null, datatype)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("12", null, datatype)); ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("123", null, datatype)); } final IV<?, ?>[] e = ivs.toArray(new IV[0]); AbstractEncodeDecodeKeysTestCase.doEncodeDecodeTest(e); AbstractEncodeDecodeKeysTestCase.doComparatorTest(e); }
Example #18
Source File: TestBigdataSailRemoteRepository.java From database with GNU General Public License v2.0 | 5 votes |
/** * Test of insert and retrieval of a large literal. */ public void test_INSERT_veryLargeLiteral() throws Exception { final Graph g = new LinkedHashModel(); final URI s = new URIImpl("http://www.bigdata.com/"); final URI p = RDFS.LABEL; final Literal o = getVeryLargeLiteral(); final Statement stmt = new StatementImpl(s, p, o); g.add(stmt); // Load the resource into the KB. assertEquals( 1L, doInsertByBody("POST", RDFFormat.RDFXML, g, null/* defaultContext */)); // Read back the data into a graph. final Graph g2; { final String queryStr = "DESCRIBE <" + s.stringValue() + ">"; final GraphQuery query = cxn.prepareGraphQuery(QueryLanguage.SPARQL, queryStr); g2 = asGraph(query.evaluate()); } assertEquals(1, g2.size()); assertTrue(g2.match(s, p, o).hasNext()); }
Example #19
Source File: BasicSkin.java From database with GNU General Public License v2.0 | 5 votes |
public boolean getBooleanValue(final URI key) { final Value v = m_gpo.getValue(key); if (v instanceof Literal) { return ((Literal) v).booleanValue(); } else { return false; } }
Example #20
Source File: ValueExprBuilder.java From database with GNU General Public License v2.0 | 5 votes |
/** * Handle a simple unary function (the child of the node is the argument to * the function). */ protected FunctionNode unary(final SimpleNode node, final URI functionURI) throws VisitorException { return new FunctionNode(functionURI, null/* scalarValues */, new ValueExpressionNode[] { left(node) }); }
Example #21
Source File: EncodeDecodeValue.java From database with GNU General Public License v2.0 | 5 votes |
/** * Encode an RDF {@link Value} as it should appear if used in a SPARQL * query. E.g., a literal will look like <code>"abc"</code>, * <code>"abc"@en</code> or * <code>"3"^^xsd:int. A URI will look like <code><http://www.bigdata.com/></code> * . * * @param v * The value (optional). * * @return The encoded value -or- <code>null</code> if the argument is * <code>null</code>. * * @throws IllegalArgumentException * if the argument is a {@link BNode}. */ public static String encodeValue(final Value v) { if(v == null) return null; if (v instanceof BNode) throw new IllegalArgumentException(); if (v instanceof URI) { return "<" + v.stringValue() + ">"; } if (v instanceof Literal) { final Literal lit = (Literal) v; final StringBuilder sb = new StringBuilder(); sb.append("\""); sb.append(lit.getLabel()); sb.append("\""); if (lit.getLanguage() != null) { sb.append("@"); sb.append(lit.getLanguage()); } if (lit.getDatatype() != null) { sb.append("^^"); sb.append(encodeValue(lit.getDatatype())); } return sb.toString(); } throw new AssertionError(); }
Example #22
Source File: AbstractTermMap.java From GeoTriples with Apache License 2.0 | 5 votes |
public void setDataType(URI dataType) throws R2RMLDataError, InvalidR2RMLStructureException { if (!isTypeable() && dataType != null) { throw new InvalidR2RMLStructureException( "[AbstractTermMap:setDataType] A term map that is not " + "a typeable term map MUST NOT have an rr:datatype" + " property."); } if (dataType != null) { // Check if datatype is valid checkDataType(dataType); //this.dataType = new dataType.stringValue(); this.dataType = dataType; } }
Example #23
Source File: EntityStateSerializer.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private void serializeAssociations( final EntityState entityState, final Graph graph, URI entityUri, final Stream<? extends AssociationDescriptor> associations, final boolean includeNonQueryable ) { ValueFactory values = graph.getValueFactory(); // Associations associations.filter( type -> includeNonQueryable || type.queryable() ).forEach( associationType -> { EntityReference associatedId = entityState .associationValueOf( associationType .qualifiedName() ); if( associatedId != null ) { URI assocURI = values .createURI( associationType .qualifiedName() .toURI() ); URI assocEntityURI = values.createURI( associatedId .toURI() ); graph.add( entityUri, assocURI, assocEntityURI ); } } ); }
Example #24
Source File: RDFSContainer.java From anno4j with Apache License 2.0 | 5 votes |
@Override public Object remove(int index) { ObjectConnection conn = getObjectConnection(); try { boolean autoCommit = conn.isAutoCommit(); if (autoCommit) { conn.setAutoCommit(false); } Object obj = get(index); int size = size(); for (int i = index; i < size - 1; i++) { replace(i, get(i + 1)); } URI pred = getMemberPredicate(size - 1); conn.remove(getResource(), pred, null); Object[] block = getBlock((size - 1) / BSIZE); if (block != null) { block[(size - 1) % BSIZE] = null; } if (_size > UNKNOWN) _size--; if (autoCommit) { conn.setAutoCommit(true); } return obj; } catch (RepositoryException e) { throw new ObjectPersistException(e); } }
Example #25
Source File: RDFSContainer.java From anno4j with Apache License 2.0 | 5 votes |
private void assign(int index, Object o) throws RepositoryException { if (o == null) throw new NullPointerException(); URI pred = getMemberPredicate(index); Value newValue = getObjectConnection().addObject(o); ObjectConnection conn = getObjectConnection(); conn.add(getResource(), pred, newValue); clearBlock(index / BSIZE); }
Example #26
Source File: ObjectRepositoryConfig.java From anno4j with Apache License 2.0 | 5 votes |
/** * Associates this concept with the given type. * * @param concept * interface or class * @param type * URI * @throws ObjectStoreConfigException */ public void addConcept(Class<?> concept, URI type) throws ObjectStoreConfigException { List<URI> list = concepts.get(concept); if (list == null && concepts.containsKey(concept)) throw new ObjectStoreConfigException(concept.getSimpleName() + " can only be added once"); if (list == null) { concepts.put(concept, list = new LinkedList<URI>()); } list.add(type); }
Example #27
Source File: BasicSkin.java From database with GNU General Public License v2.0 | 5 votes |
public String getStringValue(final URI key) { final Value v = m_gpo.getValue(key); if (v instanceof Literal) { return ((Literal) v).stringValue(); } else { return null; } }
Example #28
Source File: GeoSpatialQuery.java From database with GNU General Public License v2.0 | 5 votes |
/** * Private constructor, used for implementing the cloning logics. * It is not safe to expose this constructor to the outside: it does * not calculate the boundingBoxNorthWestWithTime and * boundingBoxSouthEastWithTime, but expects appropriate values here * as input. */ private GeoSpatialQuery(final GeoSpatialConfig geoSpatialConfig, final GeoFunction searchFunction, final URI searchDatatype, final IConstant<?> subject, final TermNode predicate, final TermNode context, final PointLatLon spatialCircleCenter, final Double spatialCircleRadius, final PointLatLon spatialRectangleSouthWest, final PointLatLon spatialRectangleNorthEast, final UNITS spatialUnit, final Long timeStart, final Long timeEnd, final Long coordSystem, final Map<String, LowerAndUpperValue> customFieldsConstraints, final IVariable<?> locationVar, final IVariable<?> timeVar, final IVariable<?> locationAndTimeVar, final IVariable<?> latVar, final IVariable<?> lonVar, final IVariable<?> coordSystemVar, final IVariable<?> customFieldsVar, final IVariable<?> literalVar, final IVariable<?> distanceVar, final IBindingSet incomingBindings, final CoordinateDD lowerBoundingBox, final CoordinateDD upperBoundingBox) { this(geoSpatialConfig, searchFunction, searchDatatype, subject, predicate, context, spatialCircleCenter, spatialCircleRadius, spatialRectangleSouthWest, spatialRectangleNorthEast, spatialUnit, timeStart, timeEnd, coordSystem, customFieldsConstraints, locationVar, timeVar, locationAndTimeVar, latVar, lonVar, coordSystemVar, customFieldsVar, literalVar, distanceVar, incomingBindings); this.lowerBoundingBox = lowerBoundingBox; this.upperBoundingBox = upperBoundingBox; }
Example #29
Source File: ObjectRepositoryConfig.java From anno4j with Apache License 2.0 | 5 votes |
private void exportAssocation(Resource subj, Map<Class<?>, List<URI>> assocation, URI relation, Graph model) { ValueFactory vf = ValueFactoryImpl.getInstance(); for (Map.Entry<Class<?>, List<URI>> e : assocation.entrySet()) { URI name = vf.createURI(JAVA_NS, e.getKey().getName()); model.add(subj, relation, name); if (e.getValue() != null) { for (URI value : e.getValue()) { model.add(name, KNOWN_AS, value); } } } }
Example #30
Source File: SesameTransformationInjectSemaphoreNeighbor.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
@Override public void activate(final Collection<SesameSemaphoreNeighborInjectMatch> matches) throws RepositoryException { final URI entry = driver.getValueFactory().createURI(RdfConstants.BASE_PREFIX + ModelConstants.ENTRY); for (SesameSemaphoreNeighborInjectMatch match : matches) { driver.getConnection().remove(match.getRoute(), entry, match.getSemaphore()); } }