/** * Take a URI and generate a legal and unique Java Bean Identifier from it. * * @param uriOrBlankNode - URI or BlankNode for which a bean identifiers has to be created. * @param usedNames - Set of already used bean identifiers * @return a legal and unique Java Bean Identifier */ public static String uri2beanname(Object uriOrBlankNode, Set<String> usedNames) { if (uriOrBlankNode instanceof BlankNode) { return "blankNode"; // TODO create names for anonymous resource // throw new RuntimeException( // "Cannot create names for anonymous resources (yet)"); } URI uri = (URI) uriOrBlankNode; String rawname; if (uri != null) { if (getLocalPart(uri.toString()) != null) { rawname = getLocalPart(uri.toString()); } else { rawname = uri.toString(); } } else { // generate name! only needed for blank nodes rawname = "genBean" + System.currentTimeMillis(); } // remove preceeding 'has' if (rawname.toLowerCase().startsWith("has") && rawname.length() > 3) { rawname = rawname.substring(3); } // make rawname bean-style String beanname = toLegalJavaIdentifier(rawname); // now we have a nice bean name - but is it unique? if (usedNames.contains(beanname)) { // TODO check when this happens and deal better with it if (uri == null) { throw new IllegalStateException(""); } // try to use namespace prefix for disambiguation String namespacePrefix = guessNSPrefix(uri.toString()); String prefixedBeanName = toLegalJavaIdentifier(namespacePrefix + beanname); if (usedNames.contains(prefixedBeanName)) { // fallback to plain uri beanname = toLegalJavaIdentifier(uri.toString()); } else { beanname = prefixedBeanName; } } return beanname; }
/** * @return - A string of SPARQL statements that can be used in a SPARQL query to restrict the * variable "?s" * @throws UnsupportedSelectorTypeException */ public String getFilterString() throws UnsupportedSelectorTypeException { String selectorSPARQLString; Literal selector = pm.getSubjectFilter(); URI selectorType = getSelectorType(selector); String selectorValue = selector.getValue(); String filterSubjectVarString = "?s"; LOGGER.info("Processing selector type " + selectorType); if (selectorType.toString().equals("http://purl.org/rvl/fslSelector")) { // RVLs basic "fsl selector" String[] fslParts = selectorValue.split("::"); URI filterPredicate = new URIImpl(fslParts[0]).asURI(); URI filterObject = new URIImpl(fslParts[1]).asURI(); selectorSPARQLString = filterSubjectVarString + " " + filterPredicate.toSPARQL() + " " + filterObject.toSPARQL() + " . " + " FILTER( ?s !=" + filterObject.toSPARQL() + ") "; // HACK: we exclude reflexive occurences for now to avoid showing classes // being the subclass of itself ... } else if (selectorType.toString().equals("http://purl.org/rvl/sparqlSelector")) { // RVLs basic "sparql selector" selectorSPARQLString = selectorValue; } else if (selectorType.toString().equals("http://purl.org/rvl/classSelector")) { // default: class selector (a class name is expected) // will be interpreted as a constraint on the type of resources selectorSPARQLString = filterSubjectVarString + " " + RDF.type.toSPARQL() + " " + new URIImpl(selectorValue).asResource().toSPARQL() + " . "; } else { throw new UnsupportedSelectorTypeException( "The selector type " + selectorType + " is noty yet supported."); } LOGGER.info( "Applying subject filter. Only resources matching " + selectorSPARQLString + " will be affected by the mapping " + "(and thus shown, which is not the default behavior --> TODO!)"); return selectorSPARQLString; }
/** * return true, if the ontology identified by the passed URI is a default ontology * * @param ontologyUri a ontology URI * @return true, if this is a default ontology */ public static boolean containsOntologyUri(URI ontologyUri) { for (Ontology o : defaults) { if (o.uri.equals(ontologyUri.toString())) return true; } return false; }