コード例 #1
0
ファイル: IRIResolver.java プロジェクト: mikeaddison93/jena
  /** Resolving resolver * */
  static class IRIResolverNormal extends IRIResolver {
    private final IRI base;
    // Not static - contains relative IRIs
    // Could split into absolute (static, global cached) and relative.
    private Cache<String, IRI> resolvedIRIs = CacheFactory.createCache(CacheSize);

    /** Construct an IRIResolver with base as the current working directory. */
    public IRIResolverNormal() {
      this((String) null);
    }

    /**
     * Construct an IRIResolver with base determined by the argument URI. If this is relative, it is
     * relative against the current working directory.
     *
     * @param baseStr
     * @throws RiotException If resulting base unparsable.
     */
    public IRIResolverNormal(String baseStr) {
      if (baseStr == null) base = chooseBaseURI();
      else base = globalResolver.resolveSilent(baseStr);
    }

    public IRIResolverNormal(IRI baseIRI) {
      if (baseIRI == null) baseIRI = chooseBaseURI();
      base = baseIRI;
    }

    @Override
    protected IRI getBaseIRI() {
      return base;
    }

    @Override
    public IRI resolveSilent(String uriStr) {
      if (resolvedIRIs == null) return resolveSilentCache(uriStr);
      else return resolveSilentNoCache(uriStr);
    }

    private IRI resolveSilentNoCache(String uriStr) {
      IRI x = IRIResolver.iriFactory.create(uriStr);
      if (SysRIOT.AbsURINoNormalization) {
        // Always process "file:", even in strict mode.
        // file: is widely used in irregular forms.
        if (x.isAbsolute() && !uriStr.startsWith("file:")) return x;
      }
      return base.create(x);
    }

    private IRI resolveSilentCache(final String uriStr) {
      Callable<IRI> filler = () -> resolveSilentNoCache(uriStr);
      return resolvedIRIs.getOrFill(uriStr, filler);
    }
  }
コード例 #2
0
ファイル: TextQueryPF.java プロジェクト: enderunal/jena
  private ListMultimap<String, TextHit> query(
      Node property, String queryString, int limit, ExecutionContext execCxt) {
    // use the graph information in the text index if possible
    if (textIndex.getDocDef().getGraphField() != null
        && execCxt.getActiveGraph() instanceof GraphView) {
      GraphView activeGraph = (GraphView) execCxt.getActiveGraph();
      if (!Quad.isUnionGraph(activeGraph.getGraphName())) {
        String uri =
            activeGraph.getGraphName() != null
                ? TextQueryFuncs.graphNodeToString(activeGraph.getGraphName())
                : Quad.defaultGraphNodeGenerated.getURI();
        String escaped = QueryParserBase.escape(uri);
        String qs2 = textIndex.getDocDef().getGraphField() + ":" + escaped;
        queryString = "(" + queryString + ") AND " + qs2;
      }
    }

    // for language-based search extension
    if (textIndex.getDocDef().getLangField() != null) {
      String field = textIndex.getDocDef().getLangField();
      if (langArg != null) {
        String qs2 = !"none".equals(langArg) ? field + ":" + langArg : "-" + field + ":*";
        queryString = "(" + queryString + ") AND " + qs2;
      }
    }

    Explain.explain(execCxt.getContext(), "Text query: " + queryString);
    if (log.isDebugEnabled()) log.debug("Text query: {} ({})", queryString, limit);

    String cacheKey = limit + " " + property + " " + queryString;
    Cache<String, ListMultimap<String, TextHit>> queryCache =
        (Cache<String, ListMultimap<String, TextHit>>) execCxt.getContext().get(cacheSymbol);
    if (queryCache == null) {
        /* doesn't yet exist, need to create it */
      queryCache = CacheFactory.createCache(CACHE_SIZE);
      execCxt.getContext().put(cacheSymbol, queryCache);
    }

    final String queryStr = queryString; // final needed for the lambda function
    ListMultimap<String, TextHit> results =
        queryCache.getOrFill(
            cacheKey,
            () -> {
              List<TextHit> resultList = textIndex.query(property, queryStr, limit);
              ListMultimap<String, TextHit> resultMultimap = LinkedListMultimap.create();
              for (TextHit result : resultList) {
                resultMultimap.put(result.getNode().getURI(), result);
              }
              return resultMultimap;
            });
    return results;
  }
コード例 #3
0
ファイル: IRIResolver.java プロジェクト: mikeaddison93/jena
  /** A resolver that does not resolve IRIs against base. This can generate relative IRIs. */
  static class IRIResolverNoOp extends IRIResolver {
    protected IRIResolverNoOp() {}

    private Cache<String, IRI> resolvedIRIs = CacheFactory.createCache(CacheSize);

    @Override
    protected IRI getBaseIRI() {
      return null;
    }

    @Override
    public IRI resolveSilent(final String uriStr) {
      if (resolvedIRIs == null) return iriFactory.create(uriStr);
      Callable<IRI> filler = () -> iriFactory.create(uriStr);
      IRI iri = resolvedIRIs.getOrFill(uriStr, filler);
      return iri;
    }

    @Override
    public String resolveToString(String uriStr) {
      return uriStr;
    }
  }