private static final URI getURI(String localPart) { return factory.createURI(namespace, localPart); }
private static final URI getURI(String localPart) { return factory.createURI(namespace, localPart); }
public List<String> getURIs(URI type) { if (type == null) throw new IllegalArgumentException("The type cannot be null"); ValueFactory f = ValueFactoryImpl.getInstance(); org.eclipse.rdf4j.model.URI uri = f.createURI(type.toString()); try { Model statements = repos.filter(null, null, uri); if (statements.isEmpty()) return Collections.emptyList(); List<String> units = new ArrayList<>(); for (Statement statement : statements) { units.add(statement.getSubject().toString()); } return units; } catch (Exception exception) { throw new IllegalStateException("Error while getting the units: " + exception.getMessage(), exception); } }
public List<String> getURIs(URI type) { if (type == null) throw new IllegalArgumentException("The type cannot be null"); ValueFactory f = ValueFactoryImpl.getInstance(); org.eclipse.rdf4j.model.URI uri = f.createURI(type.toString()); try { Model statements = repos.filter(null, null, uri); if (statements.isEmpty()) return Collections.emptyList(); List<String> units = new ArrayList<>(); for (Statement statement : statements) { units.add(statement.getSubject().toString()); } return units; } catch (Exception exception) { throw new IllegalStateException("Error while getting the units: " + exception.getMessage(), exception); } }
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length < 1) { throw new ValueExprEvaluationException("Incorrect number of arguments"); } if (!(args[0] instanceof Literal)) { throw new ValueExprEvaluationException("First argument must be a string"); } Literal s = (Literal)args[0]; String tmpl = s.getLabel(); Map<String, String> mappings = new HashMap<String, String>(args.length); for (int i = 1; i < args.length; i++) { mappings.put(Integer.toString(i), args[i].stringValue()); } String newValue = StrSubstitutor.replace(tmpl, mappings, "{?", "}"); if (tmpl.charAt(0) == '<' && tmpl.charAt(tmpl.length() - 1) == '>') { return valueFactory.createURI(newValue.substring(1, newValue.length() - 1)); } throw new ValueExprEvaluationException("Invalid URI template: " + tmpl); } }
public boolean deleteContext(String contextId) { try { RepositoryConnection conn = getConnection(); { conn.clear(conn.getValueFactory().createURI(contextId)); } closeConnection(conn); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
public boolean deleteContext(String contextId) { try { RepositoryConnection conn = getConnection(); { conn.clear(conn.getValueFactory().createURI(contextId)); } closeConnection(conn); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
@Override public boolean addIndividual(Resource resource) { try { RepositoryConnection conn = repo.getConnection(); ValueFactory factory = conn.getValueFactory(); String elementName = resource.getElementName().replaceAll(" ", "_"); org.eclipse.rdf4j.model.Statement st; if (resource.getInstanceOf() != null ) st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, factory.createURI(resource.getInstanceOf())); else st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, RDFS.RESOURCE); conn.add(st); conn.close(); return true; } catch (RepositoryException e) { return false; } }
@Override public boolean addIndividual(Resource resource) { try { RepositoryConnection conn = repo.getConnection(); ValueFactory factory = conn.getValueFactory(); String elementName = resource.getElementName().replaceAll(" ", "_"); org.eclipse.rdf4j.model.Statement st; if (resource.getInstanceOf() != null ) st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, factory.createURI(resource.getInstanceOf())); else st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, RDFS.RESOURCE); conn.add(st); conn.close(); return true; } catch (RepositoryException e) { return false; } }
/** * Evaluate a {@link Namespace} node * @param node the node to evaluate * @param bindings the set of named value bindings * @return the {@link Literal} of the URI of {@link URI} returned by evaluating the argument of the {@code node} * @throws ValueExprEvaluationException * @throws QueryEvaluationException */ private Value evaluate(Namespace node, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException { Value argValue = evaluate(node.getArg(), bindings); if (argValue instanceof URI) { URI uri = (URI) argValue; return valueFactory.createURI(uri.getNamespace()); } else { throw new ValueExprEvaluationException(); } }
private boolean addResource(Resource resource, org.eclipse.rdf4j.model.URI object) { try { RepositoryConnection conn = repo.getConnection(); ValueFactory factory = conn.getValueFactory(); String elementName = resource.getElementName().replaceAll(" ", "_"); org.eclipse.rdf4j.model.Statement st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, object); conn.add(st); conn.close(); return true; } catch (RepositoryException e) { return false; } }
private boolean addResource(Resource resource, org.eclipse.rdf4j.model.URI object) { try { RepositoryConnection conn = repo.getConnection(); ValueFactory factory = conn.getValueFactory(); String elementName = resource.getElementName().replaceAll(" ", "_"); org.eclipse.rdf4j.model.Statement st = factory.createStatement(factory.createURI(resource.getNamespace() +elementName), RDF.TYPE, object); conn.add(st); conn.close(); return true; } catch (RepositoryException e) { return false; } }
public boolean addContext(Context context) { try { RepositoryConnection conn = getConnection(); { ValueFactory vf = conn.getValueFactory(); RDFParser rdfParser = getParser(context.getRdfFormat()); StatementCollector handler = new StatementCollector(); rdfParser.setRDFHandler(handler); rdfParser.parse(context.getInputStream(), context.getBaseUri()); Collection<Statement> col = handler.getStatements(); Iterator<Statement> it = col.iterator(); while(it.hasNext()) { org.eclipse.rdf4j.model.Statement statement = it.next(); conn.add(statement, vf.createURI(context.getContextId())); } } closeConnection(conn); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
public boolean addContext(Context context) { try { RepositoryConnection conn = getConnection(); { ValueFactory vf = conn.getValueFactory(); RDFParser rdfParser = getParser(context.getRdfFormat()); StatementCollector handler = new StatementCollector(); rdfParser.setRDFHandler(handler); rdfParser.parse(context.getInputStream(), context.getBaseUri()); Collection<Statement> col = handler.getStatements(); Iterator<Statement> it = col.iterator(); while(it.hasNext()) { org.eclipse.rdf4j.model.Statement statement = it.next(); conn.add(statement, vf.createURI(context.getContextId())); } } closeConnection(conn); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
: vf.createURI(result.toString());
org.eclipse.rdf4j.model.URI uri = f.createURI(resource.toString());
org.eclipse.rdf4j.model.URI uri = f.createURI(resource.toString());