private static List<String> parseMappings(String[] parts, int start, NamespacePrefixService nps) { ArrayList<String> mappings = new ArrayList<String>(parts.length-start); for(int i=start;i<parts.length;i++){ if(!parts[i].isEmpty()){ //needed to remove two spaces in a row try { mappings.add(NamespaceMappingUtils.getConfiguredUri(nps, parts[i])); } catch (IllegalArgumentException e) { log.warn("Unable to parse mapping because of unkown namespace prefix in "+parts[i],e); } } } return mappings; }
@Override public String getFullName(String shortNameOrUri) { String prefix = NamespaceMappingUtils.getPrefix(shortNameOrUri); if(prefix != null){ String namespace = getNamespace(prefix); if(namespace != null){ return namespace+shortNameOrUri.substring(prefix.length()+1); } else { //no mapping return null return null; } } else { //not a shortName ... return the parsed return shortNameOrUri; } }
@Override public String setPrefix(String prefix, String namespace) { boolean validPrefix = NamespaceMappingUtils.checkPrefix(prefix); boolean validNamespace = NamespaceMappingUtils.checkNamespace(namespace); if(validPrefix && validNamespace){ try { return addMapping(prefix, namespace,true); } catch (IOException e) { throw new IllegalStateException("Unable to add Mapping because of an " + e.getClass().getSimpleName()+ "while setting the parsed mapping",e); } } else { StringBuilder sb = new StringBuilder("The parsed Mapping is not Valid: "); if(!validPrefix){ sb.append(String.format("The parsed prefix '%s' MUST only contain " + "alpha numeric chars including '_' and '-'",prefix)); } if(!validNamespace){ if(!validPrefix) { sb.append("| "); } sb.append(String.format("The parsed namespace '%s' MUST end with" + "'/' or '#' in case of an URI or ':' in case of an URN",namespace)); } throw new IllegalArgumentException(sb.toString()); } }
continue configs; if(NamespaceMappingUtils.getPrefix(namedEntityType) != null){ namedEntityType = NamespaceMappingUtils.getConfiguredUri( prefixService, NAMED_ENTITY_TYPE_MAPPINGS,namedEntityType); typeUri = NamespaceMappingUtils.getConfiguredUri( prefixService, NAMED_ENTITY_TYPE_MAPPINGS, entityType);
@Override public String getShortName(String uri) { String namespace = NamespaceMappingUtils.getNamespace(uri); if(namespace != null){ String prefix = getPrefix(namespace); if(prefix != null){ return prefix+uri.substring(namespace.length()); } //else no mapping -> return the full URI } //no namespace -> return the full URI return uri; }
@Override public String getShortName(String uri) { String namespace = NamespaceMappingUtils.getNamespace(uri); if(namespace != null){ String prefix = getPrefix(namespace); if(prefix != null){ return prefix+uri.substring(namespace.length()); } //else no mapping -> return the full URI } //no namespace -> return the full URI return uri; }
@Override public String getFullName(String shortNameOrUri) { String prefix = NamespaceMappingUtils.getPrefix(shortNameOrUri); if(prefix != null){ String namespace = getNamespace(prefix); if(namespace != null){ return namespace+shortNameOrUri.substring(prefix.length()+1); } else { //no mapping return null return null; } } else { //not a shortName ... return the parsed return shortNameOrUri; } }
private static List<String> parseMappings(String[] parts, int start, NamespacePrefixService nps) { ArrayList<String> mappings = new ArrayList<String>(parts.length-start); for(int i=start;i<parts.length;i++){ if(!parts[i].isEmpty()){ //needed to remove two spaces in a row try { mappings.add(NamespaceMappingUtils.getConfiguredUri(nps, parts[i])); } catch (IllegalArgumentException e) { log.warn("Unable to parse mapping because of unkown namespace prefix in "+parts[i],e); } } } return mappings; }
@Override public String setPrefix(String prefix, String namespace) { boolean validPrefix = NamespaceMappingUtils.checkPrefix(prefix); boolean validNamespace = NamespaceMappingUtils.checkNamespace(namespace); if(validPrefix && validNamespace){ try { return addMapping(prefix, namespace,true); } catch (IOException e) { throw new IllegalStateException("Unable to add Mapping because of an " + e.getClass().getSimpleName()+ "while setting the parsed mapping",e); } } else { StringBuilder sb = new StringBuilder("The parsed Mapping is not Valid: "); if(!validPrefix){ sb.append(String.format("The parsed prefix '%s' MUST only contain " + "alpha numeric chars including '_' and '-'",prefix)); } if(!validNamespace){ if(!validPrefix) { sb.append("| "); } sb.append(String.format("The parsed namespace '%s' MUST end with" + "'/' or '#' in case of an URI or ':' in case of an URN",namespace)); } throw new IllegalArgumentException(sb.toString()); } }
if(fieldUri == null){ throw new IllegalArgumentException("The prefix '" + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an " + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please " + "change the configuration to use the full URI instead of '"+value+"'!"); } else if(NamespaceMappingUtils.getPrefix(value) != null){ throw new IllegalArgumentException("'{prefix}:{localname}' configurations " + "such as '"+value+"' are only supported if the NamespacePrefixService is "
"the RdfIndexingSource as EntityDataIterable)!"); } else { values.add(Node.createURI(NamespaceMappingUtils.getConfiguredUri( nsPrefixService, fieldValue)));
boolean p = checkPrefix(prefix); boolean n = checkNamespace(namespace); if(!p || !n){ log.warn("Invalid Namespace Mapping: prefix '{}' {} , namespace '{}' {} -> mapping ignored!",
/** * @param entry * @return */ private String getUri(String entry) { String uri; String nsPrefix = NamespaceMappingUtils.getPrefix(entry); if(nsPrefix != null){ String ns = nsPrefixProvider.getNamespace(nsPrefix); if(ns == null){ throw new IllegalArgumentException("Unable to resolve namesoace prefix used by '" +entry+"' by using the NamespacePrefixService!"); } uri = new StringBuilder(ns).append(entry,nsPrefix.length()+1, entry.length()).toString(); } else { uri = entry; } return uri; }
/** * Parses the URIs for the {@link DereferenceConstants#ENTITY_REFERENCE_PROPERTIES} * @return * @throws ConfigurationException */ private Set<IRI> parseEntityReferences() throws ConfigurationException { Set<IRI> entityRefPropUris; Collection<String> entityProps = EnhancementEngineHelper.getConfigValues( config, ENTITY_REFERENCES, String.class); if(entityProps == null || entityProps.isEmpty()){ entityRefPropUris = DEFAULT_ENTITY_REFERENCES; } else { entityRefPropUris = new HashSet<IRI>(entityProps.size()); for(String prop : entityProps){ if(!StringUtils.isBlank(prop)){ entityRefPropUris.add(new IRI(getConfiguredUri(nsPrefixService, ENTITY_REFERENCES, prop.trim()))); } } } return entityRefPropUris; } /**
boolean p = checkPrefix(prefix); boolean n = checkNamespace(namespace); if(!p || !n){ log.warn("Invalid Namespace Mapping: prefix '{}' {} , namespace '{}' {} -> mapping ignored!",
if(fieldUri == null){ throw new IllegalArgumentException("The prefix '" + NamespaceMappingUtils.getPrefix(value)+"' is unknown (not mapped to an " + "namespace) by the Stanbol Namespace Prefix Mapping Service. Please " + "change the configuration to use the full URI instead of '"+value+"'!"); } else if(NamespaceMappingUtils.getPrefix(value) != null){ throw new IllegalArgumentException("'{prefix}:{localname}' configurations " + "such as '"+value+"' are only supported if the NamespacePrefixService is "
/** * Parses the URIs for the {@link DereferenceConstants#ENTITY_REFERENCE_PROPERTIES} * @return * @throws ConfigurationException */ private Set<IRI> parseEntityReferences() throws ConfigurationException { Set<IRI> entityRefPropUris; Collection<String> entityProps = EnhancementEngineHelper.getConfigValues( config, ENTITY_REFERENCES, String.class); if(entityProps == null || entityProps.isEmpty()){ entityRefPropUris = DEFAULT_ENTITY_REFERENCES; } else { entityRefPropUris = new HashSet<IRI>(entityProps.size()); for(String prop : entityProps){ if(!StringUtils.isBlank(prop)){ entityRefPropUris.add(new IRI(getConfiguredUri(nsPrefixService, ENTITY_REFERENCES, prop.trim()))); } } } return entityRefPropUris; } /**
/** * @param entry * @return */ private String getUri(String entry) { String uri; String nsPrefix = NamespaceMappingUtils.getPrefix(entry); if(nsPrefix != null){ String ns = nsPrefixProvider.getNamespace(nsPrefix); if(ns == null){ throw new IllegalArgumentException("Unable to resolve namesoace prefix used by '" +entry+"' by using the NamespacePrefixService!"); } uri = new StringBuilder(ns).append(entry,nsPrefix.length()+1, entry.length()).toString(); } else { uri = entry; } return uri; }
"the RdfIndexingSource as EntityDataIterable)!"); } else { values.add(Node.createURI(NamespaceMappingUtils.getConfiguredUri( nsPrefixService, fieldValue)));
String nsPrefix = NamespaceMappingUtils.getPrefix(prefix); if(nsPrefix != null){ String ns = nsPrefixService.getNamespace(nsPrefix);