code: public Node getOriginalResource(final Node subject) {
          if (!subject.isURI()) {
              return subject;
          }
  
          final String subjectUri = subject.getURI();
          final int index = subjectUri.indexOf(FCR_VERSIONS);
          if (index > 0) {
              return NodeFactory.createURI(subjectUri.substring(0, index - 1));
          } else {
              return subject;
          }
      }
docs: Returns the original resource as a URI Node if
  the subject represents a memento uri; otherwise it
  returns the subject parameter.
  @param subject the subject
  @return a URI node of the original resource.