use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Remote_GettingStartedTests method test_50.
/**
* Test 50.
*/
@Test
@Order(50)
void test_50() {
try {
IntelligentGraphRepository source = IntelligentGraphRepository.create("http://localhost:8080/rdf4j-server", "tutorial");
source.prefix("<http://inova8.com/calc2graph/testGraph5/>");
Graph graph = source.openGraph("<http://inova8.com/calc2graph/testGraph5>");
Thing Attribute = graph.getThing(":Attribute").addFact(RDFS.SUBCLASSOF, RDF.STATEMENT);
Thing AttributeType = graph.getThing(":AttributeType");
graph.getThing(":attributeOf").addFact(RDFS.SUB_PROPERTY_OF, RDF.SUBJECT).addFact(RDFS.DOMAIN, Attribute).addFact(RDFS.RANGE, RDFS.RESOURCE);
graph.getThing(":attributeType").addFact(RDFS.SUB_PROPERTY_OF, RDF.PREDICATE).addFact(RDFS.DOMAIN, Attribute).addFact(RDFS.RANGE, AttributeType);
graph.getThing(":attributeMeasurement").addFact(RDFS.SUB_PROPERTY_OF, RDF.OBJECT).addFact(RDFS.DOMAIN, Attribute).addFact(RDFS.RANGE, XSD.STRING);
Thing myCountry = graph.getThing(":Country1");
String performanceCalculation = "2*3";
myCountry.addFact(":Attribute@:salesPerformance", performanceCalculation, SCRIPT.GROOVY);
ResourceResults results = myCountry.getFacts(":Attribute@:salesPerformance");
// if(results.hasNext()) {
for (Resource result : results) {
assertEquals("6", result.getValue().stringValue());
break;
}
// source.removeGraph("<http://inova8.com/calc2graph/testGraph>");
source.closeGraph("<http://inova8.com/calc2graph/testGraph5>");
// }else {
// fail();
// }
} catch (Exception e) {
assertEquals("", e.getMessage());
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class ObjectProvenance method evaluate.
/**
* Evaluate.
*
* @param tripleSource the triple source
* @param args the args
* @return the value
* @throws ValueExprEvaluationException the value expr evaluation exception
*/
@Override
public Value evaluate(TripleSource tripleSource, Value... args) throws ValueExprEvaluationException {
logger.trace("Evaluate for <{}> with args <{}>", tripleSource, args);
if (args.length < 3) {
String message = "At least subject,predicate, and objectscript arguments required";
logger.error(message);
return tripleSource.getValueFactory().createLiteral(message);
} else {
IRI subject;
IRI predicate;
try {
subject = (IRI) args[0];
predicate = (IRI) args[1];
} catch (Exception e) {
String message = "Subject and predicate must be valid IRI";
logger.error(message);
return tripleSource.getValueFactory().createLiteral(message);
}
SimpleLiteral literalValue;
try {
literalValue = (SimpleLiteral) args[2];
if (isScriptEngine(literalValue.getDatatype())) {
Value[] argumentArray = Arrays.copyOfRange(args, 3, args.length);
IntelligentGraphRepository source = sources.getSource(tripleSource, argumentArray);
CustomQueryOptions customQueryOptions = source.getCustomQueryOptions(argumentArray);
EvaluationContext evaluationContext = new EvaluationContext(customQueryOptions);
evaluationContext.setTracing(true);
Thing subjectThing = Thing.create(source, subject, evaluationContext);
com.inova8.intelligentgraph.model.Resource fact = IntelligentEvaluator.processFactObjectValue(subjectThing, predicate, literalValue, customQueryOptions);
// TODO com.inova8.intelligentgraph.model.Resource fact = subjectThing.getFact( predicate,literalValue,customQueryOptions);
if (fact != null) {
fact.getValue();
logger.debug("Trace\r\n" + evaluationContext.getTrace());
return tripleSource.getValueFactory().createLiteral(evaluationContext.getTrace());
} else {
return null;
}
} else {
return args[2];
}
} catch (Exception e) {
return tripleSource.getValueFactory().createLiteral(e.getMessage());
}
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class ObjectValue method evaluate.
/**
* Evaluate.
*
* @param tripleSource the triple source
* @param args the args
* @return the value
* @throws ValueExprEvaluationException the value expr evaluation exception
*/
@Override
public Value evaluate(TripleSource tripleSource, Value... args) throws ValueExprEvaluationException {
logger.debug("Evaluate for <{}> ,{}> with args <{}>", tripleSource, tripleSource.getValueFactory(), args);
if (args.length < 3) {
String message = "At least subject,predicate, and objectscript arguments required";
logger.error(message);
return tripleSource.getValueFactory().createLiteral(message);
} else {
IRI subject;
IRI predicate;
try {
subject = (IRI) args[0];
predicate = (IRI) args[1];
} catch (Exception e) {
String message = String.format("Subject and predicate must be valid IRI. Subject %s, Object %s", args[0], args[1]);
logger.error(message);
return tripleSource.getValueFactory().createLiteral(message);
}
SimpleLiteral literalValue;
try {
literalValue = (SimpleLiteral) args[2];
if (isScriptEngine(literalValue.getDatatype())) {
Value[] argumentArray = Arrays.copyOfRange(args, 3, args.length);
// sources.getSource(tripleSource, argumentArray );
IntelligentGraphRepository source = IntelligentGraphRepository.create(tripleSource);
CustomQueryOptions customQueryOptions = source.getCustomQueryOptions(argumentArray);
EvaluationContext evaluationContext = new EvaluationContext(customQueryOptions);
// Thing subjectThing = source.thingFactory( null, subject, new Stack<String>(),customQueryOptions);
Thing subjectThing = Thing.create(source, subject, evaluationContext);
com.inova8.intelligentgraph.model.Resource fact = IntelligentEvaluator.processFactObjectValue(subjectThing, predicate, literalValue, customQueryOptions);
// TODO com.inova8.intelligentgraph.model.Resource fact = subjectThing.getFact(predicate,literalValue,customQueryOptions);
if (fact != null) {
Value result = fact.getValue();
// source.writeModelToCache(result, cacheContext);
logger.debug("ObjectValue = {}", result);
return result;
} else {
return null;
}
} else {
return args[2];
}
} catch (Exception e) {
return tripleSource.getValueFactory().createLiteral(e.getMessage());
}
}
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method getPaths.
/**
* Gets the paths.
*
* @param thingresource the thingresource
* @param pathQLValue the path QL value
* @param contexts the contexts
* @return the paths
* @throws PathPatternException the path pattern exception
*/
private CloseableIteration<? extends IntelligentStatement, SailException> getPaths(Resource thingresource, String pathQLValue, Value obj, Resource... contexts) throws PathPatternException {
IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
String pathQL = pathQLValue;
PathElement pathElement = PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
Thing thing = null;
if (thingresource != null) {
thing = Thing.create(source, thingresource, null);
pathElement.getSourceVariable().setValue(thing.getValue());
}
return getThingPaths(source, thing, pathElement, contexts);
}
use of com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method prepareDataset.
/**
* Prepare dataset.
*
* @param pathElement the path element
* @param source the source
* @param contexts the contexts
* @return the simple dataset
* @throws IllegalArgumentException the illegal argument exception
*/
private SimpleDataset prepareDataset(PathElement pathElement, IntelligentGraphRepository source, Resource... contexts) throws IllegalArgumentException {
CustomQueryOptions customQueryOptions = prepareCustomQueryOptions(pathElement, source, contexts);
SimpleDataset dataset = getDataset(contexts);
if (customQueryOptions != null && !customQueryOptions.isEmpty()) {
if (dataset == null)
dataset = new SimpleDataset();
dataset.addDefaultGraph(iri(IntelligentGraphConstants.URN_CUSTOM_QUERY_OPTIONS + "?" + customQueryOptions.toURIEncodedString()));
}
return dataset;
}
Aggregations