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


Java Dataset.getNamedModel方法代码示例

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


在下文中一共展示了Dataset.getNamedModel方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: exec

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public QueryIterator exec(Binding binding, PropFuncArg argSubject,
		Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {

	argSubject = Substitute.substitute(argSubject, binding);
	argObject = Substitute.substitute(argObject, binding);
	
	if(!argObject.getArg().isVariable()) {
		throw new ExprEvalException("Right hand side of tosh:targetContains must be a variable");
	}
	
	Node targetNode = argSubject.getArgList().get(0);
	Node shapesGraphNode = argSubject.getArgList().get(1);
	
	Model currentModel = ModelFactory.createModelForGraph(execCxt.getActiveGraph());
	Dataset dataset = new DatasetWithDifferentDefaultModel(currentModel, DatasetImpl.wrap(execCxt.getDataset()));

	Model model = dataset.getNamedModel(shapesGraphNode.getURI());
	Resource target = (Resource) model.asRDFNode(targetNode);

	Set<Node> focusNodes = new HashSet<Node>();
	SHACLUtil.addNodesInTarget(target, dataset, focusNodes);
	return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), focusNodes.iterator(), execCxt);
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:25,代码来源:TargetContainsPFunction.java

示例5: createShapesModel

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/**
 * Creates a shapes Model for a given input Model.
 * The shapes Model is the union of the input Model with all graphs referenced via
 * the sh:shapesGraph property (and transitive includes or shapesGraphs of those).
 * @param model  the Model to create the shapes Model for
 * @return a shapes graph Model
 */
private static Model createShapesModel(Dataset dataset) {
	
	Model model = dataset.getDefaultModel();
	Set<Graph> graphs = new HashSet<Graph>();
	Graph baseGraph = model.getGraph();
	graphs.add(baseGraph);
	
	for(Statement s : model.listStatements(null, SH.shapesGraph, (RDFNode)null).toList()) {
		if(s.getObject().isURIResource()) {
			String graphURI = s.getResource().getURI();
			Model sm = dataset.getNamedModel(graphURI);
			graphs.add(sm.getGraph());
			// TODO: Include includes of sm
		}
	}
	
	if(graphs.size() > 1) {
		MultiUnion union = new MultiUnion(graphs.iterator());
		union.setBaseGraph(baseGraph);
		return ModelFactory.createModelForGraph(union);
	}
	else {
		return model;
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:33,代码来源:SHACLUtil.java

示例6: 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 = Repository.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-repository,代码行数:24,代码来源:VocabularyHandler.java

示例7: getFragmentTriples

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/**
 * Return all triples from the given dataset in one model, i.e., all graphs in the dataset are merged.
 * @param dataset The dataset to get the model from
 * @return  The model containing all triples from the graphs from the dataset.
 */
private Model getFragmentTriples(final Dataset dataset) {
    Model fragmentTriples = ModelFactory.createDefaultModel();

    // add unnamed graph
    Model defaultModel = dataset.getDefaultModel();
    fragmentTriples.add(defaultModel);

    // add named graph(s)
    Iterator<String> names = dataset.listNames();
    while (names.hasNext()) {
        String name = names.next();
        Model namedModel = dataset.getNamedModel(name);
        fragmentTriples.add(namedModel);
        namedModel.close();
    }
    dataset.close();
    return fragmentTriples;
}
 
开发者ID:LinkedDataFragments,项目名称:Client.Java,代码行数:24,代码来源:LinkedDataFragmentsClient.java

示例8: printStore

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static void printStore() {
    Store storesvc = AppConfig.getApp().getComponentAs("basestore",
            Store.class);
    storesvc.lock();
    try {
        Dataset ds = storesvc.asDataset();
        Model store = ds.getDefaultModel();
        System.out.println("Default model:");
        store.write(System.out, "Turtle");
        for (Iterator<String> i = ds.listNames(); i.hasNext();) {
            String graphName = i.next();
            Model graph = ds.getNamedModel(graphName);
            System.out.println("Graph " + graphName + ":");
            graph.write(System.out, "Turtle");
        }
    } finally {
        storesvc.end();
    }
}
 
开发者ID:UKGovLD,项目名称:registry-core,代码行数:20,代码来源:TestAPIDebug.java

示例9: SemaphoreModel

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public SemaphoreModel(File tdbDirectory, String graphName, boolean resetTDB) throws IOException {
	if (resetTDB && tdbDirectory.exists()) {
		FileUtils.deleteDirectory(tdbDirectory);
	}
	Dataset dataset = TDBFactory.createDataset(tdbDirectory.getAbsolutePath());

	if  ((graphName == null) || (graphName.trim().length() == 0)) {
		model = dataset.getNamedModel(graphName);
	} else {
		model = dataset.getDefaultModel();
	}
	setPrefixes();
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:14,代码来源:SemaphoreModel.java

示例10: loadModelToTdb

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/**
 * Fetch a model at the specified URI, load and return an TDB-backed Jena model.
 *
 * @param rdfUri
 * @param modelId
 * @param tDbDirectoryPath
 * @return
 */
public static Model loadModelToTdb(String rdfUri, String modelId, String tDbDirectoryPath) {

  if (logger.isDebugEnabled()) {
    logger.debug("RDF URI : {}", rdfUri);
    logger.debug("Model ID: {}", modelId);
    logger.debug("TDB  DIR: {}", tDbDirectoryPath);
  }

  Dataset dataset = TDBFactory.createDataset(tDbDirectoryPath);
  Model model = dataset.getNamedModel(modelId);
  TDBLoader.loadModel(model, rdfUri );
  return model;
}
 
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:22,代码来源:ModelLoader.java

示例11: doRun

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
private Model doRun(RDFNode focusNode, Resource shape, Dataset dataset) {
	URI shapesGraphURI = shapesGraph.get();
	if(shapesGraphURI == null) {
		shapesGraphURI = DefaultShapesGraphProvider.get().getDefaultShapesGraphURI(dataset);
	}
	Model shapesModel = dataset.getNamedModel(shapesGraphURI.toString());
	ShapesGraph shapes = new ShapesGraph(shapesModel);
	return ValidationEngineFactory.get().create(dataset, shapesGraphURI, shapes, null).validateNodesAgainstShape(
			Collections.singletonList(focusNode), shape.asNode()).getModel();
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:11,代码来源:HasShapeFunction.java

示例12: checkModel

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
private void checkModel(Model model, URI uri, boolean useCompression) {
    String fileName = FileBasedSink.generateFileName(uri.toString(), useCompression);
    File file = new File(tempDirectory.getAbsolutePath() + File.separator + fileName);
    if (model.size() == 0) {
        Assert.assertFalse("found a file " + file.getAbsolutePath() + " while the model of " + uri.toString()
                + " was empty (and shouldn't create a file).", file.exists());
        return;
    } else {
        Assert.assertTrue("Couldn't find the file " + file.getAbsolutePath() + " for model " + uri.toString(),
                file.exists());
    }

    Model readModel = null;
    Dataset readData = DatasetFactory.createMem();
    InputStream in = null;

    try {
        in = new FileInputStream(file);
        if (useCompression) {
            in = new GZIPInputStream(in);
        }
        RDFDataMgr.read(readData, in, Lang.NQ);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail("Couldn't read file for model " + uri.toString());
    } finally {
        IOUtils.closeQuietly(in);
    }

    readModel = readData.getNamedModel(uri.toString());
    String errorMsg = "The read model of " + uri.toString() + ": " + readModel
            + " does not fit the expected model: " + model;
    StmtIterator iterator = model.listStatements();
    Statement s;
    while (iterator.hasNext()) {
        s = iterator.next();
        Assert.assertTrue(errorMsg + " The read Model does not contain " + s, readModel.contains(s));
    }
    iterator = readModel.listStatements();
    while (iterator.hasNext()) {
        s = iterator.next();
        Assert.assertTrue(errorMsg + " The read Model has the additional triple " + s, readModel.contains(s));
    }
}
 
开发者ID:dice-group,项目名称:Squirrel,代码行数:45,代码来源:FileBasedSinkTest.java

示例13: run

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
private void run() {
    // Make some triples
    dsg.clear();
    Dataset dataset = dsg.toDataset();
    String modelName = "http://example.org/graphs/charles";
    
    String turtle = "@prefix foaf: <http://xmlns.com/foaf/0.1/> ."
            + "@prefix : <http://example.org/> ."
            +":charles a foaf:Person ; "
            + "        foaf:name \"Charles\" ;"
            + "        foaf:knows :jim ."
            + ":jim    a foaf:Person ;"
            + "        foaf:name \"Jim\" ;"
            + "        foaf:knows :charles .";
    
    System.out.println("Make a model and load the turtle into it (client-side)");
    Model model = ModelFactory.createDefaultModel();
    RDFDataMgr.read(model,  new StringReader(turtle), "", Lang.TURTLE);

    System.out.println("Store the model in MarkLogic.");
    dataset.addNamedModel(modelName, model);

    System.out.println("Make a triple by hand.");
    Model moreTriples = ModelFactory.createDefaultModel();
    Statement statement = ResourceFactory.createStatement(
        ResourceFactory.createResource("http://example.org/charles"),
        ResourceFactory.createProperty("http://example.org/hasDog"),
        ResourceFactory.createResource("http://example.org/vashko")
    );
    moreTriples.add( statement );

    System.out.println("Combine models and save");
    model.add(moreTriples);
    dataset.addNamedModel(modelName, model);

    System.out.println("Get it back into a new model (union of two original ones)");
    Model retrievedModel = dataset.getNamedModel(modelName);
    
    System.out.println("Remove model from MarkLogic");
    dataset.removeNamedModel(modelName);
}
 
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:42,代码来源:ModelCRUDExample.java

示例14: determineDatasetSize

import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static long determineDatasetSize(final Dataset dataset) {

		if (dataset == null) {

			LOG.debug("dataset is null - can't count statements");

			return -1;
		}

		final Iterator<String> graphURIs = dataset.listNames();

		if (graphURIs == null) {

			LOG.debug("there are now graphs in the dataset - can't count statements");

			return -1;
		}

		long statementCount = 0;

		while (graphURIs.hasNext()) {

			final String graphURI = graphURIs.next();

			if (!dataset.containsNamedModel(graphURI)) {

				continue;
			}

			final Model graphModel = dataset.getNamedModel(graphURI);

			if (graphModel == null) {

				continue;
			}

			statementCount += graphModel.size();
		}

		// note: don't reach long number limit :)

		return statementCount;
	}
 
开发者ID:dswarm,项目名称:dswarm-commons,代码行数:44,代码来源:RDFUtils.java


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