Example #1
0
 /**
  * Given an accession, try and infer which resource the identifier is from. If the accession is
  * very general and can not be inferred it is added to the {@link #ambiguous()} set. If a single
  * resource was inferred it will try to be mapped to any entities matching the given key.
  *
  * <blockquote>
  *
  * <pre>
  *     IdentifierMap mapper = ...;
  *     mapper.map("atp", "C00002");
  *     mapper.map("atp", "CHEBI:57299");
  * </pre>
  *
  * </blockquote>
  *
  * @param key the key to locate the entity
  * @param accession the accession to infer a resource from
  * @return an entity <i>handled</i> the identifier
  * @see #ambiguous()
  */
 public boolean map(K key, String accession) {
   Collection<Class<? extends Identifier>> ids = idFactory.ofPattern(accession);
   if (ids.size() == 1) {
     Identifier identifier = idFactory.ofClass(ids.iterator().next());
     identifier.setAccession(accession);
     return map(key, identifier);
   } else if (ids.size() > 1) {
     ambiguous.add(accession);
   }
   return false;
 }
Example #2
0
 /**
  * Find the identifier for the resource name and set the accession and add then try to map the
  * identifier to an entity which matches the key. If the name cannot be found it is added to
  * {@link #unknown()}. If the identifier is invalid is will be added to {@link #invalid()}.
  *
  * <blockquote>
  *
  * <pre>
  *     IdentifierMap mapper = ...;
  *     mapper.map("atp", "C00002", "KEGG Compound");
  *     mapper.map("atp", "CHEBI:57299", "ChEBI");
  * </pre>
  *
  * </blockquote>
  *
  * @param key look up entities
  * @param accession identifier accession
  * @param name resource name
  * @return an entity <i>handled</i> the identifier
  * @see #invalid()
  * @see #unknown()
  */
 public boolean map(K key, String accession, String name) {
   Identifier identifier = idFactory.ofName(name);
   if (identifier != IdentifierFactory.EMPTY_IDENTIFIER) {
     identifier.setAccession(accession);
     if (identifier.isValid()) {
       return map(key, identifier);
     } else {
       invalid.add(accession);
     }
   } else {
     unknown.add(name);
   }
   return false;
 }