本文整理汇总了Java中org.openrdf.repository.Repository.getValueFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Repository.getValueFactory方法的具体用法?Java Repository.getValueFactory怎么用?Java Repository.getValueFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.repository.Repository
的用法示例。
在下文中一共展示了Repository.getValueFactory方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExportStatementsResult
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
/**
* Get all statements and export them as RDF.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @return a model and view for exporting the statements.
* @throws ClientHTTPException throws when errors in parameters
*/
private ModelAndView getExportStatementsResult(final Repository repository, final HttpServletRequest request,
final HttpServletResponse response)
throws ClientHTTPException {
ProtocolUtil.logRequestParameters(request);
ValueFactory vf = repository.getValueFactory();
URI graph = getGraphName(request, vf);
RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
RDFWriterRegistry.getInstance());
Map<String, Object> model = new HashMap<String, Object>();
model.put(ExportStatementsView.CONTEXTS_KEY, new Resource[] { graph });
model.put(ExportStatementsView.FACTORY_KEY, rdfWriterFactory);
model.put(ExportStatementsView.USE_INFERENCING_KEY, true);
model.put(ExportStatementsView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
return new ModelAndView(ExportStatementsView.getInstance(), model);
}
示例2: getDeleteDataResult
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
/**
* Delete data from the graph.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @return the EmptySuccessView if successes
* @throws ClientHTTPException throws when there are errors in getting the name of the Graph
* @throws ServerHTTPException throws when errors happens update the data
*/
private ModelAndView getDeleteDataResult(final Repository repository,
final HttpServletRequest request, final HttpServletResponse response)
throws ClientHTTPException, ServerHTTPException {
ProtocolUtil.logRequestParameters(request);
ValueFactory vf = repository.getValueFactory();
URI graph = getGraphName(request, vf);
try {
RepositoryConnection repositoryCon = repository.getConnection();
synchronized (repositoryCon) {
repositoryCon.clear(graph);
}
repositoryCon.close();
return new ModelAndView(EmptySuccessView.getInstance());
} catch (RepositoryException e) {
throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
}
}
示例3: populateSesame
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
private void populateSesame(Repository testRepo) throws RepositoryException {
RepositoryConnection con = testRepo.getConnection();
ValueFactory f = testRepo.getValueFactory();
con.setNamespace("rdf", RDF_NS);
con.setNamespace("rdfs", RDFS_NS);
con.setNamespace("xsd", XSD_NS);
con.setNamespace("xsd", XSD_NS);
URI alice = f.createURI("http://example.org/people/alice");
URI bob = f.createURI("http://example.org/people/bob");
URI person = f.createURI("http://example.org/ontology/Person");
URI label = f.createURI(RDFS_NS, "label");
URI birthplace = f.createURI("http://example.org/ontology/birthplace");
Literal bobsName = f.createLiteral("Bob", "en");
Literal alicesName = f.createLiteral("Alice", "en");
Literal birthplaceLabel = f.createLiteral("birth place", "en");
Literal londonLabel = f.createLiteral("London", "en");
try {
con.add(birthplace, label, birthplaceLabel);
con.add(alice, RDF.TYPE, person);
con.add(alice, label, alicesName);
con.add(alice, birthplace, londonLabel);
con.add(bob, RDF.TYPE, person);
con.add(bob, label, bobsName);
con.add(bob, birthplace, londonLabel);
} finally {
con.close();
}
}
示例4: serve
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
ProtocolUtil.logRequestParameters(request);
Map<String, Object> model = new HashMap<String, Object>();
final boolean headersOnly = METHOD_HEAD.equals(request.getMethod());
if (!headersOnly) {
ValueFactory vf = repository.getValueFactory();
Resource[] contexts = ProtocolUtil.parseContextParam(request, Protocol.CONTEXT_PARAM_NAME, vf);
long size = -1;
try {
RepositoryConnection repositoryCon = repository.getConnection();
synchronized (repositoryCon) {
size = repositoryCon.size(contexts);
}
repositoryCon.close();
} catch (RepositoryException e) {
throw new ServerHTTPException("Repository error: " + e.getMessage(), e);
}
model.put(SimpleResponseView.CONTENT_KEY, String.valueOf(size));
}
return new ModelAndView(SimpleResponseView.getInstance(), model);
}
示例5: getExportStatementsResult
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
/**
* Get all statements and export them as RDF.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @return a model and view for exporting the statements.
* @throws ClientHTTPException throws when there errors in parsing the request
*/
private ModelAndView getExportStatementsResult(final Repository repository, final HttpServletRequest request,
final HttpServletResponse response)
throws ClientHTTPException {
ProtocolUtil.logRequestParameters(request);
ValueFactory vf = repository.getValueFactory();
Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
URI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);
boolean useInferencing = ProtocolUtil.parseBooleanParam(request, INCLUDE_INFERRED_PARAM_NAME, true);
RDFWriterFactory rdfWriterFactory = ProtocolUtil.getAcceptableService(request, response,
RDFWriterRegistry.getInstance());
Map<String, Object> model = new HashMap<String, Object>();
model.put(ExportStatementsView.SUBJECT_KEY, subj);
model.put(ExportStatementsView.PREDICATE_KEY, pred);
model.put(ExportStatementsView.OBJECT_KEY, obj);
model.put(ExportStatementsView.CONTEXTS_KEY, contexts);
model.put(ExportStatementsView.USE_INFERENCING_KEY, Boolean.valueOf(useInferencing));
model.put(ExportStatementsView.FACTORY_KEY, rdfWriterFactory);
model.put(ExportStatementsView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
model.put(ExportStatementsView.REPO_KEY, repository);
return new ModelAndView(ExportStatementsView.getInstance(), model);
}
示例6: getDeleteDataResult
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
/**
* Delete data from the repository.
*
* @param repository the Repository object
* @param request the HttpServletRequest object
* @param response the HttpServletResponse object
* @return EmptySuccessView if success
* @throws HTTPException throws when there are repository update errors
*/
private ModelAndView getDeleteDataResult(final Repository repository, final HttpServletRequest request,
final HttpServletResponse response)
throws HTTPException {
ProtocolUtil.logRequestParameters(request);
ValueFactory vf = repository.getValueFactory();
Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
URI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);
try {
RepositoryConnection repositoryCon = repository.getConnection();
synchronized (repositoryCon) {
repositoryCon.remove(subj, pred, obj, contexts);
}
repositoryCon.close();
return new ModelAndView(EmptySuccessView.getInstance());
} catch (RepositoryException e) {
if (e.getCause() != null && e.getCause() instanceof HTTPException) {
// custom signal from the backend, throw as HTTPException directly
// (see SES-1016).
throw (HTTPException) e.getCause();
} else {
throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
}
}
}
示例7: main
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
public static void main(String[] args) throws RDFParseException, UnsupportedRDFormatException, IOException,
RepositoryException, ReferringExpressionException, RDFHandlerException {
Options options = new Options();
new JCommander(options, args);
FileInputStream in = new FileInputStream(options.rdf);
Model m = Rio.parse(in, "http://localhost/", RDFFormat.NTRIPLES);
ReferringExpressionAlgorithm algorithm = null;
if (options.algorithm.equals(DaleReiterAlgorithm.class.getName())) {
algorithm = new DaleReiterAlgorithm(TypePriorities.dbPediaPriorities, TypePriorities.dbPediaIgnored);
if (options.verbose)
((ch.qos.logback.classic.Logger) DaleReiterAlgorithm.logger).setLevel(Level.DEBUG);
} else if (options.algorithm.equals(GardentAlgorithm.class.getName())) {
algorithm = new GardentAlgorithm(TypePriorities.dbPediaPriorities, TypePriorities.dbPediaIgnored);
if (options.verbose)
((ch.qos.logback.classic.Logger) GardentAlgorithm.logger).setLevel(Level.DEBUG);
} else if (options.algorithm.equals(GraphAlgorithm.class.getName())) {
algorithm = new GraphAlgorithm(TypePriorities.dbPediaPriorities, TypePriorities.dbPediaIgnored);
if (options.verbose)
((ch.qos.logback.classic.Logger) GraphAlgorithm.logger).setLevel(Level.DEBUG);
} else {
System.err.println("Unknown algorithm '" + options.algorithm + "'");
System.exit(-1);
}
Repository rep = new SailRepository(new MemoryStore());
rep.initialize();
ValueFactory f = rep.getValueFactory();
List<URI> confusors = new ArrayList<URI>(options.confusors.size());
for (String confusor : options.confusors)
confusors.add(f.createURI(confusor));
RepositoryConnection conn = rep.getConnection();
try {
conn.add(m);
URI referent = f.createURI(options.referent);
if (options.type != null)
conn.add(referent, RDF.TYPE, f.createURI(options.type));
ReferringExpression r = algorithm.resolve(referent, confusors, conn);
System.out.println(r);
} finally {
conn.close();
}
}
示例8: testResolve
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
public void testResolve() throws Exception {
Repository rep = new SailRepository(new MemoryStore());
rep.initialize();
ValueFactory f = rep.getValueFactory();
List<URI> confusors = new ArrayList<URI>();
URI confusor1 = f.createURI("http://alusivo/ballfar");
URI confusor2 = f.createURI("http://alusivo/redballclose");
confusors.add(confusor1);
confusors.add(confusor2);
URI referent = f.createURI("http://alusivo/redmiddle");
RepositoryConnection conn = rep.getConnection();
try {
URI balltype = f.createURI("http://alusivo/ball");
URI color = f.createURI("http://alusivo/color");
URI distance = f.createURI("http://alusivo/distance");
conn.add(new StatementImpl(referent, RDF.TYPE, balltype));
conn.add(new StatementImpl(confusor1, RDF.TYPE, balltype));
conn.add(new StatementImpl(confusor2, RDF.TYPE, balltype));
conn.add(new StatementImpl(referent, color, f.createLiteral("red")));
conn.add(new StatementImpl(confusor1, color, f.createLiteral("black")));
conn.add(new StatementImpl(confusor2, color, f.createLiteral("red")));
conn.add(new StatementImpl(referent, distance, f.createLiteral("middle")));
conn.add(new StatementImpl(confusor1, distance, f.createLiteral("far")));
conn.add(new StatementImpl(confusor2, distance, f.createLiteral("close")));
Map<String, List<String>> priorities = new HashMap<String, List<String>>();
priorities.put(balltype.toString(), Arrays.asList(new String[] { "type", "color", "distance" }));
DaleReiterAlgorithm algorithm = new DaleReiterAlgorithm(priorities, null);
ReferringExpression r = algorithm.resolve(referent, confusors, conn);
// System.out.println(r);
assertFalse(r.hasNegatives());
assertEquals(2, r.predicates().size());
assertEquals(color, r.predicates().get(0).getPredicate());
assertEquals(distance, r.predicates().get(1).getPredicate());
} finally {
conn.close();
}
}
示例9: testResolveMembers
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
public void testResolveMembers() throws Exception {
// https://hal.inria.fr/inria-00099410/document, Fig-4
Repository rep = new SailRepository(new MemoryStore());
rep.initialize();
ValueFactory f = rep.getValueFactory();
List<URI> confusors = new ArrayList<URI>();
URI referent = null;
URI[] x = new URI[6];
for (int i = 1; i <= 6; i++) {
x[i - 1] = f.createURI("http://alusivo/x" + i);
if (i == 6)
referent = x[i - 1];
else
confusors.add(x[i - 1]);
}
RepositoryConnection conn = rep.getConnection();
try {
URI person = f.createURI("http://alusivo/person");
URI member = f.createURI("http://alusivo/member");
URI boardmember = f.createURI("http://alusivo/boardmember");
URI secretary = f.createURI("http://alusivo/secretary");
URI president = f.createURI("http://alusivo/president");
URI treasurer = f.createURI("http://alusivo/treasurer");
for (int i = 0; i < 6; i++) {
conn.add(new StatementImpl(x[i], RDF.TYPE, person));
conn.add(new StatementImpl(x[i], RDF.TYPE, member));
if (i != 5)
conn.add(new StatementImpl(x[i], RDF.TYPE, boardmember));
}
conn.add(new StatementImpl(x[0], RDF.TYPE, president));
conn.add(new StatementImpl(x[1], RDF.TYPE, secretary));
conn.add(new StatementImpl(x[2], RDF.TYPE, treasurer));
Map<String, List<String>> priorities = new HashMap<String, List<String>>();
priorities.put(person.toString(), Arrays.asList(new String[] { "type" }));
GardentAlgorithm algorithm = new GardentAlgorithm(priorities, null);
ReferringExpression r = algorithm.resolve(referent, confusors, conn);
// System.out.println(r);
assertTrue(r.hasNegatives());
assertEquals(1, r.predicates().size());
assertTrue(r.predicates().get(0).isNegative());
assertEquals(boardmember, r.predicates().get(0).getObject());
} finally {
conn.close();
}
}
示例10: serve
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Override
public ModelAndView serve(final Repository repository, final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
Map<String, Object> model = new HashMap<String, Object>();
if (METHOD_GET.equals(request.getMethod())) {
Repository systemRepository = _repositoryManager.getSystemRepository();
ValueFactory vf = systemRepository.getValueFactory();
try {
RepositoryConnection con = systemRepository.getConnection();
try {
// connection before returning. Would be much better to stream the query result directly to the client.
List<String> bindingNames = new ArrayList<String>();
List<BindingSet> bindingSets = new ArrayList<BindingSet>();
TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL,
REPOSITORY_LIST_QUERY).evaluate();
try {
// Determine the repository's URI
StringBuffer requestURL = request.getRequestURL();
if (requestURL.charAt(requestURL.length() - 1) != '/') {
requestURL.append('/');
}
String namespace = requestURL.toString();
while (queryResult.hasNext()) {
QueryBindingSet bindings = new QueryBindingSet(queryResult.next());
String id = bindings.getValue("id").stringValue();
bindings.addBinding("uri", vf.createURI(namespace, id));
bindingSets.add(bindings);
}
bindingNames.add("uri");
bindingNames.addAll(queryResult.getBindingNames());
} finally {
queryResult.close();
}
model.put(QueryResultView.QUERY_RESULT_KEY,
new TupleQueryResultImpl(bindingNames, bindingSets));
} finally {
con.close();
}
} catch (RepositoryException e) {
throw new ServerHTTPException(e.getMessage(), e);
}
}
TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
TupleQueryResultWriterRegistry.getInstance());
model.put(QueryResultView.FILENAME_HINT_KEY, "repositories");
model.put(QueryResultView.FACTORY_KEY, factory);
model.put(QueryResultView.HEADERS_ONLY, METHOD_HEAD.equals(request.getMethod()));
return new ModelAndView(TupleQueryResultView.getInstance(), model);
}
示例11: init
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
private void init(Repository repository) {
this.repository = repository;
this.valueFactory = repository.getValueFactory();
}
示例12: testDirectRepositoryAccess
import org.openrdf.repository.Repository; //导入方法依赖的package包/类
@Test
public void testDirectRepositoryAccess() throws Exception {
Model model = getModelFactory().createModel();
model.open();
// fetch the Repository, a Connection and a ValueFactory
Repository repository = (Repository) model
.getUnderlyingModelImplementation();
RepositoryConnection connection = repository.getConnection();
ValueFactory factory = repository.getValueFactory();
// add a statement
model.addStatement(subject, predicate, object);
// convert the statement parts to OpenRDF data types
Resource openRdfSubject = ConversionUtil.toOpenRDF(subject, factory);
org.openrdf.model.URI openRdfPredicate = ConversionUtil.toOpenRDF(
predicate, factory);
Value openRdfObject = ConversionUtil.toOpenRDF(object, factory);
org.openrdf.model.URI context = RepositoryModel.DEFAULT_OPENRDF_CONTEXT;
// make sure this statement is contained in this model
assertTrue(connection.hasStatement(openRdfSubject, openRdfPredicate,
openRdfObject, false, context));
// make sure this statement can also be found through the Model API
ClosableIterator<? extends Statement> sit = model.findStatements(
subject, predicate, object);
assertNotNull(sit);
assertTrue(sit.hasNext());
Statement s2 = sit.next();
URI s2s = (URI) s2.getSubject();
URI s2p = s2.getPredicate();
URI s2o = (URI) s2.getObject();
assertEquals(subject, s2s);
assertEquals(predicate, s2p);
assertEquals(object, s2o);
// make sure that this statement is only returned once
assertFalse(sit.hasNext());
// clean-up
sit.close();
connection.close();
model.close();
}