private static String stringForNode(Node n) { if ( n == null ) return "<<null>>" ; if ( n.isBlank() ) return "_:" + n.getBlankNodeLabel() ; if ( n.isLiteral() ) return stringForLiteral((Node_Literal)n) ; if ( n.isURI() ) { String uri = n.getURI() ; return stringForURI(uri) ; } if ( n.isVariable() ) return "?" + n.getName() ; if ( n.equals(Node.ANY) ) return "ANY" ; Log.warn(FmtUtils.class, "Failed to turn a node into a string: " + n) ; return n.toString() ; }
public ElementService(Node n, Element el, boolean silent) { if ( ! n.isURI() && ! n.isVariable() ) Log.error(this, "Must be a URI (or variable which will be bound) for a service endpoint") ; this.serviceNode = n ; this.element = el ; this.silent = silent ; }
public static synchronized void init() { if (initialized) return ; initialized = true ; if ( noJMX ) return ; try { mbs = ManagementFactory.getPlatformMBeanServer() ; } catch (Throwable ex) { Log.debug(ARQMgt_X.class, "Failed to initialize JMX: "+ex.getMessage()) ; noJMX = true ; mbs = null ; } }
public static boolean open(Assembler a, Resource list) { Resource current = list; while (current != null && ! current.equals(RDF.nil)){ Statement firstStmt = current.getProperty(RDF.first); if (firstStmt == null) { throw new TextIndexException("parameter list not well formed: " + current); RDFNode first = firstStmt.getObject(); if (! first.isResource()) { throw new TextIndexException("parameter specification must be an anon resource : " + first); if (adding.hasProperty(TextVocab.pFilter)) { Statement filterStmt = adding.getProperty(TextVocab.pFilter); RDFNode filterNode = filterStmt.getObject(); if (!filterNode.isResource()) { throw new TextIndexException("addFilters text:filter must be a filter spec resource: " + filterNode); if (adding.hasProperty(TextVocab.pDefFilter)) { Statement defStmt = adding.getProperty(TextVocab.pDefFilter); Resource id = defStmt.getResource(); if (id.getURI() != null) { Log.warn("DefineFiltersAssembler", "Filter specified but no text:defineFilter so filter is not accessible!");
Model model = root.getModel() ; "}") ; ParameterizedSparqlString pss = new ParameterizedSparqlString(qs1) ; pss.setIri("eMap", root.getURI()) ; List<QuerySolution> results = ResultSetFormatter.toList(rs1) ; if ( results.size() == 0 ) { Log.warn(this, "Failed to find a valid EntityMap for : "+root) ; throw new TextIndexException("Failed to find a valid EntityMap for : "+root) ; Log.warn(this, "Multiple matches for EntityMap for : "+root) ; throw new TextIndexException("Multiple matches for EntityMap for : "+root) ; Map<String, Boolean> noIndexDefs = new HashMap<>(); throw new TextIndexException("Text map list is not well formed. No rdf:first property"); n = listEntryStmt.getObject(); if (! n.isResource()) { throw new TextIndexException("Text map list entry is not a resource : " + n); throw new TextIndexException("Text map entry has no field property"); n = fieldStatement.getObject(); if (! n.isLiteral()) { throw new TextIndexException("Text map entry field property has no literal value : " + n);
@Override public TokenizerSpec open(Assembler a, Resource root, Mode mode) { if (root.hasProperty(TextVocab.pClass)) { String className = root.getProperty(TextVocab.pClass).getString(); clazz = Class.forName(className); } catch (ClassNotFoundException e) { Log.error(this, "Tokenizer class " + className + " not found. " + e.getMessage(), e); return null; Log.error(this, clazz.getName() + " has to be a subclass of " + Tokenizer.class.getName()); return null; if (root.hasProperty(TextVocab.pParams)) { RDFNode node = root.getProperty(TextVocab.pParams).getObject(); if (! node.isResource()) { throw new TextIndexException("text:params must be a list of parameter resources: " + node);
RDFNode n = root.getProperty(pDirectory).getObject() ; if ( n.isLiteral() ) { String literalValue = n.asLiteral().getLexicalForm() ; String path = IRILib.IRIToFilename(x.getURI()) ; File dir = new File(path) ; directory = FSDirectory.open(dir.toPath()) ; 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); 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); Log.warn(this, "Multilingual support implicitly enabled by text:defineAnalyzers");
static Dataset make(Resource root) { if ( !exactlyOneProperty(root, pLocation) ) throw new AssemblerException(root, "No location given") ; String dir = getStringValue(root, pLocation) ; Location loc = Location.create(dir) ; DatasetGraph dsg = TDBFactory.createDatasetGraph(loc) ; if ( root.hasProperty(pUnionDefaultGraph) ) { Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode() ; NodeValue nv = NodeValue.makeNode(b) ; if ( nv.isBoolean() ) dsg.getContext().set(TDB.symUnionDefaultGraph, nv.getBoolean()) ; else Log.warn(DatasetAssemblerTDB.class, "Failed to recognize value for union graph setting (ignored): " + b) ; } /* <r> rdf:type tdb:DatasetTDB ; tdb:location "dir" ; //ja:context [ ja:cxtName "arq:queryTimeout" ; ja:cxtValue "10000" ] ; tdb:unionGraph true ; # or "true" */ AssemblerUtils.setContext(root, dsg.getContext()); return DatasetFactory.wrap(dsg) ; }
private Binding buildBinding(Resource soln) { // foreach row BindingMap rb = BindingFactory.create(); StmtIterator bindingIter = soln.listProperties(ResultSetGraphVocab.binding); for ( ; bindingIter.hasNext() ; ) { Resource binding = bindingIter.nextStatement().getResource(); String var = binding.getRequiredProperty(ResultSetGraphVocab.variable).getString(); try { RDFNode val = binding.getRequiredProperty(ResultSetGraphVocab.value).getObject(); rb.add(Var.alloc(var), val.asNode()); } catch (PropertyNotFoundException ex) { Log.warn(this, "Failed to get value for ?" + var); } // We include the value even if it is the marker term "rs:undefined" // if ( val.equals(ResultSetVocab.undefined)) // continue ; // The ResultSetFormatter code equates null (not found) with // rs:undefined. When Jena JUnit testing, it does not matter if the // recorded result has the term absent or explicitly undefined. } bindingIter.close(); return rb; }
/** Create an Entity from a quad (as g/s/p/o). * Returns null if the quad is not a candidate for indexing. */ public static Entity entityFromQuad(EntityDefinition defn , Node g , Node s , Node p , Node o ) { String field = defn.getField(p) ; if ( field == null ) return null ; if ( !o.isLiteral() ) { Log.warn(TextQuery.class, "Not a literal value for mapped field-predicate: " + field + " :: " + FmtUtils.stringForString(field)) ; return null ; } String x = TextQueryFuncs.subjectToString(s) ; String graphText = TextQueryFuncs.graphNodeToString(g) ; String language = o.getLiteral().language() ; RDFDatatype datatype = o.getLiteral().getDatatype() ; Entity entity = new Entity(x, graphText, language, datatype) ; entity.put(field, o.getLiteralLexicalForm()) ; return entity ; }
@Override public QueryIterator execEvaluated(Binding binding, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) { try { // Subject bound to something other a URI. if ( argSubject.getArg().isLiteral() || argSubject.getArg().isBlank() ) // Only split IRIs return IterLib.noResults(execCxt) ; if ( argSubject.getArg().isURI() ) // Case 1 : subject is a fixed URI or a variable bount to a URI. return subjectIsIRI(argSubject.getArg(), argObject, binding, execCxt) ; else // Case 2 : subject is an unbound variable. return subjectIsVariable(argSubject.getArg(), argObject, execCxt) ; } catch (QueryException ex) { Log.warn(this, "Unexpected problems in splitIRI: "+ex.getMessage()) ; return null ; } }
@Override public Map<String, String> readPrefixMap(String graphName) { Map<String, String> map = new HashMap<>() ; Node g = NodeFactory.createURI(graphName) ; Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, null, null) ; for ( ; iter.hasNext() ; ) { try { Tuple<Node> t = iter.next() ; String prefix = t.get(1).getLiteralLexicalForm() ; String uri = t.get(2).getURI() ; map.put(prefix, uri) ; } catch (Exception ex) { Log.warn(this, "Mangled prefix map: graph name=" + graphName, ex) ; } } Iter.close(iter) ; return map ; }
Class<?> c = ClsLoader.loadClass(textDocProducerNode.getURI(), TextDocProducer.class) ; String className = textDocProducerNode.getURI().substring(ARQConstants.javaClassURIScheme.length()) ; Constructor<?> dyadic = getConstructor(c, DatasetGraph.class, TextIndex.class); Constructor<?> monadic = getConstructor(c, TextIndex.class); textDocProducer = (TextDocProducer) monadic.newInstance(textIndex) ; } else { Log.warn(ClsLoader.class, "Exception during instantiation '"+className+"' no TextIndex or DatasetGraph,Index constructor" ); Log.warn(ClsLoader.class, "Exception during instantiation '"+className+"': "+ex.getMessage()) ; return null ;
private void buildRows(Resource root) { // Now the results themselves int count = 0; StmtIterator solnIter = root.listProperties(ResultSetGraphVocab.solution); for ( ; solnIter.hasNext() ; ) { Resource soln = solnIter.nextStatement().getResource(); count++; Binding rb = buildBinding(soln); rows.add(rb); } solnIter.close(); if ( root.hasProperty(ResultSetGraphVocab.size) ) { try { int size = root.getRequiredProperty(ResultSetGraphVocab.size).getInt(); if ( size != count ) Log.warn(this, "Warning: Declared size = " + size + " : Count = " + count); } catch (JenaException rdfEx) {} } }
protected static ParamSpec getParamSpec(Resource node) { Statement nameStmt = node.getProperty(TextVocab.pParamName); Statement valueStmt = node.getProperty(TextVocab.pParamValue); RDFNode valueNode = valueStmt.getObject(); if (!valueNode.isResource()) { throw new TextIndexException("A set param spec text:paramValue must be a list of strings: " + valueNode); int n = ((Literal) valueStmt.getObject()).getInt(); return new ParamSpec(name, n, int.class); boolean b = ((Literal) valueStmt.getObject()).getBoolean(); return new ParamSpec(name, b, boolean.class); Log.error("org.apache.jena.query.text.assembler.Params", "Unknown parameter type: " + type + " for param: " + name + " with value: " + value); break;
Model model = root.getModel() ; "}") ; ParameterizedSparqlString pss = new ParameterizedSparqlString(qs1) ; pss.setIri("definition", root.getURI()) ; Log.warn(this, "Multiple matches for EntityMap for : "+root) ; throw new SpatialIndexException("Multiple matches for EntityDefinition for : "+root) ; return docDef; } else if ( results4.size() !=1 ) { Log.warn(this, "Multiple matches for SpatialContextFactory for : "+root) ; throw new SpatialIndexException("Multiple matches for SpatialContextFactory for : "+root) ; } else { docDef.setSpatialContextFactory(spatialContextFactory); }catch (NoClassDefFoundError e){ Log.warn(this, "Custom SpatialContextFactory lib is not ready in classpath:"+ e.getMessage()) ;
private int buildPreprocess(Resource root) { StmtIterator solnIter = root.listProperties(ResultSetGraphVocab.solution); int rows = 0; int indexed = 0; for ( ; solnIter.hasNext() ; ) { Resource soln = solnIter.nextStatement().getResource(); rows++; if ( soln.hasProperty(ResultSetGraphVocab.index) ) indexed++; } solnIter.close(); if ( indexed > 0 && rows != indexed ) { Log.warn(this, "Rows = " + rows + " but only " + indexed + " indexes"); return rows; } return rows; }
private QueryIteratorCheck(QueryIterator qIter, ExecutionContext execCxt) { super(qIter) ; if ( qIter instanceof QueryIteratorCheck ) Log.warn(this, "Checking checked iterator") ; this.execCxt = execCxt ; } @Override
private void buildRowsOrdered(Resource root, int count) { Model m = root.getModel(); // Assume one result set per file. for ( int index = 1 ;; index++ ) { Literal ind = m.createTypedLiteral(index); StmtIterator sIter = m.listStatements(null, ResultSetGraphVocab.index, ind); if ( !sIter.hasNext() ) break; Statement s = sIter.nextStatement(); if ( sIter.hasNext() ) Log.warn(this, "More than one solution: index = " + index); Resource soln = s.getSubject(); Binding rb = buildBinding(soln); rows.add(rb); sIter.close(); } if ( rows.size() != count ) Log.warn(this, "Found " + rows.size() + ": expected " + count); }
static protected void addBinding(BindingMap binding, Var var, Node value) { Node n = binding.get(var); if ( n != null ) { // Same - silently skip. if ( n.equals(value) ) return; Log.warn(SPARQLResult.class, String.format("Multiple occurences of a binding for variable '%s' with different values - ignored", var.getName())); return; } binding.add(var, value); }