本文整理汇总了Java中org.apache.uima.UIMAException类的典型用法代码示例。如果您正苦于以下问题:Java UIMAException类的具体用法?Java UIMAException怎么用?Java UIMAException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UIMAException类属于org.apache.uima包,在下文中一共展示了UIMAException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.uima.UIMAException; //导入依赖的package包/类
public static void main(String[] args) throws ResourceInitializationException, UIMAException, IOException {
SimplePipeline.runPipeline(
CollectionReaderFactory.createReaderDescription(TextgridTEIUrlReader.class,
TextgridTEIUrlReader.PARAM_INPUT, "http://www.textgridrep.org/textgrid:tx4z.0",
TextgridTEIUrlReader.PARAM_CLEANUP, true),
AnalysisEngineFactory.createEngineDescription(XmiWriter.class, XmiWriter.PARAM_USE_DOCUMENT_ID, true,
XmiWriter.PARAM_TARGET_LOCATION, "src/test/resources/SpeakerAssignmentRules/"));
SimplePipeline.runPipeline(
CollectionReaderFactory.createReaderDescription(TextgridTEIUrlReader.class,
TextgridTEIUrlReader.PARAM_INPUT, "http://www.textgridrep.org/textgrid:w3zd.0",
TextgridTEIUrlReader.PARAM_CLEANUP, true),
AnalysisEngineFactory.createEngineDescription(XmiWriter.class, XmiWriter.PARAM_USE_DOCUMENT_ID, true,
XmiWriter.PARAM_TARGET_LOCATION, "src/test/resources/SpeakerAssignmentRules/"));
new File("src/test/resources/SpeakerAssignmentRules/typesystem.xml").delete();
}
示例2: writeModel
import org.apache.uima.UIMAException; //导入依赖的package包/类
/**
* @param posTagFile
* @param modelDirectory
* @param language
* @throws UIMAException
* @throws IOException
*/
public static void writeModel(File posTagFile, String modelDirectory, String language) throws UIMAException, IOException {
CollectionReader posTagFileReader = FilesCollectionReader.getCollectionReaderWithSuffixes(
posTagFile.getAbsolutePath(), NERReader.CONLL_VIEW, posTagFile.getName());
AnalysisEngine snowballStemmer = createEngine(SnowballStemmer.class, SnowballStemmer.PARAM_LANGUAGE, language);
AnalysisEngine nerAnnotator = createEngine(NERAnnotator.class,
NERAnnotator.PARAM_FEATURE_EXTRACTION_FILE, "src/main/resources/feature/features.xml",
NERAnnotator.PARAM_IS_TRAINING, true,
DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY, modelDirectory,
DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME, CrfSuiteStringOutcomeDataWriter.class);
runPipeline(
posTagFileReader,
createEngine(NERReader.class),
snowballStemmer,
nerAnnotator
);
}
示例3: classifyTestFile
import org.apache.uima.UIMAException; //导入依赖的package包/类
public static void classifyTestFile(String modelDirectory, File testPosFile, String language)
throws ResourceInitializationException, UIMAException, IOException {
CollectionReader testPosFileReader = FilesCollectionReader.getCollectionReaderWithSuffixes(testPosFile.getAbsolutePath(),
NERReader.CONLL_VIEW, testPosFile.getName());
AnalysisEngine nerReader = createEngine(NERReader.class);
AnalysisEngine snowballStemmer = createEngine(SnowballStemmer.class, SnowballStemmer.PARAM_LANGUAGE, language);
AnalysisEngine nerAnnotator = createEngine(NERAnnotator.class,
NERAnnotator.PARAM_FEATURE_EXTRACTION_FILE, "src/main/resources/feature/features.xml",
GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH, modelDirectory + "model.jar");
AnalysisEngine nerWriter = createEngine(NERWriter.class,
NERWriter.PARAM_NULL_TYPE, "O",
NERWriter.PARAM_EXPECTED_ENTITY_TYPE_NUM, 9,
NERWriter.PARAM_FILENAME, "src/test/resources/evaluation/eval.txt",
NERWriter.PARAM_VERBOSE, true);
runPipeline(
testPosFileReader,
nerReader,
snowballStemmer,
nerAnnotator,
nerWriter);
}
示例4: writeModel
import org.apache.uima.UIMAException; //导入依赖的package包/类
/**
* @param posTagFile
* @param configFileName
* @param language
* @throws UIMAException
* @throws IOException
*/
private void writeModel(File posTagFile, String language, String configFileName) throws UIMAException, IOException {
new File(getModelDir()).mkdirs();
CollectionReader posTagFileReader = FilesCollectionReader.getCollectionReaderWithSuffixes(
posTagFile.getAbsolutePath(), NERReader.CONLL_VIEW, posTagFile.getName());
AnalysisEngine snowballStemmer = createEngine(SnowballStemmer.class, SnowballStemmer.PARAM_LANGUAGE, language);
AnalysisEngine nerAnnotator = createEngine(NERAnnotator.class,
NERAnnotator.PARAM_FEATURE_EXTRACTION_FILE, FEATURE_EXTRACTOR_CONFIG_DIRECTORY + configFileName,
NERAnnotator.PARAM_IS_TRAINING, true,
DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY, getModelDir(),
DefaultDataWriterFactory.PARAM_DATA_WRITER_CLASS_NAME, CrfSuiteStringOutcomeDataWriter.class);
runPipeline(
posTagFileReader,
createEngine(NERReader.class),
snowballStemmer,
nerAnnotator
);
}
示例5: main
import org.apache.uima.UIMAException; //导入依赖的package包/类
public static void main(String[] args) throws UIMAException, IOException {
Logger.getRootLogger().setLevel(Level.INFO);
if (args.length > 0)
textFolder = args[0];
// read preprocessed documents
CollectionReaderDescription reader = CollectionReaderFactory.createReaderDescription(BinaryCasReader.class,
BinaryCasReader.PARAM_SOURCE_LOCATION, textFolder, BinaryCasReader.PARAM_PATTERNS, textPattern,
BinaryCasReader.PARAM_LANGUAGE, "en");
// find Open IE tuples
AnalysisEngineDescription openIE = AnalysisEngineFactory.createEngineDescription(OpenIEAnnotator.class);
// write annotated data to file
AnalysisEngineDescription writer = AnalysisEngineFactory.createEngineDescription(BinaryCasWriter.class,
BinaryCasWriter.PARAM_TARGET_LOCATION, textFolder, BinaryCasWriter.PARAM_STRIP_EXTENSION, true,
BinaryCasWriter.PARAM_FILENAME_EXTENSION, ".oie.bin6", BinaryCasWriter.PARAM_OVERWRITE, true);
// run pipeline
SimplePipeline.runPipeline(reader, openIE, writer);
}
示例6: getConcepts
import org.apache.uima.UIMAException; //导入依赖的package包/类
default List<Concept> getConcepts(List<String> texts, String viewNamePrefix)
throws AnalysisEngineProcessException {
JCas jcas;
try {
jcas = JCasFactory.createJCas();
} catch (UIMAException e) {
throw new AnalysisEngineProcessException(e);
}
List<JCas> views = texts.stream().map(text -> {
String uuid = UUID.randomUUID().toString();
JCas view = ViewType.createView(jcas, viewNamePrefix, uuid, text);
InputElement ie = new InputElement(view, 0, text.length());
ie.setDataset("N/A");
ie.setQuuid(UUID.randomUUID().toString());
ie.addToIndexes();
return view;
} ).collect(Collectors.toList());
return getConcepts(views);
}
示例7: sentenceAnalysis
import org.apache.uima.UIMAException; //导入依赖的package包/类
private HashMap<String, String> sentenceAnalysis(String sentence) {
HashMap<String, String> dependency = new HashMap<String, String>();
try {
JCas snippetJcas = JCasFactory.createJCas();
snippetJcas.setDocumentText(sentence);
List<Token> tokens = parserProvider.parseDependency(snippetJcas);
for (Token tok : tokens) {
if (tok.getHead() == null)
continue;
dependency.put(tok.getLemmaForm(), tok.getHead().getLemmaForm());
}
snippetJcas.release();
} catch (UIMAException err) {
err.printStackTrace();
}
return dependency;
}
示例8: main
import org.apache.uima.UIMAException; //导入依赖的package包/类
public static void main(String[] args) throws UIMAException {
JCas jcas = JCasFactory.createJCas();
AtomicQueryConcept rheumatoidArthritisConcept = createAtomicQueryConcept(jcas, "Title",
KEYWORD_TYPE, "Rheumatoid Arthritis", "Rheumatoid Arthritis");
AtomicQueryConcept genderConcept = createAtomicQueryConcept(jcas, "Title", KEYWORD_TYPE,
"gender", "gender");
AtomicQueryConcept maleConcept = createAtomicQueryConcept(jcas, "Title", KEYWORD_TYPE, "male",
"male");
AtomicQueryConcept femaleConcept = createAtomicQueryConcept(jcas, "Title", KEYWORD_TYPE,
"female", "female");
ComplexQueryConcept orConcept = createComplexQueryConcept(jcas, KEYWORD_TYPE,
createQueryOperator(jcas, TIE), genderConcept, maleConcept, femaleConcept);
ComplexQueryConcept andConcept = createComplexQueryConcept(jcas, KEYWORD_TYPE,
createQueryOperator(jcas, REQUIRED), rheumatoidArthritisConcept, orConcept);
AbstractQuery aquery = createAbstractQuery(jcas, andConcept);
BagOfPhraseQueryStringConstructor bopQueryStringConstructor = new BagOfPhraseQueryStringConstructor();
System.out.println("Bag of phrases: " + bopQueryStringConstructor.construct(aquery));
PubMedQueryStringConstructor pubmedQueryStringConstructor = new PubMedQueryStringConstructor();
System.out.println("PubMed: " + pubmedQueryStringConstructor.construct(aquery));
}
示例9: test
import org.apache.uima.UIMAException; //导入依赖的package包/类
@Test
public void test() throws IOException, UIMAException {
final JCas jCas = JCasFactory.createJCas();
assertTrue(reader.doHasNext());
reader.doGetNext(jCas);
assertEquals("Some example\ntext.", jCas.getDocumentText());
jCas.reset();
assertTrue(reader.doHasNext());
reader.doGetNext(jCas);
assertEquals("Another example", jCas.getDocumentText());
jCas.reset();
assertFalse(reader.doHasNext());
}
示例10: beforeTest
import org.apache.uima.UIMAException; //导入依赖的package包/类
@Override
public void beforeTest() throws UIMAException {
super.beforeTest();
final ExternalResourceDescription tokensDesc = ExternalResourceFactory.createExternalResourceDescription(
"lexica",
ClearNlpLexica.class);
final AnalysisEngineDescription tokeniserDesc = AnalysisEngineFactory.createEngineDescription(
ClearNlpTokeniser.class,
"lexica",
tokensDesc);
tokeniserAe = AnalysisEngineFactory.createEngine(tokeniserDesc);
final AnalysisEngineDescription parserDesc = AnalysisEngineFactory.createEngineDescription(ClearNlpParser.class,
"lexica",
tokensDesc);
ae = AnalysisEngineFactory.createEngine(parserDesc);
}
示例11: createXMIFileForDocument
import org.apache.uima.UIMAException; //导入依赖的package包/类
private File createXMIFileForDocument(de.unisaarland.swan.entities.Document d) throws UIMAException, IOException {
JCas jCas = createJCasForDocument(d);
String filename = d.getName() + ".xmi";
File xmiFile = new File(filename);
for (Users u : d.getProject().getUsers()) {
Map<Long, SwanAnnotation> annotsById = new HashMap<>();
for (de.unisaarland.swan.entities.Annotation annotation : annotationDAO.getAllAnnotationsByUserIdDocId(u.getId(), d.getId())) {
addAnnotationToJCas(annotation, annotsById, jCas);
}
for (de.unisaarland.swan.entities.Link link : linkDAO.getAllLinksByUserIdDocId(u.getId(), d.getId())) {
addLinkToJCas(link, annotsById, jCas);
}
}
CasIOUtil.writeXmi(jCas, xmiFile);
return xmiFile;
}
示例12: buildConceptMapperAggregate
import org.apache.uima.UIMAException; //导入依赖的package包/类
private static AnalysisEngineDescription buildConceptMapperAggregate(List<String> paramValues,
TypeSystemDescription tsd, File dictionaryFile, Class<? extends Annotation> spanFeatureStructureClass)
throws UIMAException, IOException {
CaseMatchParamValue caseMatchParamValue = getCaseMatchParamValue(paramValues);
SearchStrategyParamValue searchStrategyParamValue = getSearchStrategyParamValue(paramValues);
Class<? extends Stemmer> stemmerClass = getStemmerClass(paramValues);
String[] stopwordList = getStopWordList(paramValues);
boolean orderIndependentLookup = getOrderIndependentLookup(paramValues);
boolean findAllMatches = getFindAllMatches(paramValues);
// boolean replaceCommaWithAnd = getReplaceCommaWithAnd(paramValues);
boolean replaceCommaWithAnd = false; // this parameter doesn't appear to be enabled in
// ConceptMapper
return ConceptMapperAggregateFactory.getOffsetTokenizerConceptMapperAggregateDescription(tsd, dictionaryFile,
caseMatchParamValue, searchStrategyParamValue, spanFeatureStructureClass, stemmerClass, stopwordList,
orderIndependentLookup, findAllMatches, replaceCommaWithAnd);
}
示例13: buildConceptMapperDescription
import org.apache.uima.UIMAException; //导入依赖的package包/类
/**
* Returns an {@link AnalysisEngineDescription} initialized using the input configuration data.
* The base of the description is loaded from the ConceptMapperOffsetTokenizer.xml descriptor
* file that is part of the ConceptMapper distribution. Parameter settings in that file are
* overridden by those set in the input configuration data.
*
* @param tsd
* @param configurationData
* @return
* @throws UIMAException
* @throws IOException
*/
public static AnalysisEngineDescription buildConceptMapperDescription(TypeSystemDescription tsd,
Object[] configurationData) throws UIMAException, IOException {
AnalysisEngineDescription description = AnalysisEngineFactory.createAnalysisEngineDescription(
CONCEPT_MAPPER_DESCRIPTOR_PATH, configurationData);
TypeSystemDescription cmTypeSystem = description.getAnalysisEngineMetaData().getTypeSystem();
/*
* The ConceptMapper Descriptor defines the uima.tt.TokenAnnotation type so we extract it
* and add it to the input type system
*/
TypeDescription tokenAnnotationTypeDesc = cmTypeSystem.getType("uima.tt.TokenAnnotation");
List<TypeDescription> types = new ArrayList<TypeDescription>(Arrays.asList(tsd.getTypes()));
types.add(tokenAnnotationTypeDesc);
TypeSystemDescription tsdToUse = TypeSystemDescriptionFactory.createTypeSystemDescription();
tsdToUse.setTypes(types.toArray(new TypeDescription[types.size()]));
description.getAnalysisEngineMetaData().setTypeSystem(tsdToUse);
return description;
}
示例14: initJCas
import org.apache.uima.UIMAException; //导入依赖的package包/类
@Override
protected void initJCas() throws UIMAException {
String sentence1 = "Here is some text with some GO terms.";
String sentence2 = "The NEF1 complex is known to be a part of the nucleotide-excision repair complex.";
jcas.setDocumentText(sentence1 + " " + sentence2);
Sentence sentenceAnnot1 = new Sentence(jcas, 0, sentence1.length());
sentenceAnnot1.addToIndexes();
Sentence sentenceAnnot2 = new Sentence(jcas, sentence1.length() + 1, sentence1.length() + 1
+ sentence2.length());
sentenceAnnot2.addToIndexes();
assertEquals(sentence1, sentenceAnnot1.getCoveredText());
assertEquals(sentence2, sentenceAnnot2.getCoveredText());
}
示例15: loadXCasFile
import org.apache.uima.UIMAException; //导入依赖的package包/类
/**
* Loads the input XCas file and returns a GenericDocument containing the document text and all
* annotations.
*
* @param xcasFile
* @return
*/
public static GenericDocument loadXCasFile(InputStream xcasStream, TypeSystemDescription tsd) throws UIMAException {
JCas jcas = JCasFactory.createJCas(tsd);
try {
XCASDeserializer.deserialize(xcasStream, jcas.getCas());
} catch (SAXException e) {
throw new UIMAException(e);
} catch (IOException e) {
throw new UIMAException(e);
}
GenericDocument gd = new GenericDocument();
UIMA_Util.swapDocumentInfo(jcas, gd);
int numAnnotationsInGenericDocument = gd.getAnnotations().size();
int numAnnotationsInJCas = jcas.getJFSIndexRepository().getAnnotationIndex(CCPTextAnnotation.type).size();
assert numAnnotationsInGenericDocument == numAnnotationsInJCas : String
.format("Number of annotations in jcas not equal to the number of annotations in the generic document. %d != %d",
numAnnotationsInJCas, numAnnotationsInGenericDocument);
return gd;
}