當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。