本文整理汇总了Java中org.apache.uima.util.CasCreationUtils类的典型用法代码示例。如果您正苦于以下问题:Java CasCreationUtils类的具体用法?Java CasCreationUtils怎么用?Java CasCreationUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CasCreationUtils类属于org.apache.uima.util包,在下文中一共展示了CasCreationUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: indexDocument
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
void indexDocument(Path documentPath) throws NlpTabException {
try (InputStream inputStream = Files.newInputStream(documentPath)) {
CAS cas = CasCreationUtils.createCas(typeSystem, null, null, tuningProperties, resourceManager);
if (systemIndexingSettings.useXCas()) {
XCASDeserializer.deserialize(inputStream, cas);
} else {
XmiCasDeserializer.deserialize(inputStream, cas);
}
CasProcessorSettings casProcessorSettings = new CasProcessorSettings(systemIndexingSettings.getIndex(),
typeSystemInfo, systemIndexFSProcessorDelegateProvider, systemIndexCasViewProcessorDelegate);
casProcessorFactory.create(casProcessorSettings, cas).process();
} catch (ResourceInitializationException | IOException | SAXException e) {
throw new NlpTabException(e);
}
}
示例2: run
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
private void run() throws ResourceInitializationException, IOException, SAXException {
Collection<File> inputFiles =
FileUtils.listFiles(inputDir, FileFilterUtils.suffixFileFilter(".xml"), null);
if (inputFiles.isEmpty()) {
return;
}
TypeSystemDescription tsd = TypeSystemDescriptionFactory
.createTypeSystemDescription(typeSystemDescName);
CAS cas = CasCreationUtils.createCas(tsd, null, null);
for (File inputFile : inputFiles) {
AXMLReader.read(inputFile, cas);
File outFile = getOutputFile(inputFile);
OutputStream out = FileUtils.openOutputStream(outFile);
try {
XmiCasSerializer.serialize(cas, null, out, true, null);
} finally {
out.close();
cas.reset();
}
}
}
示例3: testOverlap
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
public void testOverlap() throws ResourceInitializationException, CASException {
JCas cas = CasCreationUtils.createCas(
TypeSystemDescriptionFactory.createTypeSystemDescription(), null, null)
.getJCas();
Annotation firstAnno = new Annotation(cas);
Annotation secondAnno = new Annotation(cas);
for (Table.Cell<Offsets, Offsets, Integer> testCell : overlapTestTable.cellSet()) {
firstAnno.setBegin(testCell.getRowKey().getBegin());
firstAnno.setEnd(testCell.getRowKey().getEnd());
//
secondAnno.setBegin(testCell.getColumnKey().getBegin());
secondAnno.setEnd(testCell.getColumnKey().getEnd());
//
if (testCell.getValue() > 0) {
if (!AnnotationUtils.overlap(firstAnno, secondAnno)) {
fail(format("Annotations %s and %s must overlap but they do not", firstAnno, secondAnno));
}
} else {
if (AnnotationUtils.overlap(firstAnno, secondAnno)) {
fail(format("Annotations %s and %s must not overlap but they do", firstAnno, secondAnno));
}
}
}
}
示例4: testOverlapLength
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
public void testOverlapLength() throws ResourceInitializationException, CASException {
JCas cas = CasCreationUtils.createCas(
TypeSystemDescriptionFactory.createTypeSystemDescription(), null, null)
.getJCas();
Annotation firstAnno = new Annotation(cas);
Annotation secondAnno = new Annotation(cas);
for (Table.Cell<Offsets, Offsets, Integer> testCell : overlapTestTable.cellSet()) {
firstAnno.setBegin(testCell.getRowKey().getBegin());
firstAnno.setEnd(testCell.getRowKey().getEnd());
//
secondAnno.setBegin(testCell.getColumnKey().getBegin());
secondAnno.setEnd(testCell.getColumnKey().getEnd());
//
assertEquals("overlapLength",
AnnotationUtils.overlapLength(firstAnno, secondAnno),
testCell.getValue().longValue());
}
}
示例5: setUp
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
daoDesc = ExternalResourceFactory.createExternalResourceDescription(
XmiFileTreeCorpusDAOResource.class, corpusPathString);
tsd = CasCreationUtils
.mergeTypeSystems(Sets.newHashSet(
XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString),
TypeSystemDescriptionFactory
.createTypeSystemDescription(),
TokenizerAPI.getTypeSystemDescription(),
SentenceSplitterAPI.getTypeSystemDescription()));
readerDesc = CollectionReaderFactory.createReaderDescription(
CorpusDAOCollectionReader.class, tsd,
CorpusDAOCollectionReader.CORPUS_DAO_KEY, daoDesc);
CAS aCAS = CasCreationUtils.createCas(tsd, null, null, null);
tokenizerSentenceSplitterDesc = AnalysisEngineFactory
.createEngineDescription(Unitizer.createTokenizerSentenceSplitterAED());
unitAnnotatorDesc = AnalysisEngineFactory.createEngineDescription(
UnitAnnotator.class, UnitAnnotator.PARAM_UNIT_TYPE_NAMES,
unitTypes);
}
示例6: setUp
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
daoDesc = ExternalResourceFactory.createExternalResourceDescription(
XmiFileTreeCorpusDAOResource.class, corpusPathString);
tsd = CasCreationUtils
.mergeTypeSystems(Sets.newHashSet(
XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString),
TypeSystemDescriptionFactory
.createTypeSystemDescription(),
TokenizerAPI.getTypeSystemDescription(),
SentenceSplitterAPI.getTypeSystemDescription()));
reader = CollectionReaderFactory.createReaderDescription(
CorpusDAOCollectionReader.class, tsd,
CorpusDAOCollectionReader.CORPUS_DAO_KEY, daoDesc);
CAS aCAS = CasCreationUtils.createCas(tsd, null, null, null);
tokenizerSentenceSplitter = Unitizer.createTokenizerSentenceSplitterAED();
unitAnnotator = AnalysisEngineFactory.createEngineDescription(
UnitAnnotator.class, UnitAnnotator.PARAM_UNIT_TYPE_NAMES,
unitTypes);
unitClassifier = AnalysisEngineFactory.createEngineDescription(
UnitClassifier.class, UnitClassifier.PARAM_CLASS_TYPE_NAMES,
classTypes);
}
示例7: createTypeSystem
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
private TypeSystem createTypeSystem() throws IOException, UIMAException {
TypeSystemDescription tsDesc = null;
if (typeSystemDescPaths != null && typeSystemDescPaths.length > 0) {
tsDesc = createTypeSystemDescriptionFromPath(typeSystemDescPaths);
}
if (typeSystemDescNames != null && typeSystemDescNames.length > 0) {
TypeSystemDescription tsDescFromNames = createTypeSystemDescription(
typeSystemDescNames);
if (tsDesc != null) {
tsDesc = mergeTypeSystems(asList(tsDesc, tsDescFromNames));
} else {
tsDesc = tsDescFromNames;
}
}
if (tsDesc == null) {
log.info("TypeSystemDescription will be created using the UIMAFit discovery");
tsDesc = TypeSystemDescriptionFactory.createTypeSystemDescription();
}
CAS dumbCas = CasCreationUtils.createCas(tsDesc, null, null);
TypeSystem typeSystem = dumbCas.getTypeSystem();
// printAllTypes();
return typeSystem;
}
示例8: test1
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
@DirtiesContext
public void test1() throws UIMAException {
Type t1 = ts.getType("test.TestFirst");
CAS cas = CasCreationUtils.createCas(ts, null, null, null);
cas.setDocumentText(TXT);
AnnotationFS s1 = cas.createAnnotation(t1, 0, 10);
AnnotationFS g1 = cas.createAnnotation(t1, 0, 9);
evaluator.onDocumentChange("1");
evaluator.onPartialMatch(g1, s1);
evaluator.onDocumentChange(null);
RecognitionMeasures m = evaluator.getMeasures();
assertEquals(1, m.getMatchedScore(), 0.001f);
assertEquals(1f / 9, m.getSpuriousScore(), 0.001f);
assertEquals(0f, m.getMissedScore(), 0.001f);
}
示例9: test2
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
@DirtiesContext
public void test2() throws UIMAException {
Type t1 = ts.getType("test.TestFirst");
CAS cas = CasCreationUtils.createCas(ts, null, null, null);
cas.setDocumentText(TXT);
AnnotationFS g1 = cas.createAnnotation(t1, 0, 9);
AnnotationFS s1 = cas.createAnnotation(t1, 2, 3);
AnnotationFS s2 = cas.createAnnotation(t1, 0, 18);
AnnotationFS s3 = cas.createAnnotation(t1, 6, 12);
evaluator.onDocumentChange("1");
evaluator.onPartialMatch(g1, s1);
evaluator.onPartialMatch(g1, s2);
evaluator.onPartialMatch(g1, s3);
evaluator.onMissing(g1);
evaluator.onDocumentChange(null);
RecognitionMeasures m = evaluator.getMeasures();
assertEquals(1, m.getMatchedScore(), 0.001f);
assertEquals(3, m.getSpuriousScore(), 0.001f);
assertEquals(0, m.getMissedScore(), 0.001f);
}
示例10: test3
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
@DirtiesContext
public void test3() throws UIMAException {
// the same as test2 but with exactMatch invoked
Type t1 = ts.getType("test.TestFirst");
CAS cas = CasCreationUtils.createCas(ts, null, null, null);
cas.setDocumentText(TXT);
AnnotationFS g1 = cas.createAnnotation(t1, 0, 9);
AnnotationFS s1 = cas.createAnnotation(t1, 0, 9);
AnnotationFS s2 = cas.createAnnotation(t1, 0, 18);
AnnotationFS s3 = cas.createAnnotation(t1, 6, 12);
evaluator.onDocumentChange("1");
evaluator.onExactMatch(g1, s1);
evaluator.onPartialMatch(g1, s2);
evaluator.onPartialMatch(g1, s3);
evaluator.onDocumentChange(null);
RecognitionMeasures m = evaluator.getMeasures();
assertEquals(1f, m.getMatchedScore(), 0.001f);
assertEquals(2f, m.getSpuriousScore(), 0.001f);
assertEquals(0f, m.getMissedScore(), 0.001f);
}
示例11: testTwoSentencesWithNoSpaceInBetween
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
@Test
public void testTwoSentencesWithNoSpaceInBetween() throws Exception
{
TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
TypeSystemDescription local = TypeSystemDescriptionFactory
.createTypeSystemDescriptionFromPath(
"src/test/resources/desc/type/webannoTestTypes.xml");
TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
JCas jcas = JCasFactory.createJCas(merged);
DocumentMetaData.create(jcas).setDocumentId("doc");
jcas.setDocumentText("onetwo");
new Token(jcas, 0, 3).addToIndexes();
new Sentence(jcas, 0, 3).addToIndexes();
new Token(jcas, 3, 6).addToIndexes();
new Sentence(jcas, 3, 6).addToIndexes();
writeAndAssertEquals(jcas);
}
示例12: makeJCasOneSentence
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
private JCas makeJCasOneSentence() throws UIMAException
{
TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
TypeSystemDescription local = TypeSystemDescriptionFactory
.createTypeSystemDescriptionFromPath(
"src/test/resources/desc/types/webannoTestTypes.xml");
TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
JCas jcas = JCasFactory.createJCas(merged);
DocumentMetaData.create(jcas).setDocumentId("doc");
TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class,
Sentence.class);
tb.buildTokens(jcas, "This is a test .");
return jcas;
}
示例13: readWebAnnoTSV
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
public static JCas readWebAnnoTSV(String aPath, TypeSystemDescription aType)
throws UIMAException, IOException
{
CollectionReader reader = createReader(WebannoTsv2Reader.class,
WebannoTsv2Reader.PARAM_SOURCE_LOCATION, "src/test/resources/" + aPath);
JCas jcas;
if (aType != null) {
TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
.createTypeSystemDescription();
List<TypeSystemDescription> allTypes = new ArrayList<>();
allTypes.add(builtInTypes);
allTypes.add(aType);
jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
}
else {
jcas = JCasFactory.createJCas();
}
reader.getNext(jcas.getCas());
return jcas;
}
示例14: readXMI
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
public static JCas readXMI(String aPath, TypeSystemDescription aType)
throws UIMAException, IOException
{
CollectionReader reader = createReader(XmiReader.class, XmiReader.PARAM_SOURCE_LOCATION,
"src/test/resources/" + aPath);
JCas jcas;
if (aType != null) {
TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
.createTypeSystemDescription();
List<TypeSystemDescription> allTypes = new ArrayList<>();
allTypes.add(builtInTypes);
allTypes.add(aType);
jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
}
else {
jcas = JCasFactory.createJCas();
}
reader.getNext(jcas.getCas());
return jcas;
}
示例15: createMultiLinkWithRoleTestTypeSytem
import org.apache.uima.util.CasCreationUtils; //导入依赖的package包/类
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem()
throws Exception
{
List<TypeSystemDescription> typeSystems = new ArrayList<>();
TypeSystemDescription tsd = new TypeSystemDescription_impl();
// Link type
TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
linkTD.addFeature("target", "", Token.class.getName());
// Link host
TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
typeSystems.add(tsd);
typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());
return CasCreationUtils.mergeTypeSystems(typeSystems);
}