use of com.inova8.pathql.context.Prefixes in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Tracer method traceFacts.
/**
* Trace facts.
*
* @param thing the thing
* @param pathQLValue the path QL value
* @param prefixes the prefixes
* @param contexts the contexts
*/
public void traceFacts(Thing thing, String pathQLValue, Prefixes prefixes, org.eclipse.rdf4j.model.Resource... contexts) {
if (!tracing)
return;
addTrace(String.format("Getting facts '%s' of %s", toHTML(pathQLValue), addIRI(thing.getSuperValue())));
CustomQueryOptions customQueryOptions = CustomQueryOption.getCustomQueryOptions(contexts, prefixes);
if (!customQueryOptions.isEmpty())
addTrace(String.format("...using options: [%s]", toHTML(customQueryOptions.toString())));
ArrayList<org.eclipse.rdf4j.model.Resource> coreContexts = CustomQueryOption.getCoreContexts(contexts);
if (!coreContexts.isEmpty())
addTrace(String.format("...within contexts: %s", coreContexts.toString()));
}
use of com.inova8.pathql.context.Prefixes in project com.inova8.intelligentgraph by peterjohnlawrence.
the class CustomQueryOption method splitQuery.
/**
* Split query.
*
* @param query the query
* @param prefixes the prefixes
* @return the custom query options
*/
private static CustomQueryOptions splitQuery(String query, Prefixes prefixes) {
if (query == null || query.isEmpty()) {
return null;
}
query = query.substring(query.indexOf("?") + 1);
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
for (String queryParam : query.split("&")) {
Pair<String, Value> pair = splitQueryParameter(queryParam, prefixes);
customQueryOptions.add(pair.a, pair.b);
}
return customQueryOptions;
}
use of com.inova8.pathql.context.Prefixes in project com.inova8.intelligentgraph by peterjohnlawrence.
the class CustomQueryOption method splitQueryParameter.
/**
* Split query parameter.
*
* @param parameter the parameter
* @param prefixes the prefixes
* @return the pair
*/
private static Pair<String, Value> splitQueryParameter(String parameter, Prefixes prefixes) {
final String enc = "UTF-8";
List<String> keyValue = Arrays.stream(parameter.split("=")).map(e -> {
try {
return URLDecoder.decode(e, enc);
} catch (UnsupportedEncodingException ex) {
throw new RuntimeUnsupportedEncodingException(ex);
}
}).collect(toList());
if (keyValue.size() == 2) {
String value = keyValue.get(1);
String[] valueParts = value.split("\\^\\^");
Pair<String, Value> pair;
String valueString = valueParts[0];
if (valueString.startsWith("<")) {
valueString = valueString.substring(1, valueString.length() - 1);
pair = new Pair<String, Value>(keyValue.get(0), iri(valueString));
return pair;
} else {
if (valueString.startsWith("'") || valueString.startsWith("\""))
valueString = valueString.substring(1, valueString.length() - 1);
if (valueParts.length == 2) {
IRI qname = convertQName(valueParts[1], prefixes);
Literal typedLiteral = Values.literal(Values.getValueFactory(), valueString, qname);
pair = new Pair<String, Value>(keyValue.get(0), typedLiteral);
} else {
Literal literal = literal(valueString);
pair = new Pair<String, Value>(keyValue.get(0), literal);
}
return pair;
}
} else {
return new Pair<String, Value>(keyValue.get(0), null);
}
}
use of com.inova8.pathql.context.Prefixes in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitPname_ns.
/**
* Visit pname ns.
*
* @param ctx the ctx
* @return the iri ref value element
*/
@Override
public IriRefValueElement visitPname_ns(Pname_nsContext ctx) {
// pname_ns : PNAME_NS ;
IriRefValueElement pname_nsElement = new IriRefValueElement(this.repositoryContext);
Prefixes prefixes = null;
prefixes = this.repositoryContext.getPrefixes();
// if(thing!=null) prefixes=thing.getPrefixes();
IRI qname = this.repositoryContext.convertQName(ctx.getText(), prefixes);
if (qname != null) {
pname_nsElement.setIri(qname);
return pname_nsElement;
} else {
if (thing != null)
thing.getEvaluationContext().getTracer().traceQNameError(ctx.getText());
throw new ScriptFailedException(String.format("Error identifying namespace of qName %s", ctx.getText()));
}
}
use of com.inova8.pathql.context.Prefixes in project com.inova8.intelligentgraph by peterjohnlawrence.
the class CustomQueryOption method getCustomQueryOptions.
/**
* Gets the custom query options.
*
* @param contexts the contexts
* @param prefixes the prefixes
* @return the custom query options
*/
public static CustomQueryOptions getCustomQueryOptions(org.eclipse.rdf4j.model.Resource[] contexts, Prefixes prefixes) {
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
if (contexts != null) {
for (org.eclipse.rdf4j.model.Resource context : contexts) {
if (context.stringValue().startsWith(IntelligentGraphConstants.URN_CUSTOM_QUERY_OPTIONS)) {
String queryString = null;
try {
queryString = URLDecoder.decode(context.stringValue(), StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
customQueryOptions = CustomQueryOption.splitQuery(queryString, prefixes);
return customQueryOptions;
}
}
return customQueryOptions;
} else
return null;
}
Aggregations