Пример #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);
  }
Пример #2
0
  @Description(
      "Find taxonomic names matching the passed in prefix. Optimized for use with autocomplete boxes on webforms.")
  @PluginTarget(GraphDatabaseService.class)
  @Deprecated
  public Representation autocompleteQuery(
      @Source GraphDatabaseService graphDb,
      @Description(
              "A string containing a single name (or partial name prefix) to be queried against the db")
          @Parameter(name = "queryString")
          String queryString,
      @Description("The name of the taxonomic context to be searched")
          @Parameter(name = "contextName", optional = true)
          String contextName,
      @Description(
              "A boolean indicating whether or not suppressed taxa should be included in the results. Defaults to false.")
          @Parameter(name = "includeDubious", optional = true)
          Boolean includeDubious)
      throws ContextNotFoundException, ParseException {

    includeDubious = includeDubious == null ? false : includeDubious;

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

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

    SingleNamePrefixQuery query = new SingleNamePrefixQuery(taxonomy, context);
    query.setIncludeDubious(includeDubious);
    TNRSResults results = query.setQueryString(queryString).runQuery().getResults();

    // return results if they exist,
    if (results.iterator().hasNext()) {

      List<TNRSMatch> matches = results.iterator().next().getMatches().getMatchList();

      if (!matches.isEmpty()) {

        Collections.sort(matches, new MatchComparator());

        return TNRSResultsRepresentation_v1.getMatchSetRepresentationForAutocompleteBox(
            matches.iterator());
      }
    }

    // else just return an empty JSON array
    return OTRepresentationConverter.convert(new LinkedList<String>());
  }
Пример #3
0
  @Description("Return information on available taxonomic contexts")
  @PluginTarget(GraphDatabaseService.class)
  @Deprecated
  public Representation getContexts(@Source GraphDatabaseService graphDb) throws IOException {

    // format is: HashMap<groupName, ArrayList<contextName>>
    HashMap<String, ArrayList<String>> contexts = new HashMap<String, ArrayList<String>>();

    for (ContextGroup group : ContextGroup.values()) {

      // get all the contexts for each context group
      ArrayList<String> subcontexts = new ArrayList<String>();
      for (ContextDescription cd : group.getDescriptions()) {
        subcontexts.add(cd.name);
      }
      contexts.put(group.toString(), subcontexts);
    }

    return OTRepresentationConverter.convert(contexts);
  }
Пример #4
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);
  }