Example #1
0
  /** 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);
    }
  }
Example #2
0
  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;
  }
Example #3
0
  /** 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;
    }
  }
Example #4
0
/* Simple wrappers and operations for convenient, non-time critical logging.
 */
public class Log {
  private Log() {}

  public static void info(String caller, String msg) {
    log(caller).info(msg);
  }

  public static void info(Object caller, String msg) {
    log(caller.getClass()).info(msg);
  }

  public static void info(Class<?> cls, String msg) {
    log(cls).info(msg);
  }

  public static void info(Object caller, String msg, Throwable th) {
    log(caller.getClass()).info(msg, th);
  }

  public static void info(Class<?> cls, String msg, Throwable th) {
    log(cls).info(msg, th);
  }

  public static void debug(String caller, String msg) {
    log(caller).debug(msg);
  }

  public static void debug(Object caller, String msg) {
    log(caller.getClass()).debug(msg);
  }

  public static void debug(Class<?> cls, String msg) {
    log(cls).debug(msg);
  }

  public static void debug(Object caller, String msg, Throwable th) {
    log(caller.getClass()).debug(msg, th);
  }

  public static void debug(Class<?> cls, String msg, Throwable th) {
    log(cls).debug(msg, th);
  }

  public static void warn(String caller, String msg) {
    log(caller).warn(msg);
  }

  public static void warn(Object caller, String msg) {
    warn(caller.getClass(), msg);
  }

  public static void warn(Class<?> cls, String msg) {
    log(cls).warn(msg);
  }

  public static void warn(Object caller, String msg, Throwable th) {
    warn(caller.getClass(), msg, th);
  }

  public static void warn(Class<?> cls, String msg, Throwable th) {
    log(cls).warn(msg, th);
  }

  public static void fatal(Object caller, String msg) {
    fatal(caller.getClass(), msg);
  }

  public static void fatal(Class<?> cls, String msg) {
    log(cls).error(msg);
  }

  public static void fatal(Object caller, String msg, Throwable th) {
    fatal(caller.getClass(), msg, th);
  }

  public static void fatal(Class<?> cls, String msg, Throwable th) {
    log(cls).error(msg, th);
  }

  public static void fatal(String caller, String msg) {
    log(caller).error(msg);
  }

  private static Logger log(Class<?> cls) {
    return LoggerFactory.getLogger(cls);
  }

  private static Logger log(String loggerName) {
    return LoggerFactory.getLogger(loggerName);
  }

  private static CacheSet<Object> warningsDone = CacheFactory.createCacheSet(100);
  /** Generate a warning, once(ish) */
  public static void warnOnce(Class<?> cls, String message, Object key) {
    if (!warningsDone.contains(key)) {
      Log.warn(cls, message);
      warningsDone.add(key);
    }
  }
}