本文整理汇总了Java中org.eclipse.rdf4j.repository.sail.SailRepository.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java SailRepository.getConnection方法的具体用法?Java SailRepository.getConnection怎么用?Java SailRepository.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.rdf4j.repository.sail.SailRepository
的用法示例。
在下文中一共展示了SailRepository.getConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.eclipse.rdf4j.repository.sail.SailRepository; //导入方法依赖的package包/类
/**
* Initialize repository and load triples
*
* @throws IOException
*/
public void init() throws IOException {
LOG.debug("Initialize repository");
repo = new SailRepository(new MemoryStore());
repo.initialize();
Optional<RDFFormat> fmt = Rio.getParserFormatForFileName(path.toString());
if (!fmt.isPresent()) {
throw new IOException("Could not determine file type");
}
LOG.debug("Adding triples");
BufferedReader r = Files.newBufferedReader(path);
Date start = new Date();
RepositoryConnection con = repo.getConnection();
try {
con.add(r, BASE_URI, fmt.get());
} catch (RepositoryException cve) {
LOG.error("Error adding triples", cve);
}
LOG.info("{} triples loaded in {} ms",
con.size(), new Date().getTime() - start.getTime());
if(con.isEmpty()) {
LOG.error("No statements loaded");
close();
}
}
示例2: timestampTest
import org.eclipse.rdf4j.repository.sail.SailRepository; //导入方法依赖的package包/类
@Test
public void timestampTest() throws Exception {
CloseableIteration<? extends Statement, SailException> iter;
HBaseSail sail = new TimeAwareHBaseSail(HBaseServerTestInstance.getInstanceConfig(), "timestamptable", true, 0, true, 0, null, null);
SailRepository rep = new SailRepository(sail);
rep.initialize();
SailRepositoryConnection con = rep.getConnection();
assertTrue(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(2 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
assertTrue(testUpdate(con, "delete {<http://whatever> <http://whatever> <http://whatever>} where {bind(1 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
assertFalse(testUpdate(con, "delete {<http://whatever> <http://whatever> <http://whatever>} where {bind(4 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
assertFalse(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(3 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
assertTrue(testUpdate(con, "insert {<http://whatever> <http://whatever> <http://whatever>} where {bind(4 as ?HALYARD_TIMESTAMP_SPECIAL_VARIABLE)}"));
rep.shutDown();
}
示例3: SKOSContainer
import org.eclipse.rdf4j.repository.sail.SailRepository; //导入方法依赖的package包/类
public SKOSContainer(File physicalPath) throws RepositoryException,
RDFParseException, IOException {
triplestore = new SailRepository(new MemoryStore());
triplestore.initialize();
factory = triplestore.getValueFactory();
RepositoryConnection connect = triplestore.getConnection();
// Try RDF/XML, fallback to N3 and fail if it's not enough
try {
connect.add(physicalPath, null, RDFFormat.RDFXML);
} catch (RDFParseException e) {
connect.add(physicalPath, null, RDFFormat.N3);
}
//changing skosxl prefLabel to skos prefLabel when we load the file
String queryString1 = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>"
+"PREFIX skosxl:<http://www.w3.org/2008/05/skos-xl#>"
+ "INSERT { ?x skos:prefLabel ?y} "
+ "WHERE {?x skosxl:prefLabel/skosxl:literalForm ?y}";
Update u1 = connect.prepareUpdate(QueryLanguage.SPARQL, queryString1);
u1.execute();
String queryString2 = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>"
+"PREFIX skosxl:<http://www.w3.org/2008/05/skos-xl#>"
+ "INSERT { ?x skos:altLabel ?y} "
+ "WHERE {?x skosxl:altLabel/skosxl:literalForm ?y}";
Update u2 = connect.prepareUpdate(QueryLanguage.SPARQL, queryString2);
u2.execute();
connect.close();
onto_uri = physicalPath.toURI();
// Preload
getAllLanguageInLabels();
topConceptOfCache = new HashMap<Resource, Resource>();
for(Resource scheme: getConceptSchemes()) {
for(Resource topConcept: getTopConcepts(scheme)) {
topConceptOfCache.put(topConcept, scheme);
}
}
}
示例4: setUp
import org.eclipse.rdf4j.repository.sail.SailRepository; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
repo = new SailRepository(new MemoryStoreWithHalyardStrategy());
repo.initialize();
con = repo.getConnection();
}
示例5: rewriteTestQuery
import org.eclipse.rdf4j.repository.sail.SailRepository; //导入方法依赖的package包/类
public void rewriteTestQuery() throws RepositoryException, QueryEvaluationException, RDFHandlerException, MalformedQueryException {
int i = 0;
for (Map.Entry<String, String> entry : queries.entrySet()) {
String query = entry.getKey();
String expected = entry.getValue();
Query qc = QueryFactory.create(query);
Query qcExpected = QueryFactory.create(expected);
System.out.println("Query" + (i + 1) + ":" + qc);
System.out.println("Expected" + (i + 1) + ":" + qcExpected);
String rewritten = QueryPagingRewriter2.rewriteQuery(query, limSizes[i], 0);
Query qcRewritten = QueryFactory.create(rewritten);
System.out.println("Rewritten" + (i + 1) + ":" + qcRewritten);
SPARQLRepository sparql = new SPARQLRepository("http://dbpedia.org/sparql");
sparql.initialize();
RepositoryConnection sparqlCon = sparql.getConnection();
GraphQuery graphQueryExp = sparqlCon.prepareGraphQuery(QueryLanguage.SPARQL, expected);
StatementCollector scExp = new StatementCollector();
graphQueryExp.evaluate(scExp);
List<Statement> resultStatementsExp = new ArrayList<>(scExp.getStatements());
Collections.<Statement> sort(resultStatementsExp, new BNodeIgnoreStatementComparator());
GraphQuery graphQueryRew = sparqlCon.prepareGraphQuery(QueryLanguage.SPARQL, rewritten);
StatementCollector scRew = new StatementCollector();
graphQueryRew.evaluate(scRew);
List<Statement> resultStatementsRew = new ArrayList<>(scRew.getStatements());
Collections.<Statement> sort(resultStatementsRew, new BNodeIgnoreStatementComparator());
Assert.assertEquals(expSizes[i], resultStatementsExp.size());
Assert.assertEquals(resultStatementsExp.size(), resultStatementsRew.size());
Iterator<Statement> itExp = resultStatementsExp.iterator();
Iterator<Statement> itRew = resultStatementsRew.iterator();
while (itExp.hasNext()) {
Assert.assertEquals(0, new BNodeIgnoreStatementComparator().compare(itExp.next(), itRew.next()));
}
ValueFactory vf = SimpleValueFactory.getInstance();
IRI uriExp = vf.createIRI("http://exp");
IRI uriRew = vf.createIRI("http://rew");
SailRepository memoryRepository = new SailRepository(new MemoryStore());
memoryRepository.initialize();
RepositoryConnection memCon = memoryRepository.getConnection();
RDFInserter scExp2 = new RDFInserter(memCon);
scExp2.enforceContext(uriExp);
graphQueryExp.evaluate(scExp2);
RDFInserter scRew2 = new RDFInserter(memCon);
scRew2.enforceContext(uriRew);
graphQueryRew.evaluate(scRew2);
Assert.assertEquals(memCon.size(uriExp), memCon.size(uriRew));
RepositoryResult<Statement> resultExp = memCon.getStatements(null, null, null, false, uriExp);
resultStatementsExp = new ArrayList<>();
while (resultExp.hasNext()) {
resultStatementsExp.add(resultExp.next());
}
Collections.<Statement> sort(resultStatementsExp, new BNodeIgnoreStatementComparator());
RepositoryResult<Statement> resultRew = memCon.getStatements(null, null, null, false, uriRew);
resultStatementsRew = new ArrayList<>();
while (resultRew.hasNext()) {
resultStatementsRew.add(resultRew.next());
}
Collections.<Statement> sort(resultStatementsRew, new BNodeIgnoreStatementComparator());
Assert.assertEquals(resultStatementsExp.size(), resultStatementsRew.size());
itExp = resultStatementsExp.iterator();
itRew = resultStatementsRew.iterator();
while (itExp.hasNext()) {
Statement exp = itExp.next();
Statement rew = itRew.next();
Assert.assertEquals(0, new BNodeIgnoreStatementComparator().compare(exp, rew));
}
i++;
}
}