当前位置: 首页>>代码示例>>Java>>正文


Java Dataset类代码示例

本文整理汇总了Java中org.apache.jena.query.Dataset的典型用法代码示例。如果您正苦于以下问题:Java Dataset类的具体用法?Java Dataset怎么用?Java Dataset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Dataset类属于org.apache.jena.query包,在下文中一共展示了Dataset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.jena.query.Dataset; //导入依赖的package包/类
public static void main(String[] args) {

    if (args.length != 3) {
      System.err.println("Wrong arguments");
      showUsage();
    }
    System.out.println("Model file   : " + args[0]);
    System.out.println("Model URI    : " + args[1]);
    System.out.println("Model tdb dir: " + args[2]);

    Dataset dataset = TDBFactory.createDataset(args[2]);
    try {
      Model model = dataset.getNamedModel(args[1]);
      TDBLoader.loadModel(model, args[0]);
    } finally {
      dataset.close();
    }
  }
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:19,代码来源:SKOSTDBLoader.java

示例2: listVocabularies

import org.apache.jena.query.Dataset; //导入依赖的package包/类
public static Set<String> listVocabularies() {
	Set<String> tds = new HashSet<>();
	Dataset dataset = ThingDirectory.get().dataset;
	dataset.begin(ReadWrite.READ);

	try {
		String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?o a <http://www.w3.org/2002/07/owl#Ontology> } }";
		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;
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:21,代码来源:VocabularyUtils.java

示例3: loadOEModelToTdb

import org.apache.jena.query.Dataset; //导入依赖的package包/类
/**
  * Fetch a model from Ontology Editor, load and return as TDB-backed Jena model.
  *
  * @param endpoint
  * @param tDbDirectoryPath
  * @return
* @throws OEConnectionException 
* @throws IOException 
  */
 public static Model loadOEModelToTdb(OEModelEndpoint endpoint, String tDbDirectoryPath) throws IOException, OEConnectionException {
   Preconditions.checkNotNull(endpoint);
   Preconditions.checkArgument(!Strings.isNullOrEmpty(tDbDirectoryPath));

   if (logger.isDebugEnabled()) {
     logger.debug("OEModelEndpoint: {}", endpoint);
     logger.debug("TDB Dir path   : {}", tDbDirectoryPath);
   }

   String modelAsTTL = endpoint.fetchData();

   Dataset dataset = TDBFactory.createDataset(tDbDirectoryPath);
   Model model = dataset.getNamedModel(endpoint.modelIri);
   model.read(new ByteArrayInputStream(modelAsTTL.getBytes()), "TTL");
   return model;
 }
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:26,代码来源:ModelLoader.java

示例4: init

import org.apache.jena.query.Dataset; //导入依赖的package包/类
public void init(String db, String uri, String lucene) {

    	Dataset ds = TDBFactory.createDataset(db);
        
        // Lucene configuration
        try {
            Directory luceneDir = FSDirectory.open(new File(lucene));
            EntityDefinition entDef = new EntityDefinition("comment", "text", RDFS.comment);
            // Set uid in order to remove index entries automatically
            entDef.setUidField("uid");
            StandardAnalyzer stAn = new StandardAnalyzer(Version.LUCENE_4_9);
            dataset = TextDatasetFactory.createLucene(ds, luceneDir, entDef, stAn);
            
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        baseURI = uri;
        servers = new ArrayList<>();
        tdQueue = new PriorityQueue<ThingDescription>();
        loadTDQueue();
    }
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:24,代码来源:ThingDirectory.java

示例5: get

import org.apache.jena.query.Dataset; //导入依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
	RESTResource resource = new RESTResource(uri.toString(),this);

	Dataset dataset = ThingDirectory.get().dataset;
	dataset.begin(ReadWrite.READ);

	try {
		Model result = dataset.getNamedModel(uri.toString());
		if (!result.isEmpty()) {
			resource.contentType = "text/turtle";
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			result.write(out, "Turtle");
			resource.content = out.toString();
		} else {
			throw new RESTException();
		}
	} finally {
		dataset.end();
	}
	
	return resource;
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:24,代码来源:VocabularyHandler.java

示例6: delete

import org.apache.jena.query.Dataset; //导入依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
	Dataset dataset = ThingDirectory.get().dataset;
	dataset.begin(ReadWrite.WRITE);
	
	try {
		dataset.getDefaultModel().getResource(uri.toString()).removeProperties();
		dataset.removeNamedModel(uri.toString());
		deleteToAll(uri.getPath());
		dataset.commit();
	} catch (Exception e) {
		// TODO distinguish between client and server errors
		throw new RESTException();
	} finally {
		dataset.end();
	}
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:18,代码来源:VocabularyHandler.java

示例7: get

import org.apache.jena.query.Dataset; //导入依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
	RESTResource resource = new RESTResource(uri.toString(),this);

	Dataset dataset = ThingDirectory.get().dataset;
	dataset.begin(ReadWrite.READ);

	try {
		String q = "SELECT ?str WHERE { <" + uri + "> <" + DC.source + "> ?str }";
		QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
		ResultSet result = qexec.execSelect();

		if (result.hasNext()) {
			resource.contentType = "application/ld+json";
			resource.content = result.next().get("str").asLiteral().getLexicalForm();
		} else {
			throw new RESTException();
		}
	} finally {
		dataset.end();
	}
	
	return resource;
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:25,代码来源:ThingDescriptionHandler.java

示例8: delete

import org.apache.jena.query.Dataset; //导入依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
	Dataset dataset = ThingDirectory.get().dataset;
	dataset.begin(ReadWrite.WRITE);
	try {
		dataset.getDefaultModel().createResource(uri.toString()).removeProperties();
		dataset.removeNamedModel(uri.toString());
		deleteToAll(uri.getPath());
		dataset.commit();
		
		// Remove from priority queue
		ThingDescription td = new ThingDescription(uri.toString());
		ThingDirectory.get().tdQueue.remove(td);
		ThingDirectory.get().setTimer();
					
	} catch (Exception e) {
		// TODO distinguish between client and server errors
		throw new RESTException();
	} finally {
		dataset.end();
	}
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:23,代码来源:ThingDescriptionHandler.java

示例9: listThingDescriptions

import org.apache.jena.query.Dataset; //导入依赖的package包/类
public static List<String> listThingDescriptions(String query) {
List<String> tds = new ArrayList<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);

try {
  String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { " + query + " FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
  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;
 }
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:23,代码来源:ThingDescriptionUtils.java

示例10: getThingDescriptionIdFromUri

import org.apache.jena.query.Dataset; //导入依赖的package包/类
/**
  * Returns the ID of a thing description stored in the database given its URI.
  * @param uri URI of the thing description we want to return.
  * @return the ID of the thing description.
  */
 public static String getThingDescriptionIdFromUri(String uri) {

String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> <" + uri + ">";
String id = "NOT FOUND";
  
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);

try {
  String q = "SELECT ?g_id WHERE { GRAPH ?g_id { " + query + " }}";
  QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
  ResultSet result = qexec.execSelect();
  while (result.hasNext()) { 
    id = result.next().get("g_id").toString();
  }
} catch (Exception e) {
  e.printStackTrace();
  throw e;
} finally {
  dataset.end();
}

return id;
 }
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:30,代码来源:ThingDescriptionUtils.java

示例11: listThingDescriptionsUri

import org.apache.jena.query.Dataset; //导入依赖的package包/类
/**
  * Returns a list of the thing descriptions URIs.
  * @return a list of URIs stored in the database.
  */
 public static List<String> listThingDescriptionsUri() {

List<String> tds = new ArrayList<>();
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> ?uri";
  
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);

try {
  String q = "SELECT ?uri WHERE { GRAPH ?g_id { " + query + " }}";
  try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
	ResultSet result = qexec.execSelect();
	while (result.hasNext()) { 
	tds.add(result.next().get("uri").toString());
	}
  }
catch (Exception e) {
  throw e;
}
} finally {
  dataset.end();
}

return tds;
 }
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:30,代码来源:ThingDescriptionUtils.java

示例12: queryData

import org.apache.jena.query.Dataset; //导入依赖的package包/类
public static List<String> queryData(String query){
	Dataset db = TDBFactory.createDataset("temp/dataset");
	db.begin(ReadWrite.READ);
    Model model = db.getDefaultModel();
    Query q = QueryFactory.create(query);
    QueryExecution qexec = QueryExecutionFactory.create(query, model);
    ResultSet results = qexec.execSelect();
    List<String> answer = new ArrayList<String>();
    while(results.hasNext()){
    	QuerySolution t = results.nextSolution();
    	RDFNode x  = t.get("x");
    	String s = x.toString();
	System.out.println(s);
    	answer.add(s.substring(7));
    }
    qexec.close();
    db.close();
    return answer;
}
 
开发者ID:kunal15595,项目名称:smart-question-answering-nlp,代码行数:20,代码来源:Database.java

示例13: getDatasetGraph

import org.apache.jena.query.Dataset; //导入依赖的package包/类
private Optional<DatasetGraph> getDatasetGraph(final String url) {
    try (final FcrepoResponse head = headResource(url)) {

        final List<URI> types = head.getLinkHeaders("type");
        LOGGER.debug("Link headers: " + types);

        if (types.contains(URI.create(LDP + "NonRDFSource"))) {
            // Is this a NonRDFSource?
            LOGGER.debug("Get NonRdfSource Description for: {}", url);
            verifyNonRdfSourceDescription(head);
            return Optional.empty();

        } else {
            // This is a container
            LOGGER.debug("Get triples for: {}", url);
            try (final FcrepoResponse get = getResource(url)) {
                final Model model = createDefaultModel();
                final Dataset d = new DatasetImpl(model.read(get.getBody(), "", TEXT_TURTLE));
                return Optional.of(d.asDatasetGraph());
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:awoods,项目名称:fcrepo-java-client-etc,代码行数:26,代码来源:Walker.java

示例14: main

import org.apache.jena.query.Dataset; //导入依赖的package包/类
public static void main(String ...args) {
    // -- Base dataset 
    DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem();

    // -- Destination for changes.
    // Text form of output.  
    OutputStream out = System.out;
    // Create an RDFChanges that writes to "out".
    RDFChanges changeLog = RDFPatchOps.textWriter(out);

    // Combined datasetgraph and changes. 
    DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog);

    // Wrap in the Dataset API
    Dataset ds = DatasetFactory.wrap(dsg);

    // --------
    // Do something. Read in data.ttl inside a transaction.
    // (data.ttl is in src/main/resources/)
    Txn.executeWrite(ds,
        ()->RDFDataMgr.read(dsg, "data.ttl")
        );
}
 
开发者ID:afs,项目名称:rdf-delta,代码行数:24,代码来源:DeltaEx1_DatasetWithPatchLog.java

示例15: exec

import org.apache.jena.query.Dataset; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
final void exec(
        final Dataset inputDataset,
        final StreamRDF outputStream,
        final BindingHashMapOverwrite binding,
        final BNodeMap bNodeMap) {

    final StringBuilder sb = new StringBuilder("Output triples");
    bgp.getList().stream()
            .map((t) -> TemplateLib.subst(t, binding, bNodeMap.asMap()))
            .filter((t2) -> (t2.isConcrete()))
            .forEach((t2) -> {
                if (LOG.isTraceEnabled()) {
                    sb.append("\n\t").append(t2);
                }
                outputStream.triple(t2);
            });
    LOG.trace(sb.toString());
}
 
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:22,代码来源:GenerateTriplesPlanImpl.java


注:本文中的org.apache.jena.query.Dataset类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。