/**
   * Returns the identifier of an LSRN-typed Resource
   *
   * @param lsrnNode
   * @return the identifier
   */
  public static String getID(Resource lsrnNode) {
    Set<String> namespaces = new HashSet<String>();
    for (Iterator<Resource> types = RdfUtils.getTypes(lsrnNode); types.hasNext(); ) {
      Resource type = types.next();
      if (type.isURIResource()) {
        String ns = getNamespaceFromLSRNTypeURI(type.getURI());
        if (ns != null) namespaces.add(ns);
      }
    }

    Iterator<Resource> ids =
        RdfUtils.getPropertyValues(lsrnNode, SIO.has_identifier, null)
            .andThen(RdfUtils.getPropertyValues(lsrnNode, SIO.has_attribute, null));
    while (ids.hasNext()) {
      Resource identifier = ids.next();
      for (Iterator<Resource> types = RdfUtils.getTypes(identifier); types.hasNext(); ) {
        Resource type = types.next();
        if (type.isURIResource()) {
          String ns = getNamespaceFromLSRNIdentifierTypeURI(type.getURI());
          if (ns != null && namespaces.contains(ns)) {
            Statement s = identifier.getProperty(SIO.has_value);
            if (s != null) {
              return s.getString();
            }
          }
        }
      }
    }

    return null;
  }
예제 #2
0
  /** @todo Add Documentation. */
  @Override
  public boolean isFedoraGraphSubject(Resource subject) {
    checkArgument(subject != null, "null cannot be a Fedora object!");
    assert (subject != null);

    return subject.isURIResource() && subject.getURI().startsWith("info:fedora/");
  }
 /**
  * Adds the LSRN SIO identifier structure to an LSRN-typed Resource. Attempts to use the URL of
  * the Resource to determine the ID.
  *
  * @param lsrnNode
  */
 public static void addIdentifier(Resource lsrnNode) {
   if (lsrnNode.isURIResource()) {
     Matcher idMatcher = ID_PATTERN.matcher(lsrnNode.getURI());
     if (idMatcher.find()) {
       String id = idMatcher.group(1);
       for (Resource type : RdfUtils.getTypes(lsrnNode).toList()) {
         if (!type.isURIResource()) continue;
         Matcher typeMatcher = TYPE_PATTERN.matcher(type.getURI());
         if (typeMatcher.find()) {
           String idTypeURI = OUTPUT_ID_TYPE_PATTERN.replace("$NS", typeMatcher.group(1));
           SIOUtils.createAttribute(
               lsrnNode, SIO.has_identifier, ResourceFactory.createResource(idTypeURI), id);
         }
       }
     }
   }
 }
 public static String algorithmResourceToString(Resource algorithmResource)
     throws InvalidSPDXAnalysisException {
   String uri = algorithmResource.getURI();
   if (!algorithmResource.isURIResource()) {
     throw (new InvalidSPDXAnalysisException("Algorithm resource must be a URI"));
   }
   String retval = URI_TO_ALGORITHM.get(uri);
   if (retval == null) {
     throw (new InvalidSPDXAnalysisException("Invalid algorithm resource."));
   }
   return retval;
 }
 /* (non-Javadoc)
  * @see org.sadiframework.client.Registry#findServicesByConnectedClass(com.hp.hpl.jena.rdf.model.Resource)
  */
 @Override
 public Collection<? extends Service> findServicesByConnectedClass(Resource clazz)
     throws SADIException {
   Set<String> classURIs = new HashSet<String>();
   if (clazz.isURIResource()) classURIs.add(clazz.getURI());
   if (clazz.canAs(OntClass.class)) {
     for (Iterator<? extends OntClass> i = clazz.as(OntClass.class).listSubClasses();
         i.hasNext(); ) {
       OntClass c = i.next();
       if (c.isURIResource()) classURIs.add(c.getURI());
     }
   }
   return findServicesByConnectedClass(classURIs);
   // TODO
   //		return findServices(RegistrySearchCriteria.findService().addConnectedClass(clazz));
 }
  /**
   * Returns the LSRN identifier for the given node. The method will first try to obtain an
   * explicitly specified ID as encoded by the following SIO attribute structure:
   *
   * <pre>{@code
   * root [
   *   'has attribute'/'has identifier' (SIO_000008/SIO_000067)
   *     [
   *       rdf:type $identifierClass;
   *       'has value' (SIO_000300) $ID
   *     ]
   * ]
   * }</pre>
   *
   * <p>If no such structure is attached to root, then the method will fall back to parsing the ID
   * from the root's URI, using the regular expressions associated with the given LSRN identifier
   * class.
   *
   * @param root the root resource
   * @param lsrnIdentifierType the LSRN identifier type URI (e.g. lsrn:UniProt_Identifier).
   * @return the database identifier of the given node
   */
  public static String getID(Resource root, Resource lsrnIdentifierType) {
    Collection<String> identifiers = SIOUtils.getAttributeValues(root, lsrnIdentifierType);
    identifiers.addAll(SIOUtils.getAttributeValues(root, SIO.has_identifier, lsrnIdentifierType));

    if (identifiers.size() > 0) {
      if (identifiers.size() > 1) {
        log.warn(
            String.format(
                "%s has multiple IDs of type %s, returning only the first ID",
                root, lsrnIdentifierType));
      }
      return identifiers.iterator().next();
    }

    log.info(String.format("%s has no explicit ID, attempting to parse URI", root));
    if (!root.isURIResource()) {
      log.warn(
          "could not determine the database ID, resource has no attached LSRN ID and is a blank node");
      return null;
    }

    String uri = root.getURI();
    for (Pattern pattern : Config.getConfig().getURIPatterns(lsrnIdentifierType)) {
      Matcher matcher = pattern.matcher(uri);
      if (matcher.groupCount() < 1) {
        log.warn(String.format("URI pattern '%s' does not contain any capturing groups", pattern));
        continue;
      }
      if (matcher.find()) {
        String match = matcher.group(1);
        if (!match.isEmpty()) return match;
      }
    }

    log.warn(
        String.format(
            "could not determine lsrn ID for %s, it has no attached ID and does not match any known URI pattern",
            root));
    return null;
  }
 public static boolean isLSRNIdentifierType(Resource type) {
   return type.isURIResource() && isLSRNIdentifierType(type.getURI());
 }