@Override public boolean accept(OntClass cls) { if (!cls.isAnon()) { return cls.getURI().startsWith(RDF.getURI()); } return false; }
protected Set<OWLClass> getAllClasses() { if (ks.isRemote()) { return new SPARQLTasks(((SparqlEndpointKS) ks).getEndpoint()).getAllClasses(); } else { Set<OWLClass> classes = new TreeSet<OWLClass>(); for (OntClass cls : ((LocalModelBasedSparqlEndpointKS) ks) .getModel() .listClasses() .filterDrop(new OWLFilter()) .filterDrop(new RDFSFilter()) .filterDrop(new RDFFilter()) .toList()) { if (!cls.isAnon()) { classes.add(df.getOWLClass(IRI.create(cls.getURI()))); } } return classes; } }
// gets the URIs of the classes and their translation public HashMap<String, String> getClassesIdentifiers( float percentage, boolean activeRandomString, boolean activeTranslateString, boolean activeSynonym, int activeStringOperation) { HashMap<String, String> classesIdentifiers = new HashMap<String, String>(); // the HashMap of classes identifiers int nbClasses, toBeRenamed, renamedClasses; List<OntClass> notRenamedClasses = new ArrayList<OntClass>(); // the list of not renamed classes List<OntClass> classes = getOntologyClasses(); // the list of ontology classes List<OntClass> classesTo = new ArrayList<OntClass>(); // the list of classes to be renamed // alignment contains those classes which have already been renamed // builds the list of all unrenamed classes from the model for (OntClass c : classes) { String local = getLocalName(c.getURI()); if (alignment.containsKey(local)) { if (alignment.getProperty(local).equals(local)) notRenamedClasses.add(c); // add the class to not renamed classes } } nbClasses = classes.size(); renamedClasses = nbClasses - notRenamedClasses.size(); // the number of renamed classes toBeRenamed = Math.round(percentage * nbClasses) - renamedClasses; // -renamedClasses -> for Benchmark // logger.trace( "NbClasses = {}; YetToRename = {}; I will rename = {};", nbClasses, // notRenamedClasses.size(), toBeRenamed ); // toBeRenamed is negative when classes have been added to the model if (toBeRenamed < 0) toBeRenamed = 0; // build the list of classes to be renamed int[] n = randNumbers(notRenamedClasses.size(), toBeRenamed); for (int i = 0; i < toBeRenamed; i++) { OntClass cls = notRenamedClasses.get(n[i]); classesTo.add(cls); } for (OntClass cls : classesTo) { if (!cls.isRestriction()) { if (!cls.isAnon()) { String prefix = getNameSpace(cls.getURI()); String localName = getLocalName(cls.getURI()); // has the same Namespace as the Ontology Namespace if (prefix.equals(modifiedOntologyNS)) { if (!classesIdentifiers.containsKey(localName)) { if (activeTranslateString) { // replace the URI with the translated one String translateStrg = parseString(localName, true, false); classesIdentifiers.put(localName, translateStrg); replaceClassLabel( cls.getURI(), translateStrg, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation); if (alignment.containsKey(localName)) { // alignment.remove( cls.getURI() ); alignment.put(localName, translateStrg); // the reference alignment } } else if (activeRandomString) { // replace the URI with a random string String newStrg = getRandomString(); classesIdentifiers.put(localName, newStrg); replaceClassLabel( cls.getURI(), newStrg, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation); if (alignment.containsKey(localName)) { // alignment.remove( cls.getURI() ); alignment.put(localName, newStrg); // the reference alignment } } else if (activeSynonym) { // replace the URI with a synonym String synonym = parseString(localName, false, true); classesIdentifiers.put(localName, synonym); replaceClassLabel( cls.getURI(), synonym, activeRandomString, activeTranslateString, activeSynonym, activeStringOperation); if (alignment.containsKey(localName)) { // alignment.remove( cls.getURI() ); alignment.put(localName, synonym); // the reference alignment } } else if (activeStringOperation == 1) { // replace the URI with the UpperCase URI classesIdentifiers.put(localName, localName.toUpperCase()); replaceClassLabel( cls.getURI(), localName.toUpperCase(), activeRandomString, activeTranslateString, activeSynonym, activeStringOperation); if (alignment.containsKey(localName)) { // alignment.remove( cls.getURI() ); alignment.put(localName, localName.toUpperCase()); // the reference alignment } } else if (activeStringOperation == 2) { // replace the URI with the LowerCase URI classesIdentifiers.put(localName, localName.toLowerCase()); replaceClassLabel( cls.getURI(), localName.toLowerCase(), activeRandomString, activeTranslateString, activeSynonym, activeStringOperation); if (alignment.containsKey(localName)) { // alignment.remove( cls.getURI() ); alignment.put(localName, localName.toLowerCase()); // the reference alignment } } else { classesIdentifiers.put(localName, localName + "CLASS"); replaceClassLabel( cls.getURI(), localName + "CLASS", activeRandomString, activeTranslateString, activeSynonym, activeStringOperation); if (alignment.containsKey(localName)) { // alignment.remove( cls.getURI() ); alignment.put(localName, localName + "CLASS"); } } } } } } } return classesIdentifiers; }