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);
}
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;
}
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);
}
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;
}
}
use of org.apache.jena.rdf.model.Resource in project jena by apache.
the class ConfigurableAnalyzerAssembler method toFilterList.
private List<String> toFilterList(Resource list) {
List<String> result = new ArrayList<>();
Resource current = list;
while (current != null && !current.equals(RDF.nil)) {
Statement stmt = current.getProperty(RDF.first);
if (stmt == null) {
throw new TextIndexException("filter list not well formed");
}
RDFNode node = stmt.getObject();
if (!node.isResource()) {
throw new TextIndexException("filter is not a resource : " + node);
}
result.add(node.asResource().getLocalName());
stmt = current.getProperty(RDF.rest);
if (stmt == null) {
throw new TextIndexException("filter list not terminated by rdf:nil");
}
node = stmt.getObject();
if (!node.isResource()) {
throw new TextIndexException("filter list node is not a resource : " + node);
}
current = node.asResource();
}
return result;
}
Aggregations