Compact an URI String using base URI and namespace prefixes. The prefixes map, which maps name prefixes of the form "ns:" or the empty string to URI prefixes is searched for the first URI prefix in the value set that matches the beginning of the uriString. The corresponding name prefix is then used
(String uriString, Map<String, String> prefixes)
| 995 | * @return a shortened URI where the URI prefix is replaced with a prefix name or the empty string |
| 996 | */ |
| 997 | public static String shortenUriString(String uriString, Map<String, String> prefixes) { |
| 998 | // get the URI prefixes |
| 999 | String uriPrefix = ""; |
| 1000 | String namePrefix = ""; |
| 1001 | for(Map.Entry<String,String> entry : prefixes.entrySet()) { |
| 1002 | String np = entry.getKey(); |
| 1003 | String uri = entry.getValue(); |
| 1004 | if(uriString.startsWith(uri)) { |
| 1005 | uriPrefix = uri; |
| 1006 | namePrefix = np; |
| 1007 | break; |
| 1008 | } |
| 1009 | } |
| 1010 | if(uriPrefix.equals("")) { |
| 1011 | throw new GateRuntimeException("No prefix found in prefixes map for "+uriString); |
| 1012 | } |
| 1013 | return namePrefix + uriString.substring(uriPrefix.length()); |
| 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * Get all the annotations from the source annotation set that start and end |