001/**
002 * 
003 */
004package org.dllearner.algorithms.isle.textretrieval;
005
006import java.io.File;
007import java.util.List;
008import java.util.Map;
009import java.util.Map.Entry;
010import java.util.Set;
011import java.util.SortedMap;
012import java.util.TreeMap;
013
014import org.dllearner.algorithms.isle.index.Token;
015import org.dllearner.kb.OWLAPIOntology;
016import org.semanticweb.owlapi.apibinding.OWLManager;
017import org.semanticweb.owlapi.model.IRI;
018import org.semanticweb.owlapi.model.OWLEntity;
019import org.semanticweb.owlapi.model.OWLOntology;
020import org.semanticweb.owlapi.model.OWLOntologyManager;
021import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
022
023import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl;
024
025import com.google.common.base.Charsets;
026import com.google.common.io.Files;
027
028/**
029 * @author Lorenz Buehmann
030 *
031 */
032public class RDFSLabelEntityTextRetriever extends AnnotationEntityTextRetriever{
033        
034        public RDFSLabelEntityTextRetriever(OWLOntology ontology) {
035                super(ontology, new OWLDataFactoryImpl().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()));
036                determineHeadNoun = true;
037        }
038        
039        public RDFSLabelEntityTextRetriever(OWLAPIOntology ontology) {
040                super(ontology, new OWLDataFactoryImpl().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()));
041                determineHeadNoun = true;
042        }
043        
044        public static void main(String[] args) throws Exception {
045                OWLOntologyManager man = OWLManager.createOWLOntologyManager();
046                OWLOntology ontology = man.loadOntology(IRI.create("http://www.semanticbible.com/2006/11/NTNames.owl"));
047                
048                RDFSLabelEntityTextRetriever labelRetriever = new RDFSLabelEntityTextRetriever(ontology);
049                Map<OWLEntity, Set<List<Token>>> relevantText = labelRetriever.getRelevantText(ontology);
050                SortedMap<String, String> uri2Labels = new TreeMap<>();
051                
052                for (Entry<OWLEntity, Set<List<Token>>> entry : relevantText.entrySet()) {
053                        OWLEntity key = entry.getKey();
054                        Set<List<Token>> value = entry.getValue();
055                        uri2Labels.put(key.toStringID(), value.iterator().next().get(0).getRawForm());
056                }
057                
058                StringBuilder csv = new StringBuilder();
059                for (Entry<String, String> entry : uri2Labels.entrySet()) {
060                        String uri = entry.getKey();
061                        String label = entry.getValue();
062                        csv.append(uri).append(",").append(label).append("\n");
063                }
064                Files.asCharSink(new File("semantic-bible-labels.csv"), Charsets.UTF_8).write(csv);
065        }
066}