本文整理汇总了Java中org.apache.jena.atlas.lib.StrUtils.strjoinNL方法的典型用法代码示例。如果您正苦于以下问题:Java StrUtils.strjoinNL方法的具体用法?Java StrUtils.strjoinNL怎么用?Java StrUtils.strjoinNL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.atlas.lib.StrUtils
的用法示例。
在下文中一共展示了StrUtils.strjoinNL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseZookeeper
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
private static void parseZookeeper(Model model, ConfCluster confCluster) {
String qs = StrUtils.strjoinNL(prefixes,
"SELECT * {",
":zookeeper :server ?X" ,
" OPTIONAL { ?X :hostname ?hostname }",
" OPTIONAL { ?X :port ?port }",
"}") ;
Map<String, VNode> placements = new HashMap<>() ;
for ( QuerySolution row : Q.queryToList(model, qs) ) {
String host = Q.getStringOrNull(row, "hostname") ;
if ( host == null )
throw new LizardException("No zookeeper host") ;
String p = Q.getStringOrNull(row, "port") ;
if ( p == null )
throw new LizardException("No zookeeper port") ;
int port = Integer.parseInt(p) ;
ConfZookeeper confZK = ConfZookeeper.create(host, port) ;
confCluster.zkServer.add(confZK) ;
}
}
示例2: performQuery
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
public static void performQuery(Dataset ds) {
// Quack.setVerbose(true) ;
// ARQ.setExecutionLogging(InfoLevel.NONE);
String x = "<http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductType15>" ;
String qs1 = "SELECT * { VALUES ?s {"+x+"} ?s ?p ?o }" ;
String qs2 = StrUtils.strjoinNL("PREFIX : <http://example/>"
,"SELECT (count(*) AS ?C) "
,"{ ?s ?p ?o }" ) ;
String qs3 = "SELECT * { ?s ?p ?o }" ;
String qs = qs1 ;
Query q = QueryFactory.create(qs) ;
performQuery(ds, q);
}
示例3: parseTable
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
private static <X> RowList<X> parseTable(ItemParser<X> parser, String... s) {
RowListBuilder<X> builder = new RowListBuilderBase<>() ;
String x = StrUtils.strjoinNL(s) ;
Item item = SSE.parse(x) ;
ItemList list = item.getList() ;
BuilderLib.checkTag(list, "table") ;
list = list.cdr() ;
for (Item e : list) {
Row<X> r = parseRow(parser, e) ;
builder.add(r) ;
}
return builder.build() ;
}
示例4: loadOntology
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
/**
* Loads an ontology to the triple store, in the
* default graph.
* @param fileName File name with the ontology context.
*/
public static void loadOntology(InputStream fileName) {
List<String> ont = new ArrayList<>();
// Check if the ontology is already there
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String prefix = StrUtils.strjoinNL
( "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "PREFIX owl: <http://www.w3.org/2002/07/owl#>");
String query = prefix + "SELECT ?s WHERE {?s rdf:type owl:Ontology}";
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
ont.add(result.next().get("s").toString());
}
}
} finally {
dataset.end();
}
// Load QUDT ontology
if (ont.isEmpty()) {
dataset = ThingDirectory.get().dataset;
dataset.begin( ReadWrite.WRITE );
try {
Model m = dataset.getDefaultModel();
//RDFDataMgr.read(m, fileName);
RDFDataMgr.read(m, fileName, Lang.TURTLE);
dataset.commit();
} finally {
dataset.end();
}
}
}
示例5: main
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
public static void main(String...argv) {
JenaSystem.init();
Table table = new PFbyTable.Table() ;
add(table, ":s1", ":o1") ;
add(table, ":s1", ":o2") ;
add(table, ":s2", ":o1") ;
add(table, ":s2", ":o2") ;
add(table, ":s2", ":o3") ;
Dataset ds = DatasetFactory.create() ;
PropertyFunctionFactory pff = (uri)->new PFbyTable() ;
// rdf:rest is special to property functions!
String iri = "http://example/trans" ;
PFbyTable.addTable(NodeFactory.createURI(iri), table);
PropertyFunctionRegistry.get().put(iri, pff) ;
String x = StrUtils.strjoinNL
("PREFIX : <http://example/>"
,"PREFIX rdf: <"+RDF.getURI()+">"
,"PREFIX rdfs: <"+RDFS.getURI()+">"
//,"SELECT * { ?s ?p ?o . ?s rdfs:member :o1 . ?s rdf:rest :o1 }"
//,"SELECT * { ?s rdfs:member :o1 }"
,"SELECT * { { ?s :trans :o1 } UNION { :s2 :trans ?o } UNION { ?X :trans ?Y } }"
) ;
Query query = QueryFactory.create(x) ;
System.out.println(query);
Op op = Algebra.compile(query) ;
Op op1 = Algebra.optimize(op) ;
System.out.println(op1);
SSE.write(op1);
QueryExecution qExec = QueryExecutionFactory.create(query, ds) ;
QueryExecUtils.executeQuery(qExec);
}
示例6: queryData
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
private int queryData(Dataset dataset, String toponym){
int addressCounter = 0;
log.info("START") ;
long startTime = System.nanoTime() ;
String pre = StrUtils.strjoinNL(
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" ,
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" ,
"PREFIX schema: <http://schema.org/>" ,
"PREFIX text: <http://jena.apache.org/text#>" ,
"PREFIX ogc: <http://www.opengis.net/ont/geosparql#>") ;
String qs = StrUtils.strjoinNL( "SELECT DISTINCT ?s ?address ?wkt " ,
" { ?s text:query (schema:streetAddress '" + toponym + "') ;" ,
" schema:streetAddress ?address ;" ,
" ogc:geometry ?geo ." ,
" ?geo ogc:asWKT ?wkt ." ,
" }") ;
dataset.begin(ReadWrite.READ) ;
try {
Query q = QueryFactory.create(pre + "\n" + qs) ;
QueryExecution qexec = QueryExecutionFactory.create(q , dataset) ;
//QueryExecUtils.executeQuery(q, qexec) ;
ResultSet results = qexec.execSelect();
for( ; results.hasNext(); ){
addressCounter++;
QuerySolution sol = results.nextSolution();
System.out.println( sol.get("s") );
}
}
finally {
dataset.end() ;
}
long finishTime = System.nanoTime() ;
double time = (finishTime-startTime)/1.0e6 ;
log.info(String.format("FINISH - %.2fms", time)) ;
return addressCounter;
}
示例7: loadOntology
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
/**
* Loads an ontology to the triple store, in the
* default graph.
* @param fileName File name with the ontology context.
*/
public static void loadOntology(InputStream fileName) {
List<String> ont = new ArrayList<>();
// Check if the ontology is already there
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String prefix = StrUtils.strjoinNL
( "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "PREFIX owl: <http://www.w3.org/2002/07/owl#>");
String query = prefix + "SELECT ?s WHERE {?s rdf:type owl:Ontology}";
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
ont.add(result.next().get("s").toString());
}
}
} finally {
dataset.end();
}
// Load QUDT ontology
if (ont.isEmpty()) {
dataset = Repository.get().dataset;
dataset.begin( ReadWrite.WRITE );
try {
Model m = dataset.getDefaultModel();
//RDFDataMgr.read(m, fileName);
RDFDataMgr.read(m, fileName, Lang.TURTLE);
dataset.commit();
} finally {
dataset.end();
}
}
}
示例8: dataset
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
public static LzDatasetDesc dataset(Resource lz) {
String qsDatasets = StrUtils.strjoinNL(Config.prefixes,
"SELECT * {",
" ?lz a lizard:Dataset ;",
" OPTIONAL { ?lz :name ?name }",
" OPTIONAL { ?lz :indexes ?indexes }",
" OPTIONAL { ?lz :nodetable ?nodes }",
"}") ;
List<QuerySolution> rows = Q.queryToList(lz.getModel(), qsDatasets, "lz", lz) ;
if ( rows.size() != 1 )
throw new LizardException("Multiple dataset descriptions") ;
QuerySolution row = rows.get(0) ;
String name = Q.getStringOrNull(row, "name") ;
if ( name == null ) {
if ( lz.isAnon() )
name = "dataset" ;
else
name = lz.getLocalName() ;
}
List<Resource> indexes = Q.getListResourceOrNull(row, "indexes") ;
if ( indexes == null )
throw new LizardException("No :indexes in lizard:Dataset description") ;
List<Resource> nodes = Q.getListResourceOrNull(row, "nodes") ;
if ( nodes == null )
throw new LizardException("No :nodes in lizard:Dataset description") ;
LzDatasetDesc desc = new LzDatasetDesc(lz, name, indexes, nodes) ;
return desc ;
}
示例9: findNodeServices
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
private static Map<Resource, ConfNodeTable> findNodeServices(Model model, ConfCluster confCluster, Map<Resource, DataServer> servers) {
String qsNodeServices = StrUtils.strjoinNL(prefixes,
"SELECT * {",
" ?svc a :NodeService ;",
" OPTIONAL { ?svc :name ?name } ",
" OPTIONAL { ?svc :servers ?sList }",
"}") ;
Map<Resource, ConfNodeTable> svcs = new LinkedHashMap<>() ;
for ( QuerySolution row : Q.queryToList(model, qsNodeServices) ) {
//@@ Check one nodetable.
Resource svc = row.getResource("svc") ;
if ( svcs.containsKey(svc) )
throw new LizardException("Malform declaration for: "+svc) ;
String name = Q.getStringOrNull(row, "name") ;
if ( name == null )
throw new LizardException("No name for NodeService: "+svc) ;
Resource list = Q.getResourceOrNull(row, "sList") ;
if ( list == null )
throw new LizardException(name+" : No shard list for NodeService") ;
List<Resource> sList = Q.listResources(list) ;
FmtLog.debug(logConf, "Node service <%s>:%s", svc.getURI(), name) ;
int N = sList.size() ;
ConfNodeTable confNode = new ConfNodeTable(1, N) ;
// Process servers.
AtomicInteger integer = new AtomicInteger(0) ;
sList.forEach(svr -> {
DataServer ds = servers.get(svr) ;
if ( ds == null )
throw new LzConfigurationException("No server found: "+svr) ;
int i = integer.incrementAndGet() ;
ConfNodeTableElement nt = new ConfNodeTableElement(ds.name, ds.data, confNode, ds.addr) ;
confCluster.eltsNodeTable.add(nt) ;
});
confCluster.dataset.nodeTable = confNode ;
svcs.put(svc, confNode) ;
}
return svcs ;
}
示例10: dataServers
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
/** Extract all data servers */
private static Map<Resource, DataServer> dataServers(Model model, String resourceType) {
String qs = StrUtils.strjoinNL(prefixes,
"SELECT * {",
" ?nServer a "+resourceType ,
" OPTIONAL { ?nServer :name ?name }",
" OPTIONAL { ?nServer :hostname ?host }",
" OPTIONAL { ?nServer :port ?port }",
" OPTIONAL { ?nServer :data ?data }",
"}") ;
Map<Resource, DataServer> servers = new HashMap<>() ;
for ( QuerySolution row : Q.queryToList(model, qs) ) {
Resource svr = row.getResource("nServer") ;
String name = Q.getStringOrNull(row, "name") ;
if ( name == null )
throw new LizardException("No name for "+svr) ;
String host = Q.getStringOrNull(row, "host") ;
if ( host == null )
throw new LizardException(name+" : No host") ;
String p = Q.getStringOrNull(row, "port") ;
if ( p == null )
throw new LizardException(name+" : No port") ;
int port = Integer.parseInt(p) ;
String data = Q.getStringOrNull(row, "data") ;
if ( data == null )
throw new LizardException(name+" : No data location") ;
VNodeAddr addr = VNodeAddr.create(host, port) ;
DataServer ds = new DataServer(svr, name, data, addr) ;
servers.put(svr, ds) ;
}
return servers ;
}
示例11: main
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
public static void main(String... argv)
{
String directory = "MyDatabases/DB1" ;
Dataset dataset = TDBFactory.createDataset(directory) ;
// Start WRITE transaction.
// It's possible to read from the datet inside the write transaction.
// An application can have other Datasets, in the same JVM,
// tied to the same TDB database performing read
// transactions concurrently. If another write transaction
// starts, the call of dataset.begin(WRITE) blocks until
// existing writer finishes.
dataset.begin(ReadWrite.WRITE) ;
try
{
GraphStore graphStore = GraphStoreFactory.create(dataset) ;
// Do a SPARQL Update.
String sparqlUpdateString = StrUtils.strjoinNL(
"PREFIX . <http://example/>",
"INSERT { :s :p ?now } WHERE { BIND(now() AS ?now) }"
) ;
execUpdate(sparqlUpdateString, graphStore) ;
dataset.commit() ;
// Or call .abort()
} finally
{
// Notify the end of the transaction.
// The transaction was finished at the point .commit or .abort was called.
// .end will force an abort() if no previous call to .commit() or .abort()
// has occurred, so .end() help manage track the state of the transaction.
// .end() can be called multiple times for the same .begin(WRITE)
dataset.end() ;
}
}
示例12: parseJoinKey
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
public static JoinKey parseJoinKey(String... s) {
String x = StrUtils.strjoinNL(s) ;
Item item = SSE.parse(x) ;
ItemList list = item.getList() ;
BuilderLib.checkTag(list, "key") ;
JoinKey.Builder builder = new JoinKey.Builder() ;
list = list.cdr() ;
for (Item e : list) {
Var v = Var.alloc(e.getNode()) ;
builder.add(v) ;
}
return builder.build() ;
}
示例13: listRDFTypeValues
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
/**
* Returns a list of type values for the given property.
* @param propertyURI Complete URI of the property (baseUri + propertyName).
* @return List of values for the given property.
*/
public static List<String> listRDFTypeValues(String propertyURI) {
List<String> vals = new ArrayList<>();
Dataset dataset = ThingDirectory.get().dataset;
String prefix = StrUtils.strjoinNL
( "PREFIX td: <http://w3c.github.io/wot/w3c-wot-td-ontology.owl#>"
, "PREFIX qu: <http://purl.oclc.org/NET/ssnx/qu/qu#>"
, "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
, "PREFIX owl: <http://www.w3.org/2002/07/owl#>"
, "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
, "PREFIX dim: <http://purl.oclc.org/NET/ssnx/qu/dim#>"
, "PREFIX quantity: <http://purl.oclc.org/NET/ssnx/qu/quantity#>");
String query = prefix + "SELECT ?unit WHERE { "
+ "GRAPH ?g { "
+ " ?td td:hasProperty ?property . "
+ "?property a ?propertytype . "
+ "} "
+ "?propertytype a ?class . "
+ "?class rdfs:subClassOf ?s . "
+ "?s owl:onProperty qu:unitKind ; "
+ "owl:allValuesFrom ?unitKind . "
+ "?unit rdf:type ?unitKind . "
+ "FILTER (?property = <" + propertyURI + ">)"
+ "}";
dataset.begin(ReadWrite.READ);
try {
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
vals.add(result.next().get("unit").toString());
}
}
} finally {
dataset.end();
}
return vals;
}
示例14: listThingDescriptionsFromTextSearch
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
/**
* Does a full text searc using jena-text.
* Returns the uris of the TDs that matched with the given key words.
* @param keyWords Words to find in a TD content.
* @return List of uris
*/
public static List<String> listThingDescriptionsFromTextSearch(String keyWords) {
List<String> tds = new ArrayList<>();
// Construct query
String qMatch = "";
String predicate, property;
predicate = " text:query ";
property = "rdfs:comment";
qMatch += " ?g " + predicate + "(" + property + " " + keyWords + ") . ";
String prefix = StrUtils.strjoinNL
( "PREFIX text: <http://jena.apache.org/text#>"
, "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
, "PREFIX td: <http://www.w3c.org/wot/td#>"
, "PREFIX qu: <http://purl.oclc.org/NET/ssnx/qu/qu#>"
, "PREFIX unit: <http://purl.oclc.org/NET/ssnx/qu/unit#>"
, "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>");
// Run the query
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String query = "SELECT DISTINCT ?g WHERE { " + qMatch + " GRAPH ?g { FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
Query q = QueryFactory.create(prefix + "\n" + query);
try {
QueryExecution qexec = QueryExecutionFactory.create(q , dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
} catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例15: geocodeAddress
import org.apache.jena.atlas.lib.StrUtils; //导入方法依赖的package包/类
/**
* Search for an address (a node in OSM).
* @param graph The input graph contains a schema:streetAddress with the name of the street, the locality and the country code .
* @return Returns the geocoordinates of the street that has been found.
*/
private TripleCollection geocodeAddress(Dataset ds, Address address){
TripleCollection geoCodeRdf = new SimpleMGraph();
String pre = StrUtils.strjoinNL(
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" ,
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" ,
"PREFIX schema: <http://schema.org/>" ,
"PREFIX text: <http://jena.apache.org/text#>" ,
"PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>" ,
"PREFIX ogc: <http://www.opengis.net/ont/geosparql#>") ;
String qs = StrUtils.strjoinNL( "SELECT ?s ?street ?lat ?lon" ,
" { ?s text:query (schema:streetAddress '" + address.getStreetAddress() + "') ;" ,
" schema:streetAddress ?street ;" ,
" schema:addressLocality \"" + address.getLocality() + "\" ;" ,
" schema:addressCountry \"" + address.getCountryCode() + "\" ;" ,
" geo:lat ?lat ;" ,
" geo:long ?lon ." ,
" }") ;
log.info(pre + "\n" + qs);
ds.begin(ReadWrite.READ) ;
try {
Query q = QueryFactory.create(pre + "\n" + qs) ;
QueryExecution qexec = QueryExecutionFactory.create(q , ds) ;
//QueryExecUtils.executeQuery(q, qexec) ;
ResultSet results = qexec.execSelect();
int numberOfAddresses = 0;
for( ; results.hasNext(); ){
QuerySolution sol = results.nextSolution();
String streetUriName = sol.getResource("s").getURI();
String streetName = sol.getLiteral("?street").getString();
String latitude = sol.getLiteral("?lat").getLexicalForm();
String longitude = sol.getLiteral("?lon").getLexicalForm();
UriRef addressRef = new UriRef(streetUriName);
geoCodeRdf.add(new TripleImpl(addressRef, schema_streetAddress, new PlainLiteralImpl(streetName)));
geoCodeRdf.add(new TripleImpl(addressRef, schema_addressLocality, new PlainLiteralImpl( address.getLocality())) );
geoCodeRdf.add(new TripleImpl(addressRef, schema_addressCountry, new PlainLiteralImpl( address.getCountryCode())) );
geoCodeRdf.add(new TripleImpl(addressRef, geo_lat, new PlainLiteralImpl( latitude )) );
geoCodeRdf.add(new TripleImpl(addressRef, geo_lon, new PlainLiteralImpl( longitude )) );
numberOfAddresses++;
}
log.info("Number of addresses like " + address.getStreetAddress() + " found: " + numberOfAddresses);
}
finally {
ds.end() ;
}
return geoCodeRdf;
}