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


Java ModelFactory.createModelForGraph方法代码示例

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


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

示例1: createModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
@Override
protected Model createModel(String dbId) {
    Model model = null;
    try {
        File hdtFile = getHDTPath(dbId).toFile();
        if (hdtFile.exists()) {
            boolean useIdx = useIndex(dbId);
            String hdtFilePathStr = hdtFile.getAbsolutePath();
            logger.info(marker, "Loading '{}', useIndex={}", hdtFilePathStr, useIdx);
            HDT hdt = useIdx ? HDTManager.mapIndexedHDT(hdtFilePathStr, null) : HDTManager.loadHDT(hdtFilePathStr, null);
            HDTGraph graph = new HDTGraph(hdt);
            model = ModelFactory.createModelForGraph(graph);
            return model;
        }

       throw new FileNotFoundException("HDT file not found: '" + hdtFile + "'");

    } catch (Exception e) {
        throw new StarGraphException(e);
    }
    finally {
        if (model == null) {
            logger.error(marker, "No Graph Model instantiated for {}", dbId);
        }
    }
}
 
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:27,代码来源:HDTModelFactory.java

示例2: initDefaultModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
private void initDefaultModel() throws GraphNotFoundException {
	if(defaultGraphs.isEmpty()) {
		defaultModel = super.getDefaultModel();
	}
	else {
		if(defaultGraphs.size() == 1) {
			String defaultGraphURI = defaultGraphs.iterator().next();
			defaultModel = getNamedModel(defaultGraphURI);
			if(defaultModel == null) {
				throw new GraphNotFoundException("Named graph " + defaultGraphURI + " not found");
			}
		}
		else {
			MultiUnion multiUnion = JenaUtil.createMultiUnion();
			for(String graphURI : defaultGraphs) {
				Model model = getNamedModel(graphURI);
				if(model == null) {
					throw new GraphNotFoundException("Named graph " + graphURI + " not found");
				}
				multiUnion.addGraph(model.getGraph());
			}
			defaultModel = ModelFactory.createModelForGraph(multiUnion);
		}
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:26,代码来源:FromDataset.java

示例3: exec

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的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

示例4: createModelWithEntailment

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
@Override
public Model createModelWithEntailment(Dataset dataset, URI shapesGraphURI, ShapesGraph shapesGraph, ProgressMonitor monitor) throws InterruptedException {
	Model dataModel = dataset.getDefaultModel();
	Model inferencesModel = JenaUtil.createDefaultModel();
	MultiUnion unionGraph = new MultiUnion(new Graph[] {
		dataModel.getGraph(),
		inferencesModel.getGraph()
	});
	Model unionDataModel = ModelFactory.createModelForGraph(unionGraph);
	RuleEngine engine = new RuleEngine(dataset, shapesGraphURI, shapesGraph, inferencesModel);
	engine.setProgressMonitor(monitor);
	engine.executeAll();
	if(inferencesModel.isEmpty()) {
		return dataModel;
	}
	else {
		return unionDataModel;
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:20,代码来源:RulesEntailment.java

示例5: createIncludesModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/**
 * Creates an includes Model for a given input Model.
 * The includes Model is the union of the input Model will all graphs linked via
 * sh:include (or owl:imports), transitively. 
 * @param model  the Model to create the includes Model for
 * @param graphURI  the URI of the named graph represented by Model
 * @return a Model including the semantics
 */
public static Model createIncludesModel(Model model, String graphURI) {
	Set<Graph> graphs = new HashSet<Graph>();
	Graph baseGraph = model.getGraph();
	
	addIncludes(baseGraph, graphURI, graphs, new HashSet<String>());
	
	if(graphs.size() == 1) {
		return model;
	}
	else {
		MultiUnion union = new MultiUnion(graphs.iterator());
		union.setBaseGraph(baseGraph);
		return ModelFactory.createModelForGraph(union);
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:24,代码来源:SHACLUtil.java

示例6: createShapesModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的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

示例7: createDefaultValueTypesModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/**
 * Runs the rule to infer missing rdf:type triples for certain blank nodes.
 * @param model  the input Model
 * @return a new Model containing the inferred triples
 */
public static Model createDefaultValueTypesModel(Model model) {
	String sparql = JenaUtil.getStringProperty(DASH.DefaultValueTypeRule.inModel(model), SH.construct);
	if(sparql == null) {
		throw new IllegalArgumentException("Shapes graph does not include " + TOSH.PREFIX + ":" + DASH.DefaultValueTypeRule);
	}
	Model resultModel = JenaUtil.createMemoryModel();
	MultiUnion multiUnion = new MultiUnion(new Graph[] {
		model.getGraph(),
		resultModel.getGraph()
	});
	Model unionModel = ModelFactory.createModelForGraph(multiUnion);
	Query query = ARQFactory.get().createQuery(model, sparql);
	try(QueryExecution qexec = ARQFactory.get().createQueryExecution(query, unionModel)) {
	    qexec.execConstruct(resultModel);
	    return resultModel;    
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:23,代码来源:SHACLUtil.java

示例8: validate

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public Model validate(Model dataModel, Model shapesModel) throws Exception {
	Model shaclModel = SHACLSystemModel.getSHACLModel();
	MultiUnion unionGraph = new MultiUnion(new Graph[] {
		shaclModel.getGraph(),
		dataModel.getGraph(),
		shapesModel.getGraph()
	});
	Model all = ModelFactory.createModelForGraph(unionGraph);

	// Make sure all sh:Functions are registered
	SHACLFunctions.registerFunctions(all);
	
	URI shapesGraphURI = URI.create("urn:x-shacl-shapes-graph:" + UUID.randomUUID().toString());
	Dataset dataset = ARQFactory.get().getDataset(dataModel);
	dataset.addNamedModel(shapesGraphURI.toString(), all);
       
	Model results = new ModelConstraintValidator().validateModel(dataset, shapesGraphURI, null, true, null, null).getModel();
       results.setNsPrefixes(all);
	return results; 
}
 
开发者ID:labra,项目名称:shaclRunner,代码行数:21,代码来源:ShaclValidator.java

示例9: getBaseModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public static Model getBaseModel(Model model) {
	Graph baseGraph = getBaseGraph(model);
	if(baseGraph == model.getGraph()) {
		return model;
	}
	else {
		return ModelFactory.createModelForGraph(baseGraph);
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:10,代码来源:JenaUtil.java

示例10: validateModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/**
 * Validates a given data Model against all shapes from a given shapes Model.
 * If the shapesModel does not include the system graph triples then these will be added.
 * Entailment regimes are applied prior to validation.
 * @param dataModel  the data Model
 * @param shapesModel  the shapes Model
 * @param validateShapes  true to also validate any shapes in the data Model (false is faster)
 * @return an instance of sh:ValidationReport in a results Model
 */
public static Resource validateModel(Model dataModel, Model shapesModel, boolean validateShapes) {
	
	// Ensure that the SHACL, DASH and TOSH graphs are present in the shapes Model
	if(!shapesModel.contains(TOSH.hasShape, RDF.type, (RDFNode)null)) { // Heuristic
		Model unionModel = SHACLSystemModel.getSHACLModel();
		MultiUnion unionGraph = new MultiUnion(new Graph[] {
			unionModel.getGraph(),
			shapesModel.getGraph()
		});
		shapesModel = ModelFactory.createModelForGraph(unionGraph);
	}

	// Make sure all sh:Functions are registered
	SHACLFunctions.registerFunctions(shapesModel);
	
	// Create Dataset that contains both the data model and the shapes model
	// (here, using a temporary URI for the shapes graph)
	URI shapesGraphURI = URI.create("urn:x-shacl-shapes-graph:" + UUID.randomUUID().toString());
	Dataset dataset = ARQFactory.get().getDataset(dataModel);
	dataset.addNamedModel(shapesGraphURI.toString(), shapesModel);

	ShapesGraph shapesGraph = new ShapesGraph(shapesModel);
	if(!validateShapes) {
		shapesGraph.setShapeFilter(new ExcludeMetaShapesFilter());
	}
	ValidationEngine engine = ValidationEngineFactory.get().create(dataset, shapesGraphURI, shapesGraph, null);
	try {
		engine.applyEntailments();
		return engine.validateAll();
	}
	catch(InterruptedException ex) {
		return null;
	}
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:44,代码来源:ValidationUtil.java

示例11: asJenaModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
@Override
public Model asJenaModel() {
    if (model == null) {
        synchronized (this) {
            // As Model can be used for locks, we should make sure we don't
            // make
            // more than one model
            if (model == null) {
                model = ModelFactory.createModelForGraph(graph);
            }
        }
    }
    return model;
}
 
开发者ID:apache,项目名称:commons-rdf,代码行数:15,代码来源:JenaGraphImpl.java

示例12: getValidationModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/***************************************************************************
 * Public Static Methods
 **************************************************************************/
public static Model getValidationModel(Model shapesModel)
{
    MultiUnion unionGraph = new MultiUnion(new Graph[] {
        getSHACL().getGraph(), shapesModel.getGraph()
    });
    Model m = ModelFactory.createModelForGraph(unionGraph);

    // Make sure all sh:Functions are registered
    // Note that we don't perform validation of the shape definitions themselves.
    // To do that, activate the following line to make sure that all required triples are present:
    // dataModel = SHACLUtil.withDefaultValueTypeInferences(shapesModel);
    SHACLFunctions.registerFunctions(m);
    return m;
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:18,代码来源:TopBraidValidator.java

示例13: isInstanceOf

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
public static boolean isInstanceOf(Node instance, Node type, Graph graph) {
	// TODO: Use Node API only (maybe worth it)
	Model model = ModelFactory.createModelForGraph(graph);
	return JenaUtil.hasIndirectType((Resource)model.asRDFNode(instance), (Resource)model.asRDFNode(type));
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:6,代码来源:JenaNodeUtil.java

示例14: createDefaultModel

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的package包/类
/**
 * Wraps the result of {@link #createDefaultGraph()} into a Model and initializes namespaces. 
 * @return a default Model
 * @see #createDefaultGraph()
 */
public static Model createDefaultModel() {
	Model m = ModelFactory.createModelForGraph(createDefaultGraph());
	initNamespaces(m);
	return m;
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:11,代码来源:JenaUtil.java

示例15: exec

import org.apache.jena.rdf.model.ModelFactory; //导入方法依赖的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:exprEval must be a variable");
	}
	
	Node exprNode = argSubject.getArgList().get(0);
	Node focusNode = argSubject.getArgList().get(1);
	
	Model model = ModelFactory.createModelForGraph(execCxt.getActiveGraph());
	Dataset dataset = ARQFactory.get().getDataset(model);
	URI shapesGraphURI = URI.create("urn:x-topbraid:dummyShapesGraph");
	dataset.addNamedModel(shapesGraphURI.toString(), model);
	
	ShapesGraph[] shapesGraph = new ShapesGraph[1];
	
	NodeExpression n = NodeExpressionFactory.get().create(model.asRDFNode(exprNode));
	List<RDFNode> results = n.eval(model.asRDFNode(focusNode), new NodeExpressionContext() {
		
		@Override
		public URI getShapesGraphURI() {
			return shapesGraphURI;
		}
		
		@Override
		public ShapesGraph getShapesGraph() {
			if(shapesGraph[0] == null) {
				shapesGraph[0] = new ShapesGraph(model);
			}
			return shapesGraph[0];
		}
		
		@Override
		public Dataset getDataset() {
			return dataset;
		}
	});
	
	List<Node> nodes = new LinkedList<>();
	for(RDFNode rdfNode : results) {
		nodes.add(rdfNode.asNode());
	}

	return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), nodes.iterator(), execCxt);
}
 
开发者ID:TopQuadrant,项目名称:shacl,代码行数:51,代码来源:EvalExprPFunction.java


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