1   package eu.fbk.dkm.pikes.resources.ontonotes;
2   
3   import eu.fbk.dkm.pikes.resources.ontonotes.frames.Frameset;
4   import eu.fbk.dkm.pikes.resources.ontonotes.frames.Note;
5   import org.xml.sax.InputSource;
6   import org.xml.sax.SAXException;
7   import org.xml.sax.XMLReader;
8   
9   import javax.xml.XMLConstants;
10  import javax.xml.bind.JAXBContext;
11  import javax.xml.bind.JAXBException;
12  import javax.xml.bind.Unmarshaller;
13  import javax.xml.parsers.ParserConfigurationException;
14  import javax.xml.parsers.SAXParserFactory;
15  import javax.xml.transform.sax.SAXSource;
16  import java.io.File;
17  import java.io.FileNotFoundException;
18  import java.io.FileReader;
19  
20  /**
21   * Created by alessio on 07/05/15.
22   */
23  
24  public class OntoNotesLoader {
25  
26  	public static <T> T load(Class<T> thisClass, File file) throws SAXException, ParserConfigurationException, FileNotFoundException, JAXBException {
27  		JAXBContext jaxbContext = JAXBContext.newInstance(thisClass);
28  
29  		SAXParserFactory spf = SAXParserFactory.newInstance();
30  
31  		spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
32  		spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
33  		spf.setFeature("http://xml.org/sax/features/validation", false);
34  
35  		XMLReader xmlReader = spf.newSAXParser().getXMLReader();
36  		InputSource inputSource = new InputSource(new FileReader(file));
37  		SAXSource source = new SAXSource(xmlReader, inputSource);
38  
39  		Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
40  
41  		return thisClass.cast(jaxbUnmarshaller.unmarshal(source));
42  	}
43  
44  	public static void main(String[] args) {
45  		File file = new File("/Users/alessio/Desktop/eu.fbk.dkm.pikes.resources.ontonotes-release-5.0/data/files/data/english/metadata/frames/look-v.xml");
46  		try {
47  			Frameset frameset = load(Frameset.class, file);
48  			for (Object noteOrPredicate : frameset.getNoteOrPredicate()) {
49  				if (noteOrPredicate instanceof Note) {
50  					Note note = (Note) noteOrPredicate;
51  					System.out.println(note.getvalue());
52  				}
53  			}
54  		} catch (Exception e) {
55  			e.printStackTrace();
56  		}
57  	}
58  }