Search in sources :

Example 36 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class DatasetStoreAssembler method openStore.

/** Get the StoreDesc for this dataset */
public StoreDesc openStore(Assembler a, Resource root, Mode mode) {
    Resource s = storeResource(root);
    StoreDesc desc = storeAssem.open(a, s, mode);
    return desc;
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) Resource(org.apache.jena.rdf.model.Resource)

Example 37 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class SDBModelAssembler method open.

@Override
public Model open(Assembler a, Resource root, Mode mode) {
    // Make a model.
    // [] rdf:type sdb:Model ;
    //    sdb:dataset <dataset> ;
    //    sdb:graphName <someURI> .
    // A model (graph) is a (dataset, name) pair where the name can be absent
    // meaning the default graph of the dataset.
    Resource dataset = GraphUtils.getResourceValue(root, AssemblerVocab.pDataset);
    if (dataset == null)
        throw new MissingException(root, "No dataset for model or graph");
    StoreDesc storeDesc = datasetAssem.openStore(a, dataset, mode);
    // Attempt to find a graph name - may be absent.
    // Two names : "namedGraph" and "graphName"
    String x = GraphUtils.getAsStringValue(root, AssemblerVocab.pNamedGraph1);
    if (x == null)
        x = GraphUtils.getAsStringValue(root, AssemblerVocab.pNamedGraph2);
    // No name - default model.
    Graph g = null;
    if (x == null)
        return SDBFactory.connectDefaultModel(storeDesc);
    else
        return SDBFactory.connectNamedModel(storeDesc, x);
}
Also used : Graph(org.apache.jena.graph.Graph) StoreDesc(org.apache.jena.sdb.StoreDesc) Resource(org.apache.jena.rdf.model.Resource)

Example 38 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class StoreDescAssembler method open.

@Override
public StoreDesc open(Assembler a, Resource root, Mode mode) {
    SDBConnectionDesc sdbConnDesc = null;
    Resource c = GraphUtils.getResourceValue(root, AssemblerVocab.pConnection);
    if (c != null)
        sdbConnDesc = (SDBConnectionDesc) a.open(c);
    String layoutName = GraphUtils.getStringValue(root, AssemblerVocab.pLayout);
    String dbType = chooseDBType(root, sdbConnDesc);
    // Features
    List<Resource> x = GraphUtils.multiValueResource(root, AssemblerVocab.featureProperty);
    FeatureSet fSet = new FeatureSet();
    for (Resource r : x) {
        String n = GraphUtils.getStringValue(r, AssemblerVocab.featureNameProperty);
        String v = GraphUtils.getStringValue(r, AssemblerVocab.featureValueProperty);
        Feature f = new Feature(new Feature.Name(n), v);
        fSet.addFeature(f);
    }
    StoreDesc storeDesc = new StoreDesc(layoutName, dbType, fSet);
    storeDesc.connDesc = sdbConnDesc;
    // MySQL specials
    String engineName = GraphUtils.getStringValue(root, AssemblerVocab.pMySQLEngine);
    storeDesc.engineType = null;
    if (engineName != null)
        try {
            storeDesc.engineType = MySQLEngineType.convert(engineName);
        } catch (SDBException ex) {
        }
    // SAP specials
    String storageType = GraphUtils.getStringValue(root, AssemblerVocab.pStorageType);
    if (storageType != null)
        try {
            storeDesc.storageType = SAPStorageType.convert(storageType);
        } catch (SDBException ex) {
        }
    return storeDesc;
}
Also used : StoreDesc(org.apache.jena.sdb.StoreDesc) SDBException(org.apache.jena.sdb.SDBException) SDBConnectionDesc(org.apache.jena.sdb.sql.SDBConnectionDesc) Resource(org.apache.jena.rdf.model.Resource) FeatureSet(org.apache.jena.sdb.store.FeatureSet) Feature(org.apache.jena.sdb.store.Feature)

Example 39 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class AbstractTestDatasetWithAnalyzer method init.

public void init(String analyzer, String parser) {
    Reader reader = new StringReader(makeSpec(analyzer, parser));
    Model specModel = ModelFactory.createDefaultModel();
    specModel.read(reader, "", "TURTLE");
    TextAssembler.init();
    Resource root = specModel.getResource(SPEC_ROOT_URI);
    dataset = (Dataset) Assembler.general.open(root);
}
Also used : StringReader(java.io.StringReader) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) StringReader(java.io.StringReader) Reader(java.io.Reader)

Example 40 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TextIndexLuceneAssembler method open.

/*
    <#index> a :TextIndexLucene ;
        #text:directory "mem" ;
        #text:directory "DIR" ;
        text:directory <file:DIR> ;
        text:entityMap <#endMap> ;
        .
    */
@SuppressWarnings("resource")
@Override
public TextIndex open(Assembler a, Resource root, Mode mode) {
    try {
        if (!GraphUtils.exactlyOneProperty(root, pDirectory))
            throw new TextIndexException("No 'text:directory' property on " + root);
        Directory directory;
        RDFNode n = root.getProperty(pDirectory).getObject();
        if (n.isLiteral()) {
            String literalValue = n.asLiteral().getLexicalForm();
            if (literalValue.equals("mem")) {
                directory = new RAMDirectory();
            } else {
                File dir = new File(literalValue);
                directory = FSDirectory.open(dir.toPath());
            }
        } else {
            Resource x = n.asResource();
            String path = IRILib.IRIToFilename(x.getURI());
            File dir = new File(path);
            directory = FSDirectory.open(dir.toPath());
        }
        Analyzer analyzer = null;
        Statement analyzerStatement = root.getProperty(pAnalyzer);
        if (null != analyzerStatement) {
            RDFNode aNode = analyzerStatement.getObject();
            if (!aNode.isResource()) {
                throw new TextIndexException("Text analyzer property is not a resource : " + aNode);
            }
            Resource analyzerResource = (Resource) aNode;
            analyzer = (Analyzer) a.open(analyzerResource);
        }
        Analyzer queryAnalyzer = null;
        Statement queryAnalyzerStatement = root.getProperty(pQueryAnalyzer);
        if (null != queryAnalyzerStatement) {
            RDFNode qaNode = queryAnalyzerStatement.getObject();
            if (!qaNode.isResource()) {
                throw new TextIndexException("Text query analyzer property is not a resource : " + qaNode);
            }
            Resource analyzerResource = (Resource) qaNode;
            queryAnalyzer = (Analyzer) a.open(analyzerResource);
        }
        String queryParser = null;
        Statement queryParserStatement = root.getProperty(pQueryParser);
        if (null != queryParserStatement) {
            RDFNode qpNode = queryParserStatement.getObject();
            if (!qpNode.isResource()) {
                throw new TextIndexException("Text query parser property is not a resource : " + qpNode);
            }
            Resource parserResource = (Resource) qpNode;
            queryParser = parserResource.getLocalName();
        }
        boolean isMultilingualSupport = false;
        Statement mlSupportStatement = root.getProperty(pMultilingualSupport);
        if (null != mlSupportStatement) {
            RDFNode mlsNode = mlSupportStatement.getObject();
            if (!mlsNode.isLiteral()) {
                throw new TextIndexException("text:multilingualSupport property must be a string : " + mlsNode);
            }
            isMultilingualSupport = mlsNode.asLiteral().getBoolean();
        }
        boolean storeValues = false;
        Statement storeValuesStatement = root.getProperty(pStoreValues);
        if (null != storeValuesStatement) {
            RDFNode svNode = storeValuesStatement.getObject();
            if (!svNode.isLiteral()) {
                throw new TextIndexException("text:storeValues property must be a string : " + svNode);
            }
            storeValues = svNode.asLiteral().getBoolean();
        }
        Resource r = GraphUtils.getResourceValue(root, pEntityMap);
        EntityDefinition docDef = (EntityDefinition) a.open(r);
        TextIndexConfig config = new TextIndexConfig(docDef);
        config.setAnalyzer(analyzer);
        config.setQueryAnalyzer(queryAnalyzer);
        config.setQueryParser(queryParser);
        config.setMultilingualSupport(isMultilingualSupport);
        config.setValueStored(storeValues);
        return TextDatasetFactory.createLuceneIndex(directory, config);
    } catch (IOException e) {
        IO.exception(e);
        return null;
    }
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) IOException(java.io.IOException) Analyzer(org.apache.lucene.analysis.Analyzer) RAMDirectory(org.apache.lucene.store.RAMDirectory) File(java.io.File) RDFNode(org.apache.jena.rdf.model.RDFNode) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)178 Model (org.apache.jena.rdf.model.Model)86 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)34 RDFNode (org.apache.jena.rdf.model.RDFNode)24 Dataset (org.apache.jena.query.Dataset)20 Literal (org.apache.jena.rdf.model.Literal)17 BaseTest (org.apache.jena.atlas.junit.BaseTest)16 Node (org.apache.jena.graph.Node)16 Statement (org.apache.jena.rdf.model.Statement)14 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 InfModel (org.apache.jena.rdf.model.InfModel)9 Reader (java.io.Reader)8 ArrayList (java.util.ArrayList)8 JsonString (org.apache.jena.atlas.json.JsonString)8 Triple (org.apache.jena.graph.Triple)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5