XmiFileTreeCorpusDAO implements CorpusDAO { @Override public void getDocumentCas(URI docURI, String annotatorId, CAS aCAS) throws SAXException, IOException { if (fileByURIandAnnotatorId.containsKey(new UriAnnotatorPair(docURI, annotatorId))) { FileInputStream xmiFileIn = new FileInputStream( fileByURIandAnnotatorId.get(new UriAnnotatorPair( docURI, annotatorId))); XmlCasDeserializer.deserialize(xmiFileIn, aCAS); closeQuietly(xmiFileIn); } else { throw new FileNotFoundException(String.format( "There is no document '%s' annotated by '%s'", docURI, annotatorId)); } } XmiFileTreeCorpusDAO(String corpusPathString); @Override Set<URI> getDocuments(); @Override Set<String> getAnnotatorIds(URI docURI); @Override void getDocumentCas(URI docURI, String annotatorId, CAS aCAS); @Override boolean hasDocument(URI docURI, String annotatorId); @Override void persist(URI docUri, String annotatorId, CAS cas); static TypeSystemDescription getTypeSystem(String corpusPathString); static final String XMI_FILE_EXTENSION; }
@Test public void testGetDocumentCas() throws ResourceInitializationException, IOException, SAXException, URISyntaxException, ParserConfigurationException { CAS aCAS = CasCreationUtils.createCas( XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString), null, null, null); corpusDAO.getDocumentCas(new URI("62007.txt"), "1", aCAS); assertThat(aCAS.getDocumentText(), containsString("РИА Новости")); assertEquals(6, CasUtil.selectAll(aCAS).size()); assertEquals( 1, CasUtil.select( aCAS, CasUtil.getAnnotationType(aCAS, "ru.kfu.itis.issst.evex.Weapon")).size()); aCAS = CasCreationUtils.createCas( XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString), null, null, null); corpusDAO.getDocumentCas(new URI("62007.txt"), "5", aCAS); assertThat(aCAS.getDocumentText(), containsString("РИА Новости")); assertThat(CasUtil.selectAll(aCAS).size(), equalTo(5)); assertEquals( 0, CasUtil.select( aCAS, CasUtil.getAnnotationType(aCAS, "ru.kfu.itis.issst.evex.Weapon")).size()); }