本文整理汇总了Java中org.apache.uima.util.CasCreationUtils.mergeTypeSystems方法的典型用法代码示例。如果您正苦于以下问题:Java CasCreationUtils.mergeTypeSystems方法的具体用法?Java CasCreationUtils.mergeTypeSystems怎么用?Java CasCreationUtils.mergeTypeSystems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.uima.util.CasCreationUtils
的用法示例。
在下文中一共展示了CasCreationUtils.mergeTypeSystems方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: 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;
}
示例5: 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);
}
示例6: setUp
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
daoDesc = ExternalResourceFactory.createExternalResourceDescription(
XmiFileTreeCorpusDAOResource.class, corpusPathString);
reader = CollectionReaderFactory.createReader(
CorpusDAOCollectionReader.class,
XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString),
CorpusDAOCollectionReader.CORPUS_DAO_KEY, daoDesc);
tsd = CasCreationUtils.mergeTypeSystems(Sets.newHashSet(
XmiFileTreeCorpusDAO.getTypeSystem(corpusPathString),
TypeSystemDescriptionFactory.createTypeSystemDescription()));
CAS aCAS = CasCreationUtils.createCas(tsd, null, null, null);
reader.typeSystemInit(aCAS.getTypeSystem());
}
示例7: 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.createReader(
CorpusDAOCollectionReader.class, tsd,
CorpusDAOCollectionReader.CORPUS_DAO_KEY, daoDesc);
CAS aCAS = CasCreationUtils.createCas(tsd, null, null, null);
reader.typeSystemInit(aCAS.getTypeSystem());
tokenizerSentenceSplitter = AnalysisEngineFactory
.createEngine(Unitizer.createTokenizerSentenceSplitterAED());
unitAnnotator = AnalysisEngineFactory.createEngine(
UnitAnnotator.class, UnitAnnotator.PARAM_UNIT_TYPE_NAMES,
unitTypes);
unitClassifier = AnalysisEngineFactory.createEngine(
UnitClassifier.class, UnitClassifier.PARAM_CLASS_TYPE_NAMES,
classTypes);
unitsTSV = tempFolder.newFile();
unitsDAOWriter = AnalysisEngineFactory.createEngine(
UnitsDAOWriter.class, UnitsDAOWriter.UNITS_TSV_PATH,
unitsTSV.getPath());
}
示例8: makeJCas
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
private static JCas makeJCas() throws UIMAException
{
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");
return jcas;
}
示例9: makeJCasOneSentence
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
private JCas makeJCasOneSentence(String aText) throws UIMAException
{
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");
TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class,
Sentence.class);
tb.buildTokens(jcas, aText);
// Remove the sentences generated by the token builder which treats the line break as a
// sentence break
for (Sentence s : select(jcas, Sentence.class)) {
s.removeFromIndexes();
}
// Add a new sentence covering the whole text
new Sentence(jcas, 0, jcas.getDocumentText().length()).addToIndexes();
return jcas;
}
示例10: runTest
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
@Test
public void runTest() throws Exception
{
TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
TypeSystemDescription local;
if (new File(referenceFolder, "typesystem.xml").exists()) {
local = TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath(
new File(referenceFolder, "typesystem.xml").toString());
}
else {
local = TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath(
"src/test/resources/desc/type/webannoTestTypes.xml");
}
TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
String targetFolder = "target/test-output/WebAnnoTsv3XReaderWriterRoundTripTest/"
+ referenceFolder.getName();
CollectionReaderDescription reader = createReaderDescription(WebannoTsv3XReader.class,
merged,
WebannoTsv3XReader.PARAM_SOURCE_LOCATION, referenceFolder,
WebannoTsv3XReader.PARAM_PATTERNS, "reference.tsv");
AnalysisEngineDescription checker = createEngineDescription(
DKProCoreConventionsChecker.class);
AnalysisEngineDescription tsvWriter = createEngineDescription(WebannoTsv3XWriter.class,
merged,
WebannoTsv3XWriter.PARAM_TARGET_LOCATION, targetFolder,
WebannoTsv3XWriter.PARAM_STRIP_EXTENSION, true);
AnalysisEngineDescription xmiWriter = createEngineDescription(XmiWriter.class,
merged,
XmiWriter.PARAM_TARGET_LOCATION, targetFolder,
XmiWriter.PARAM_STRIP_EXTENSION, true);
SimplePipeline.runPipeline(reader, checker, tsvWriter, xmiWriter);
String referenceTsv = FileUtils.readFileToString(new File(referenceFolder, "reference.tsv"),
"UTF-8");
String actualTsv = FileUtils.readFileToString(new File(targetFolder, "reference.tsv"),
"UTF-8");
//
// The XMI files here are not compared semantically but using their serialization which
// is subject to minor variations depending e.g. on the order in which annotation are
// created in the CAS. Thus, this code is commented out and should only be used on a
// case-by-case base to compare XMIs during development.
//
// String referenceXmi = FileUtils.readFileToString(new File(referenceFolder,
// "reference.xmi"),
// "UTF-8");
//
// String actualXmi = FileUtils.readFileToString(new File(targetFolder, "reference.xmi"),
// "UTF-8");
assertEquals(referenceTsv, actualTsv);
// assertEquals(referenceXmi, actualXmi);
}
示例11: simpleRelGovStackedTest
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
@Test
public void simpleRelGovStackedTest()
throws Exception
{
TypeSystemDescription customeTypesSpan = DiffUtils.createCustomTypeSystem(SPAN_TYPE,
"webanno.custom.Multivalspan", asList("f1", "f2"), null);
TypeSystemDescription customeTypesRel = DiffUtils.createCustomTypeSystem(RELATION_TYPE,
"webanno.custom.Multivalrel", asList("rel1", "rel2"),
"webanno.custom.Multivalspan");
List<TypeSystemDescription> customTypes = new ArrayList<>();
customTypes.add(customeTypesSpan);
customTypes.add(customeTypesRel);
TypeSystemDescription customType = CasCreationUtils.mergeTypeSystems(customTypes);
Map<String, List<JCas>> casByUser = DiffUtils.loadWebAnnoTSV(customType,
"mergecas/multivalspanrel/tale.tsv", "mergecas/multivalspanrel/tale.tsv");
List<String> entryTypes = asList("webanno.custom.Multivalspan",
"webanno.custom.Multivalrel");
List<? extends DiffAdapter> diffAdapters = asList(
new ArcDiffAdapter("webanno.custom.Multivalrel", "Dependent", "Governor", "rel1",
"rel2"),
new SpanDiffAdapter("webanno.custom.Multivalspan", "f1", "f2"));
addRandomMergeCas(casByUser);
DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters,
LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
casByUser = new HashMap<>();
JCas actual = DiffUtils.readWebAnnoTSV("mergecas/multivalspanrel/tale2.tsv", customType);
casByUser.put("actual", asList(actual));
casByUser.put("merge", asList(mergeCas));
result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL,
casByUser);
assertEquals(0, result.getDifferingConfigurationSets().size());
assertEquals(0, result.getIncompleteConfigurationSets().size());
}
示例12: relStackedTest
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
@Test
public void relStackedTest()
throws Exception
{
TypeSystemDescription customeTypesSpan = DiffUtils.createCustomTypeSystem(SPAN_TYPE,
"webanno.custom.Multivalspan", asList("f1", "f2"), null);
TypeSystemDescription customeTypesRel = DiffUtils.createCustomTypeSystem(RELATION_TYPE,
"webanno.custom.Multivalrel", asList("rel1", "rel2"),
"webanno.custom.Multivalspan");
List<TypeSystemDescription> customTypes = new ArrayList<>();
customTypes.add(customeTypesSpan);
customTypes.add(customeTypesRel);
TypeSystemDescription customType = CasCreationUtils.mergeTypeSystems(customTypes);
Map<String, List<JCas>> casByUser = DiffUtils.loadXMI(customType,
"mergecas/multivalspanrel/stackedrel1.xmi",
"mergecas/multivalspanrel/stackedrel2.xmi");
List<String> entryTypes = asList("webanno.custom.Multivalspan",
"webanno.custom.Multivalrel");
List<? extends DiffAdapter> diffAdapters = asList(
new ArcDiffAdapter("webanno.custom.Multivalrel", "Dependent", "Governor", "rel1",
"rel2"),
new SpanDiffAdapter("webanno.custom.Multivalspan", "f1", "f2"));
addRandomMergeCas(casByUser);
DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters,
LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
JCas actual = DiffUtils.readXMI("mergecas/multivalspanrel/stackedmerge.xmi", customType);
Type relType = mergeCas.getTypeSystem().getType("webanno.custom.Multivalrel");
int numRelMerge = CasUtil.select(mergeCas.getCas(), relType).size();
int numRelActual = CasUtil.select(actual.getCas(), relType).size();
Type spanType = mergeCas.getTypeSystem().getType("webanno.custom.Multivalspan");
int numspanMerge = CasUtil.select(mergeCas.getCas(), spanType).size();
int numspanActual = CasUtil.select(actual.getCas(), spanType).size();
assertEquals(2, numRelMerge);
assertEquals(2, numRelActual);
assertEquals(4, numspanMerge);
assertEquals(4, numspanActual);
}
示例13: upgradeCas
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
@Override
public void upgradeCas(CAS aCas, SourceDocument aSourceDocument, String aUser)
throws UIMAException, IOException
{
TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
.createTypeSystemDescription();
List<TypeSystemDescription> projectTypes = getProjectTypes(aSourceDocument.getProject());
projectTypes.add(builtInTypes);
TypeSystemDescription allTypes = CasCreationUtils.mergeTypeSystems(projectTypes);
// Prepare template for new CAS
CAS newCas = JCasFactory.createJCas(allTypes).getCas();
CASCompleteSerializer serializer = Serialization.serializeCASComplete((CASImpl) newCas);
// Save old type system
TypeSystem oldTypeSystem = aCas.getTypeSystem();
// Save old CAS contents
ByteArrayOutputStream os2 = new ByteArrayOutputStream();
Serialization.serializeWithCompression(aCas, os2, oldTypeSystem);
// Prepare CAS with new type system
Serialization.deserializeCASComplete(serializer, (CASImpl) aCas);
// Restore CAS data to new type system
Serialization.deserializeCAS(aCas, new ByteArrayInputStream(os2.toByteArray()),
oldTypeSystem, null);
// Make sure JCas is properly initialized too
aCas.getJCas();
try (MDC.MDCCloseable closable = MDC.putCloseable(
Logging.KEY_PROJECT_ID,
String.valueOf(aSourceDocument.getProject().getId()))) {
Project project = aSourceDocument.getProject();
log.info(
"Upgraded CAS of user [{}] for "
+ "document [{}]({}) in project [{}]({})",
aUser, aSourceDocument.getName(), aSourceDocument.getId(), project.getName(),
project.getId());
}
}
示例14: importCasFromFile
import org.apache.uima.util.CasCreationUtils; //导入方法依赖的package包/类
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public JCas importCasFromFile(File aFile, Project aProject, String aFormat)
throws UIMAException, IOException, ClassNotFoundException
{
Class readerClass = getReadableFormats().get(aFormat);
if (readerClass == null) {
throw new IOException("No reader available for format [" + aFormat + "]");
}
// Prepare a CAS with the project type system
TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory
.createTypeSystemDescription();
List<TypeSystemDescription> projectTypes = annotationService.getProjectTypes(aProject);
projectTypes.add(builtInTypes);
TypeSystemDescription allTypes = CasCreationUtils.mergeTypeSystems(projectTypes);
CAS cas = JCasFactory.createJCas(allTypes).getCas();
// Convert the source document to CAS
CollectionReader reader = CollectionReaderFactory.createReader(readerClass,
ResourceCollectionReaderBase.PARAM_SOURCE_LOCATION, aFile.getParentFile()
.getAbsolutePath(), ResourceCollectionReaderBase.PARAM_PATTERNS,
new String[] { "[+]" + aFile.getName() });
if (!reader.hasNext()) {
throw new FileNotFoundException(
"Source file [" + aFile.getName() + "] not found in [" + aFile.getPath() + "]");
}
reader.getNext(cas);
JCas jCas = cas.getJCas();
// Create sentence / token annotations if they are missing
boolean hasTokens = JCasUtil.exists(jCas, Token.class);
boolean hasSentences = JCasUtil.exists(jCas, Sentence.class);
// if (!hasTokens || !hasSentences) {
// AnalysisEngine pipeline = createEngine(createEngineDescription(
// BreakIteratorSegmenter.class,
// BreakIteratorSegmenter.PARAM_WRITE_TOKEN, !hasTokens,
// BreakIteratorSegmenter.PARAM_WRITE_SENTENCE, !hasSentences));
// pipeline.process(jCas);
// }
if (!hasSentences) {
splitSentences(jCas);
}
if (!hasTokens) {
tokenize(jCas);
}
if (!JCasUtil.exists(jCas, Token.class) || !JCasUtil.exists(jCas, Sentence.class)) {
throw new IOException("The document appears to be empty. Unable to detect any "
+ "tokens or sentences. Empty documents cannot be imported.");
}
return jCas;
}