/** Check every URI as a possible use of a prefix */ private static Set<String> fullMethod(Model m) { /* Method: Covers prefixes not based on "/", "#" or final ":" splitting. * * Build a trie to use as a partial lookup matcher. * For each URI in the data, look it up as a partial match in the trie * to get all URIs in the prefix map that apply. */ // Map prefix to URI. Map<String, String> pmap = m.getNsPrefixMap() ; // Map URI to prefix, with partial lookup (all uri keys that partly match the URI) Trie<String> trie = new Trie<>() ; // change to add(uri, prefix) to get prefixes. pmap.forEach((prefix,uri)-> trie.add(uri, uri)) ; Iterator<Triple> iter = m.getGraph().find(null, null, null) ; // Prefix URIs in use. Set<String> inUseURIs = new HashSet<>() ; while(iter.hasNext()) { Triple triple = iter.next() ; processFull(trie, inUseURIs, triple.getSubject()) ; processFull(trie, inUseURIs, triple.getPredicate()) ; processFull(trie, inUseURIs, triple.getObject()) ; if ( pmap.size() == inUseURIs.size() ) break ; } return inUseURIs ; }
/** Check every URI as a possible use of a prefix */ private static Set<String> fullMethod(Model m) { /* Method: Covers prefixes not based on "/", "#" or final ":" splitting. * * Build a trie to use as a partial lookup matcher. * For each URI in the data, look it up as a partial match in the trie * to get all URIs in the prefix map that apply. */ // Map prefix to URI. Map<String, String> pmap = m.getNsPrefixMap() ; // Map URI to prefix, with partial lookup (all uri keys that partly match the URI) Trie<String> trie = new Trie<>() ; // change to add(uri, prefix) to get prefixes. pmap.forEach((prefix,uri)-> trie.add(uri, uri)) ; Iterator<Triple> iter = m.getGraph().find(null, null, null) ; // Prefix URIs in use. Set<String> inUseURIs = new HashSet<>() ; while(iter.hasNext()) { Triple triple = iter.next() ; processFull(trie, inUseURIs, triple.getSubject()) ; processFull(trie, inUseURIs, triple.getPredicate()) ; processFull(trie, inUseURIs, triple.getObject()) ; if ( pmap.size() == inUseURIs.size() ) break ; } return inUseURIs ; }