001 package org.dllearner.examples;
002
003 import java.io.BufferedReader;
004 import java.io.File;
005 import java.io.FileReader;
006 import java.io.IOException;
007 import java.net.URI;
008 import java.util.ArrayList;
009 import java.util.List;
010 import java.util.StringTokenizer;
011
012 import org.dllearner.examples.corpus.Sentence;
013 import org.semanticweb.owl.apibinding.OWLManager;
014 import org.semanticweb.owl.model.AddAxiom;
015 import org.semanticweb.owl.model.OWLAxiom;
016 import org.semanticweb.owl.model.OWLDataFactory;
017 import org.semanticweb.owl.model.OWLOntology;
018 import org.semanticweb.owl.model.OWLOntologyChangeException;
019 import org.semanticweb.owl.model.OWLOntologyCreationException;
020 import org.semanticweb.owl.model.OWLOntologyManager;
021 import org.semanticweb.owl.util.SimpleURIMapper;
022
023 public class Corpus {
024
025 static BufferedReader br = null;
026 static File file;
027 public static String namespace = "http://www.test.de/test";
028 static OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
029 public static OWLDataFactory factory;
030 static OWLOntology currentOntology;
031
032 /**
033 * @param args
034 */
035 public static void main(String[] args) {
036 file= new File("ling/test.export");
037 init();
038 try{
039 Sentence sentence = nextSentence();
040 sentence.processSentence();
041
042 /*for (String line : sentence) {
043 System.out.println(line);
044 }*/
045 }catch (Exception e) {
046 e.printStackTrace();
047 }
048
049 saveOntology();
050 }
051
052
053
054 public static Sentence nextSentence()throws IOException {
055 List<String> retList = new ArrayList<String>();
056 int retID = 0;
057 String line = "";
058 boolean proceed = true;
059 while (proceed ) {
060 line = br.readLine();
061 if (line == null){
062 break;
063 }else if(line.startsWith("#EOS")){
064
065 proceed = false;
066 }else if(line.startsWith("%%")||line.startsWith("#BOS")){
067 if(line.startsWith("#BOS")){
068 StringTokenizer s = new StringTokenizer(line);
069 s.nextToken();
070 String id = s.nextToken();
071 retID = Integer.parseInt(id);
072 }
073 proceed = true;;
074 }else{
075 retList.add(line);
076 }
077 }
078
079 return new Sentence(retID, retList);
080
081 }
082
083
084
085 public static void init(){
086 try{
087 br = new BufferedReader(new FileReader(file));
088 URI ontologyURI = URI.create(namespace);
089 //URI physicalURI = new File("cache/"+System.currentTimeMillis()+".owl").toURI();
090 URI physicalURI = new File("cache/tiger.owl").toURI();
091 SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI);
092 manager.addURIMapper(mapper);
093 try{
094 currentOntology = manager.createOntology(ontologyURI);
095 }catch(OWLOntologyCreationException e){
096 //logger.error("FATAL failed to create Ontology " + ontologyURI);
097 e.printStackTrace();
098 }
099 factory = manager.getOWLDataFactory();
100
101 }catch (Exception e) {
102 e.printStackTrace();
103 System.exit(0);
104 }
105 }
106
107 public static void addAxiom(OWLAxiom axiom){
108 AddAxiom addAxiom = new AddAxiom(currentOntology, axiom);
109 try{
110 manager.applyChange(addAxiom);
111 }catch (OWLOntologyChangeException e) {
112 //TODO
113 e.printStackTrace();
114 }
115 }
116
117 public static void saveOntology(){
118 try{
119 manager.saveOntology(currentOntology);
120 //manager.s
121 }catch (Exception e) {
122 e.printStackTrace();
123
124 }
125 }
126
127 }