private void createOntologyTable(List<Tuple> tuples, OntologyLoader model) { int count = 0; for (OWLClass subClass : model.getTopClasses()) { recursiveAddTuple("0." + count, subClass, model, tuples); count++; } }
private void recursiveAddTuple( String termPath, OWLClass cls, OntologyLoader ontologyLoader, List<Tuple> tuples) { String label = ontologyLoader.getLabel(cls).replaceAll("[^a-zA-Z0-9 ]", " "); Set<String> synonyms = new HashSet<String>(); synonyms.add(label); synonyms.addAll(ontologyLoader.getSynonyms(cls)); // listOfChildren.addAll(model.getAssociatedClasses(cls)); StringBuilder alternativeDefinitions = new StringBuilder(); for (Set<OWLClass> alternativeDefinition : ontologyLoader.getAssociatedClasses(cls)) { StringBuilder newDefinition = new StringBuilder(); for (OWLClass associatedClass : alternativeDefinition) { if (newDefinition.length() != 0) newDefinition.append(','); newDefinition.append(associatedClass.getIRI().toString()); } if (alternativeDefinitions.length() != 0 && newDefinition.length() != 0) alternativeDefinitions.append("&&&"); alternativeDefinitions.append(newDefinition); } if (alternativeDefinitions.length() != 0) { System.out.println(alternativeDefinitions.toString()); } for (String synonym : synonyms) { KeyValueTuple tuple = new KeyValueTuple(); tuple.set(NODE_PATH, termPath); tuple.set(BOOST, false); tuple.set(ONTOLOGY_IRI, ontologyIRI); tuple.set(ONTOLOGY_NAME, ontologyName); tuple.set(ONTOLOGY_TERM, label); tuple.set(ONTOLOGY_TERM_IRI, cls.getIRI().toString()); tuple.set(ONTOLOGY_LABEL, ontologyLoader.getOntologyName()); tuple.set(ENTITY_TYPE, "ontologyTerm"); tuple.set(SYNONYMS, synonym.replaceAll("[^a-zA-Z0-9 ]", " ")); tuple.set(ALTERNATIVE_DEFINITION, alternativeDefinitions.toString()); tuples.add(tuple); } Set<OWLClass> listOfChildren = ontologyLoader.getChildClass(cls); if (listOfChildren.size() > 0) { int i = 0; for (OWLClass childClass : listOfChildren) { String childTermPath = termPath + "." + i; recursiveAddTuple(childTermPath, childClass, ontologyLoader, tuples); i++; } } }