use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class ReportEntry method generate.
public void generate(Model model, Resource report) {
Resource entry = model.createResource();
entry.addProperty(RDF.type, SHACLM.ValidationResult);
report.addProperty(SHACLM.result, entry);
Function<Node, RDFNode> rdfNode = (gn) -> ModelUtils.convertGraphNodeToRDFNode(gn, entry.getModel());
Function<String, RDFNode> str = (s) -> entry.getModel().createLiteral(s);
// Section 3.6.2
// The properties sh:focusNode, sh:resultSeverity and
// sh:sourceConstraintComponent are the only properties that are mandatory
// for all validation results.
Objects.requireNonNull(focusNode, "focus node");
// Objects.requireNonNull(message,"message");
Objects.requireNonNull(severity, "severity");
Objects.requireNonNull(sourceConstraintComponent, "sourceConstraintComponent");
entry.addProperty(SHACLM.focusNode, rdfNode.apply(focusNode));
entry.addProperty(SHACLM.resultSeverity, rdfNode.apply(severity.level()));
entry.addProperty(SHACLM.sourceConstraintComponent, rdfNode.apply(sourceConstraintComponent));
for (Node msg : messages) entry.addProperty(SHACLM.resultMessage, rdfNode.apply(msg));
if (sourceConstraint != null)
entry.addProperty(SHACLM.sourceConstraint, rdfNode.apply(sourceConstraint));
if (source != null)
entry.addProperty(SHACLM.sourceShape, rdfNode.apply(source));
if (resultPath != null) {
Node pn = ShaclPaths.pathToRDF(model.getGraph()::add, resultPath);
entry.addProperty(SHACLM.resultPath, rdfNode.apply(pn));
}
if (value != null)
entry.addProperty(SHACLM.value, rdfNode.apply(value));
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class ShexValidationTest method testShexValidationStartFocus.
// Expected: ShexT.schema (with start), ShexT.data, ShexT.focus
static Runnable testShexValidationStartFocus(ManifestEntry entry) {
Resource action = entry.getAction();
Resource schema = action.getProperty(ShexT.schema).getResource();
Resource data = action.getProperty(ShexT.data).getResource();
// URI or literal.
RDFNode focus = action.getProperty(ShexT.focus).getObject();
return new ShexValidationTest(entry, data, schema, (Resource) null, (String) null, focus, TestType.StartFocus);
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class ShexValidationTest method testShexValidationShapeFocus.
// Expected: ShexT.schema, ShexT.shape, ShexT.data, ShexT.focus
static Runnable testShexValidationShapeFocus(ManifestEntry entry) {
Resource action = entry.getAction();
Resource schema = action.getProperty(ShexT.schema).getResource();
Resource shape = action.getProperty(ShexT.shape).getResource();
Resource data = action.getProperty(ShexT.data).getResource();
// URI or literal.
RDFNode focus = action.getProperty(ShexT.focus).getObject();
return new ShexValidationTest(entry, data, schema, shape, (String) null, focus, TestType.ShapeFocus);
}
use of org.apache.jena.rdf.model.RDFNode 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 <#entMap> ;
.
*/
@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 ByteBuffersDirectory();
} 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());
}
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 boolean : " + mlsNode);
}
isMultilingualSupport = mlsNode.asLiteral().getBoolean();
}
int maxBasicQueries = 1024;
Statement maxBasicQueriesStatement = root.getProperty(pMaxBasicQueries);
if (null != maxBasicQueriesStatement) {
RDFNode mbqNode = maxBasicQueriesStatement.getObject();
if (!mbqNode.isLiteral()) {
throw new TextIndexException("text:maxBasicQueries property must be a int : " + mbqNode);
}
try {
maxBasicQueries = mbqNode.asLiteral().getInt();
} catch (RuntimeException ex) {
// Problems with the integer.
throw new TextIndexException("text:maxBasicQueries property must be a int : " + mbqNode + "(" + ex.getMessage() + ")");
}
}
// define any property lists for text:query
Statement propListsStmt = root.getProperty(pPropLists);
if (null != propListsStmt) {
RDFNode aNode = propListsStmt.getObject();
if (!aNode.isResource()) {
throw new TextIndexException("text:propLists property is not a resource (list) : " + aNode);
}
PropListsAssembler.open(a, (Resource) aNode);
}
// define any filters and tokenizers first so they can be referenced in analyzer definitions if need be
Statement defAnalyzersStatement = root.getProperty(pDefAnalyzers);
if (null != defAnalyzersStatement) {
RDFNode aNode = defAnalyzersStatement.getObject();
if (!aNode.isResource()) {
throw new TextIndexException("text:defineAnalyzers property is not a resource (list) : " + aNode);
}
DefineFiltersAssembler.open(a, (Resource) aNode);
DefineTokenizersAssembler.open(a, (Resource) aNode);
boolean addedLangs = DefineAnalyzersAssembler.open(a, (Resource) aNode);
// multilingual support is enabled
if (addedLangs) {
if (!isMultilingualSupport) {
Log.warn(this, "Multilingual support implicitly enabled by text:defineAnalyzers");
}
isMultilingualSupport = true;
}
}
// initialize default analyzer and query analyzer after processing all analyzer definitions
// so they can be referred to
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);
}
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 boolean : " + svNode);
}
storeValues = svNode.asLiteral().getBoolean();
}
boolean ignoreIndexErrs = false;
Statement ignoreIndexErrsStatement = root.getProperty(pIgnoreIndexErrors);
if (null != ignoreIndexErrsStatement) {
RDFNode iieNode = ignoreIndexErrsStatement.getObject();
if (!iieNode.isLiteral()) {
throw new TextIndexException("text:ignoreIndexErrors property must be a boolean : " + iieNode);
}
ignoreIndexErrs = iieNode.asLiteral().getBoolean();
}
// use query cache by default
boolean cacheQueries = true;
Statement cacheQueriesStatement = root.getProperty(pCacheQueries);
if (null != cacheQueriesStatement) {
RDFNode cqNode = cacheQueriesStatement.getObject();
if (!cqNode.isLiteral()) {
throw new TextIndexException("text:cacheQueries property must be a boolean : " + cqNode);
}
cacheQueries = cqNode.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.setMaxBasicQueries(maxBasicQueries);
config.setValueStored(storeValues);
config.setIgnoreIndexErrors(ignoreIndexErrs);
docDef.setCacheQueries(cacheQueries);
return TextDatasetFactory.createLuceneIndex(directory, config);
} catch (IOException e) {
IO.exception(e);
return null;
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class PropListsAssembler method open.
public static void open(Assembler assembler, Resource list) {
Resource current = list;
while (current != null && !current.equals(RDF.nil)) {
Statement firstStmt = current.getProperty(RDF.first);
if (firstStmt == null) {
throw new TextIndexException("text:propLists list not well formed: " + current);
}
RDFNode first = firstStmt.getObject();
if (!first.isResource()) {
throw new TextIndexException("text:propLists element must be an anon resource : " + first);
}
// process the current list element to add a property list
Resource adding = (Resource) first;
if (adding.hasProperty(TextVocab.pPropListProp)) {
Statement propListPropStmt = adding.getProperty(TextVocab.pPropListProp);
RDFNode propListPropNode = propListPropStmt.getObject();
if (!propListPropNode.isResource()) {
throw new TextIndexException("text:propLists text:propListProp must be a resource: " + propListPropNode);
}
if (adding.hasProperty(TextVocab.pProps)) {
Statement propsStmt = adding.getProperty(TextVocab.pProps);
List<Resource> props = getPropsList(propsStmt);
Util.addPropsList((Resource) propListPropNode, props);
}
} else {
throw new TextIndexException("text:propLists text:propListProp must be a resource: " + adding.getProperty(TextVocab.pPropListProp));
}
Statement restStmt = current.getProperty(RDF.rest);
if (restStmt == null) {
throw new TextIndexException("text:propLists list not terminated by rdf:nil");
}
RDFNode rest = restStmt.getObject();
if (!rest.isResource()) {
throw new TextIndexException("text:propLists list rest is not a resource : " + rest);
}
current = (Resource) rest;
}
}
Aggregations