Example #1
0
  @Description("Returns the version of the taxonomy used to initialize the graph")
  @PluginTarget(GraphDatabaseService.class)
  @Deprecated
  public Representation getTaxonomyVersion(@Source GraphDatabaseService graphDb) {

    GraphDatabaseAgent gdb = new GraphDatabaseAgent(graphDb);
    String taxVersion = "";
    taxVersion = (String) gdb.getGraphProperty("source");

    return OTRepresentationConverter.convert(taxVersion);
  }
Example #2
0
  @Description(
      "Find the least inclusive taxonomic context defined for the provided set of taxon names.")
  @PluginTarget(GraphDatabaseService.class)
  @Deprecated
  public Representation getContextForNames(
      @Source GraphDatabaseService graphDb,
      @Description("An array of taxon names to be queried.")
          @Parameter(name = "names", optional = false)
          String[] names) {

    // initialize objects
    GraphDatabaseAgent gdb = new GraphDatabaseAgent(graphDb);
    Taxonomy taxonomy = new Taxonomy(gdb);
    MultiNameContextQuery tnrs = new MultiNameContextQuery(taxonomy);

    // format input for the TNRS query object
    Map<Object, String> idNameMap = new HashMap<Object, String>();
    for (String name : names) {
      idNameMap.put(name, name);
    }

    // call TNRS query, remembering names that could not be matched
    Collection<String> namesNotMatched =
        tnrs.setSearchStrings(idNameMap).inferContextAndReturnAmbiguousNames().values();

    //        if (nameIdsNotMatched.isEmpty()) {
    //        	nameIdsNotMatched = (Collection<Object>) new HashSet<Object>();
    //        }

    // get the inferred context
    TaxonomyContext inferredContext = tnrs.getContext();

    // format results and finish
    ContextResult contextResult = new ContextResult(inferredContext, namesNotMatched);
    gdb.shutdownDb();

    //        return OpentreeRepresentationConverter.convert(contextResult);
    return TNRSResultsRepresentation_v1.getContextRepresentation(contextResult);
  }
Example #3
0
  @Description(
      "Return information about potential matches to a set of taxonomic names. This service uses taxonomic contexts to narrow search parameters and help disambiguate synonyms and homonyms. ")
  @PluginTarget(GraphDatabaseService.class)
  @Deprecated
  public Representation contextQuery(
      @Source GraphDatabaseService graphDb,
      @Description(
              "A comma-delimited string of taxon names to be queried against the taxonomy db. This is an alternative to the use of the 'names' parameter")
          @Parameter(name = "queryString", optional = true)
          String queryString,
      @Description("The name of the taxonomic context to be searched")
          @Parameter(name = "contextName", optional = true)
          String contextName,
      @Description(
              "An array of taxon names to be queried. This is an alternative to the use of the 'queryString' parameter")
          @Parameter(name = "names", optional = true)
          String[] names,
      @Description(
              "An array of ids to use for identifying names. These will be set in the id field of each name result. If this parameter is used, ids will be treated as strings.")
          @Parameter(name = "idStrings", optional = true)
          String[] idStrings,
      @Description(
              "An array of ids to use for identifying names. These will be set in the id field of each name result. If this parameter is used, ids will be treated as ints.")
          @Parameter(name = "idInts", optional = true)
          Long[] idInts,
      @Description("A boolean indicating whether or not to include deprecated taxa in the search.")
          @Parameter(name = "includeDeprecated", optional = true)
          Boolean includeDeprecated,
      @Description(
              "A boolean indicating whether or not to perform approximate string (a.k.a. \"fuzzy\") matching. Will greatly improve speed if this is turned OFF (false). By default, however, it is on (true).")
          @Parameter(name = "doApproximateMatching", optional = true)
          Boolean doFuzzyMatching,
      @Description(
              "Whether to include so-called 'dubious' taxa--those which are not accepted by OTT.")
          @Parameter(name = "includeDubious", optional = true)
          Boolean includeDubious)
      throws ContextNotFoundException {

    GraphDatabaseAgent gdb = new GraphDatabaseAgent(graphDb);
    Taxonomy taxonomy = new Taxonomy(gdb);

    // including deprecated and dubious names are turned OFF by default
    includeDeprecated = includeDeprecated == null ? false : includeDeprecated;
    includeDubious = includeDubious == null ? false : includeDubious;

    // fuzzy matching is turned ON by default
    doFuzzyMatching = doFuzzyMatching == null ? true : doFuzzyMatching;

    // check valid input on names
    String[] searchStrings = null;
    if (queryString != null && names == null) {
      searchStrings = queryString.split("\\s*\\,\\s*");
    } else if (names != null && queryString == null) {
      searchStrings = names;
    } else {
      throw new IllegalArgumentException(
          "You must provide exactly one of either the 'queryString' or 'names' parameters");
    }

    // check valid input on ids
    Object[] ids = null;
    if (idInts != null && idStrings == null) {

      ids = new Object[idInts.length];
      int i = 0;
      for (Long id : idInts) {
        ids[i++] = id;
      }

    } else if (idStrings != null && idInts == null) {
      ids = idStrings;

    } else if (idStrings != null && idInts != null) {
      throw new IllegalArgumentException(
          "You may provide at most one of the 'idStrings' an 'idInts' parameters");

    } else {
      ids = searchStrings;
    }

    Map<Object, String> idNameMap = new HashMap<Object, String>();
    if (ids != null) {
      int i = 0;
      for (String name : searchStrings) {
        try {
          idNameMap.put(ids[i++], name);
        } catch (ArrayIndexOutOfBoundsException ex) {
          throw new IllegalArgumentException("There are more names than ids");
        }
      }
      if (ids.length > i) {
        throw new IllegalArgumentException("There are more ids than names");
      }
    } else {
      for (String name : searchStrings) {
        idNameMap.put(name, name);
      }
    }

    if (idNameMap.keySet().size() > MAX_QUERY_STRINGS) {
      HashMap<String, Object> results = new HashMap<String, Object>();
      results.put("status", "error");
      results.put(
          "message",
          "Queries containing more than "
              + MAX_QUERY_STRINGS
              + " strings are not supported. You may submit multiple"
              + "smaller queries to avoid this limit.");
      return OTRepresentationConverter.convert(results);
    }

    // attempt to get the named context, will throw exception if a name is supplied but no
    // corresponding context can be found
    TaxonomyContext context = null;
    boolean useAutoInference = true;
    if (contextName != null) {
      context = taxonomy.getContextByName(contextName);
      useAutoInference = false;
    }

    MultiNameContextQuery mncq = new MultiNameContextQuery(taxonomy);
    TNRSResults results =
        mncq.setSearchStrings(idNameMap)
            .setContext(context)
            .setAutomaticContextInference(useAutoInference)
            .setIncludeDubious(includeDubious)
            .setIncludeDeprecated(includeDeprecated)
            .setDoFuzzyMatching(doFuzzyMatching)
            .runQuery()
            .getResults();

    gdb.shutdownDb();
    return TNRSResultsRepresentation_v1.getResultsRepresentation(results);
  }