code: public static Function<Resource, Optional<String>> resourceToProperty(final Session session) {
          return resource -> {
              try {
                  final NamespaceRegistry registry = getNamespaceRegistry(session);
                  return Optional.of(registry.getPrefix(resource.getNameSpace()) + ":" + resource.getLocalName());
              } catch (final RepositoryException ex) {
                  LOGGER.debug("Could not resolve resource namespace ({}): {}", resource.toString(), ex.getMessage());
              }
              return empty();
          };
      }
docs: Using a JCR session, return a function that maps an RDF Resource to a corresponding property name.
  
  @param session The JCR session
  @return a Function that maps a Resource to an Optional-wrapped String