本文整理汇总了Java中org.apache.uima.fit.util.CasUtil类的典型用法代码示例。如果您正苦于以下问题:Java CasUtil类的具体用法?Java CasUtil怎么用?Java CasUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CasUtil类属于org.apache.uima.fit.util包,在下文中一共展示了CasUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
try{
JCas deidView = CasUtil.getView(jCas.getCas(), DEID_VIEW_NAME, true).getJCas();
String text = jCas.getDocumentText();
String decoderOut = decoder.decodeString(text);
while(true) {
Matcher m = xmlPatt.matcher(decoderOut);
if (!m.find()) {
break;
}
String matchType = m.group(1);
int matchStart = m.start();
int matchEnd = m.end();
decoderOut = decoderOut.substring(0, matchStart) + "[" + matchType + "]" + decoderOut.substring(matchEnd);
}
deidView.setDocumentText(decoderOut);
}catch(Exception e){
System.err.println("Error trying to run mist!");
throw new AnalysisEngineProcessException(e);
}
}
开发者ID:tmills,项目名称:ctakes-docker,代码行数:27,代码来源:MistAnalysisEngine.java
示例2: process
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
TreeMatcher treeMatcher = new TreeMatcher(this.tree);
Iterator<Token> iterator = JCasUtil.iterator(jcas, Token.class);
Type type = CasUtil.getType(jcas.getCas(), this.annotationType);
while (iterator.hasNext()) {
Token token = iterator.next();
String tokenText = token.getCoveredText();
tokenText = this.textNormalizer.normalize(tokenText);
treeMatcher.proceed(token.getBegin(), token.getEnd(), tokenText);
List<TreeMatch> matches = treeMatcher.getMatches();
for (TreeMatch match : matches) {
for (EntryMetadata metadata : match.matchedEntries()) {
annotate(jcas, type, match, metadata);
}
}
}
}
开发者ID:tokenmill,项目名称:dictionary-annotator,代码行数:20,代码来源:DictionaryAnnotator.java
示例3: checkForTheSameBoundaries
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
public static void checkForTheSameBoundaries(CAS cas, Class<? extends AnnotationFS> typeClass) {
Type type = CasUtil.getType(cas, typeClass);
FSIterator<AnnotationFS> iter = cas.getAnnotationIndex(type).iterator();
iter.moveToFirst();
if (!iter.isValid()) {
return;
}
AnnotationOffsetComparator<AnnotationFS> cmp =
AnnotationOffsetComparator.instance(AnnotationFS.class);
AnnotationFS lastAnno = iter.get();
iter.moveToNext();
while (iter.isValid()) {
AnnotationFS anno = iter.get();
if (cmp.compare(anno, lastAnno) == 0) {
throw new IllegalStateException(String.format(
"Annotations %s and %s have the same boundaries",
lastAnno, anno));
}
iter.moveToNext();
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:22,代码来源:AnnotationOffsetComparator.java
示例4: process
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Override
public void process(CAS cas) throws AnalysisEngineProcessException {
String docUriStr = DocumentUtils.getDocumentUri(cas);
if (docUriStr == null) {
throw new IllegalStateException("Can't extract document URI");
}
Path docUriPath = IoUtils.extractPathFromURI(docUriStr);
if (docUriPath.isAbsolute()) {
docUriPath = Paths.get("/").relativize(docUriPath);
}
Path outputPath = outputDir.resolve(docUriPath);
outputPath = IoUtils.addExtension(outputPath, outputFileSuffix);
try (PrintWriter out = IoUtils.openPrintWriter(outputPath.toFile())) {
for (AnnotationFS anno : CasUtil.select(cas, targetType)) {
String text = anno.getCoveredText();
text = StringUtils.replaceChars(text, "\r\n", " ");
out.println(text);
}
} catch (IOException e) {
throw new AnalysisEngineProcessException(e);
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:23,代码来源:AnnotationPerLineWriter.java
示例5: test
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void test() throws UIMAException, SAXException,
CpeDescriptorException, IOException {
for (JCas jCas : new JCasIterable(readerDesc,
tokenizerSentenceSplitterDesc, unitAnnotatorDesc)) {
CAS aCas = jCas.getCas();
Type unitSourceType = CasUtil.getType(aCas, unitTypes.iterator()
.next());
Type unitType = aCas.getTypeSystem().getType(
UnitAnnotator.UNIT_TYPE_NAME);
int sourceNumber = CasUtil.select(aCas, unitSourceType).size();
int unitNumber = CasUtil.select(aCas, unitType).size();
assertTrue(sourceNumber > 0);
assertThat(unitNumber, equalTo(sourceNumber));
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:18,代码来源:UnitAnnotatorTest.java
示例6: test
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void test() throws UIMAException, IOException {
SetMultimap<String, String> unitsByClass = HashMultimap.create();
for (JCas jCas : new JCasIterable(reader, tokenizerSentenceSplitter,
unitAnnotator, unitClassifier)) {
CAS aCas = jCas.getCas();
Type unitType = aCas.getTypeSystem().getType(
UnitAnnotator.UNIT_TYPE_NAME);
Feature classFeature = unitType
.getFeatureByBaseName(UnitClassifier.CLASS_FEAT_NAME);
for (AnnotationFS unitAnnotation : CasUtil.select(aCas, unitType)) {
if (unitAnnotation.getStringValue(classFeature) != null) {
unitsByClass.put(
unitAnnotation.getStringValue(classFeature),
unitAnnotation.getCoveredText());
}
}
}
assertEquals(
Sets.newHashSet("Вагнер", "двое", "боевиков", "пособница"),
unitsByClass.get("ru.kfu.itis.issst.evex.Person"));
assertEquals(Sets.newHashSet("ЦСКА"),
unitsByClass.get("ru.kfu.itis.issst.evex.Organization"));
assertEquals(Sets.newHashSet("штурма", "квартиры"),
unitsByClass.get("ru.kfu.itis.issst.evex.Weapon"));
}
开发者ID:textocat,项目名称:textokit-core,代码行数:27,代码来源:UnitClassifierTest.java
示例7: get
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
/**
* Get the {@link org.dkpro.argumentation.types.WebArgumentMetadata} from the JCas.
*
* @throws IllegalArgumentException if no {@link DocumentMetaData} exists in the jCas
*/
public static WebArgumentMetadata get(final JCas jCas)
{
FSIterator<FeatureStructure> iterator = jCas.getCas().getIndexRepository().getAllIndexedFS(
CasUtil.getType(jCas.getCas(), WebArgumentMetadata.class));
if (!iterator.hasNext()) {
throw new IllegalArgumentException(new Throwable("CAS does not contain any "
+ WebArgumentMetadata.class.getName()));
}
WebArgumentMetadata result = (WebArgumentMetadata) iterator.next();
if (iterator.hasNext()) {
throw new IllegalArgumentException(new Throwable("CAS contains more than one "
+ WebArgumentMetadata.class.getName()));
}
return result;
}
开发者ID:dkpro,项目名称:dkpro-argumentation,代码行数:25,代码来源:WebArgumentMetadataHelper.java
示例8: setAllRoleAnnosOnPosition
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
private static void setAllRoleAnnosOnPosition(Map<String, JCas> aJCases,
Map<String, ArrayFS> slotAnnosPerUser, Set<String> aUsers, FeatureStructure aBaseAnno,
Feature aFeature)
{
Type t = aBaseAnno.getType();
int begin = ((AnnotationFS) aBaseAnno).getBegin();
int end = ((AnnotationFS) aBaseAnno).getEnd();
for (String usr : aUsers) {
for (FeatureStructure baseFS : CasUtil.selectCovered(aJCases.get(usr).getCas(), t,
begin, end)) {
// if non eqal stacked annotations with slot feature exists, get
// the right one
if (isSameAnno(aBaseAnno, baseFS)) {
ArrayFS roleFs = (ArrayFS) WebAnnoCasUtil.getFeatureFS(baseFS,
aFeature.getShortName());
slotAnnosPerUser.put(usr, roleFs);
break;
}
}
}
}
开发者ID:webanno,项目名称:webanno,代码行数:23,代码来源:MergeCas.java
示例9: simpleCopyToEmptyTest
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void simpleCopyToEmptyTest()
throws Exception
{
AnnotatorState state = new AnnotatorStateImpl(Mode.CURATION);
state.setUser(new User());
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
JCas mergeCAs = JCasFactory.createJCas();
createTokenAnno(mergeCAs, 0, 0);
MergeCas.addSpanAnnotation(state, annotationSchemaService,
posLayer, mergeCAs, clickedFs, false);
assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:CopyAnnotationTest.java
示例10: simpleCopyToDiffExistingAnnoWithNoStackingTest
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void simpleCopyToDiffExistingAnnoWithNoStackingTest()
throws Exception
{
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
JCas mergeCAs = JCasFactory.createJCas();
AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
Feature posValue = type.getFeatureByBaseName("PosValue");
existingFs.setStringValue(posValue, "NE");
mergeCAs.addFsToIndexes(existingFs);
MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService,
posLayer, mergeCAs, clickedFs, false);
assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:CopyAnnotationTest.java
示例11: simpleCopyToDiffExistingAnnoWithStackingTest
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void simpleCopyToDiffExistingAnnoWithStackingTest()
throws Exception
{
AnnotatorState state = new AnnotatorStateImpl(Mode.CURATION);
state.setUser(new User());
posLayer.setAllowStacking(true);
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
JCas mergeCAs = JCasFactory.createJCas();
createTokenAnno(mergeCAs, 0, 0);
AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
Feature posValue = type.getFeatureByBaseName("PosValue");
existingFs.setStringValue(posValue, "NE");
mergeCAs.addFsToIndexes(existingFs);
MergeCas.addSpanAnnotation(state, annotationSchemaService, posLayer, mergeCAs, clickedFs,
true);
assertEquals(2, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
开发者ID:webanno,项目名称:webanno,代码行数:26,代码来源:CopyAnnotationTest.java
示例12: copySpanWithSlotNoStackingTest
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Test
public void copySpanWithSlotNoStackingTest()
throws Exception
{
slotLayer.setAllowStacking(false);
JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
Type type = jcasA.getTypeSystem().getType(DiffUtils.HOST_TYPE);
Feature feature = type.getFeatureByBaseName("f1");
AnnotationFS clickedFs = DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A",
DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
JCas mergeCAs = JCasFactory
.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
DiffUtils.makeLinkHostMultiSPanFeatureFS(mergeCAs, 0, 0, feature, "C",
DiffUtils.makeLinkFS(mergeCAs, "slot1", 0, 0));
MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService,
slotLayer, mergeCAs, clickedFs, false);
assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
开发者ID:webanno,项目名称:webanno,代码行数:25,代码来源:CopyAnnotationTest.java
示例13: delete
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Override
public void delete(AnnotatorState aState, JCas aJCas, VID aVid)
{
AnnotationFS fs = selectByAddr(aJCas, AnnotationFS.class, aVid.getId());
aJCas.removeFsFromIndexes(fs);
// delete associated attachFeature
if (getAttachTypeName() != null) {
Type theType = CasUtil.getType(aJCas.getCas(), getAttachTypeName());
Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
if (attachFeature != null) {
CasUtil.selectCovered(aJCas.getCas(), theType, fs.getBegin(), fs.getEnd()).get(0)
.setFeatureValue(attachFeature, null);
}
}
publishEvent(new SpanDeletedEvent(this, aState.getDocument(),
aState.getUser().getUsername(), fs));
}
开发者ID:webanno,项目名称:webanno,代码行数:20,代码来源:SpanAdapter.java
示例14: getSpan
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
public Serializable getSpan(JCas aJCas, int aBegin, int aEnd, AnnotationFeature aFeature,
String aLabelValue)
{
List<Token> tokens = selectOverlapping(aJCas, Token.class, aBegin, aEnd);
int begin = tokens.get(0).getBegin();
int end = tokens.get(tokens.size() - 1).getEnd();
String baseName = StringUtils.substringBeforeLast(getAnnotationTypeName(), CHAIN) + LINK;
Type linkType = CasUtil.getType(aJCas.getCas(), baseName);
for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), linkType, begin, end)) {
if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) {
return getFeatureValue(aFeature, fs);
}
}
return null;
}
开发者ID:webanno,项目名称:webanno,代码行数:17,代码来源:ChainAdapter.java
示例15: getAttachedSpans
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
private Set<AnnotationFS> getAttachedSpans(AnnotationFS aFs, AnnotationLayer aLayer)
{
CAS cas = aFs.getCAS();
Set<AnnotationFS> attachedSpans = new HashSet<>();
TypeAdapter adapter = annotationService.getAdapter(aLayer);
if (adapter instanceof SpanAdapter && aLayer.getAttachType() != null) {
Type spanType = CasUtil.getType(cas, aLayer.getAttachType().getName());
Feature attachFeature = spanType.getFeatureByBaseName(aLayer.getAttachFeature()
.getName());
for (AnnotationFS attachedFs : selectAt(cas, spanType, aFs.getBegin(), aFs.getEnd())) {
if (isSame(attachedFs.getFeatureValue(attachFeature), aFs)) {
attachedSpans.add(attachedFs);
}
}
}
return attachedSpans;
}
开发者ID:webanno,项目名称:webanno,代码行数:19,代码来源:AnnotationDetailEditorPanel.java
示例16: get
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
/**
* Get the {@link de.tudarmstadt.ukp.dkpro.argumentation.types.WebArgumentMetadata} from the JCas.
*
* @throws IllegalArgumentException if no {@link DocumentMetaData} exists in the jCas
*/
public static WebArgumentMetadata get(final JCas jCas)
{
FSIterator<FeatureStructure> iterator = jCas.getCas().getIndexRepository().getAllIndexedFS(
CasUtil.getType(jCas.getCas(), WebArgumentMetadata.class));
if (!iterator.hasNext()) {
throw new IllegalArgumentException(new Throwable("CAS does not contain any "
+ WebArgumentMetadata.class.getName()));
}
WebArgumentMetadata result = (WebArgumentMetadata) iterator.next();
if (iterator.hasNext()) {
throw new IllegalArgumentException(new Throwable("CAS contains more than one "
+ WebArgumentMetadata.class.getName()));
}
return result;
}
开发者ID:habernal,项目名称:dkpro-argumentation-minimal,代码行数:25,代码来源:WebArgumentMetadataHelper.java
示例17: getSingleAnnotation
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <A extends AnnotationFS> A getSingleAnnotation(JCas cas, Class<A> typeJCasClass) {
Type annoType = CasUtil.getAnnotationType(cas.getCas(), typeJCasClass);
AnnotationIndex<Annotation> annoIdx = cas.getAnnotationIndex(annoType);
if (annoIdx.size() == 0) {
return null;
} else if (annoIdx.size() == 1) {
return (A) annoIdx.iterator().next();
} else {
throw new IllegalStateException(String.format(
"Too much (>1) annotations of type %s", annoType));
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:14,代码来源:AnnotationUtils.java
示例18: process
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
private void process(CAS cas, PrintWriter out) {
AnnotationIndex<AnnotationFS> tokenIdx = cas.getAnnotationIndex(tokenType);
Multimap<AnnotationFS, String> tokLabelsMap = HashMultimap.create(tokenIdx.size(), 1);
// phase 1 - initialize map <token => label>
for (Type et : encodeTypesMap.keySet()) {
String typeLabel = encodeTypesMap.get(et);
for (AnnotationFS encAnno : cas.getAnnotationIndex(et)) {
Iterator<AnnotationFS> encAnnoTokens =
CasUtil.selectCovered(tokenType, encAnno).iterator();
if (!encAnnoTokens.hasNext()) {
getLogger().warn(format("%s: %s does not cover any tokens",
docURI, toPrettyString(encAnno)));
continue;
}
// handle first token of encAnno
tokLabelsMap.put(encAnnoTokens.next(), BEGIN_PREFIX + typeLabel);
// handle other tokens
while (encAnnoTokens.hasNext()) {
tokLabelsMap.put(encAnnoTokens.next(), INSIDE_PREFIX + typeLabel);
}
}
}
// phase 2 - write token records into output stream
for (AnnotationFS tok : tokenIdx) {
List<String> recordFields = Lists.newLinkedList();
recordFields.add(tok.getCoveredText());
//
Collection<String> tokLabels = tokLabelsMap.get(tok);
if (tokLabels.isEmpty()) {
recordFields.add(OUTSIDE_LABEL);
} else {
recordFields.addAll(tokLabels);
}
//
out.println(tabJoiner.join(recordFields));
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:38,代码来源:IobWriter.java
示例19: process
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Override
public void process(CAS cas) throws AnalysisEngineProcessException {
List<AnnotationFS> anno2DeleteList = Lists.newLinkedList();
for (AnnotationFS coveringAnno : CasUtil.select(cas, coveringAnnoType)) {
anno2DeleteList.addAll(CasUtil.selectCovered(cas, annoToDeleteType, coveringAnno));
}
for (AnnotationFS anno : anno2DeleteList) {
cas.removeFsFromIndexes(anno);
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:11,代码来源:DeleteCoveredAnnotations.java
示例20: process
import org.apache.uima.fit.util.CasUtil; //导入依赖的package包/类
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
for (AnnotationFS unit : CasUtil.select(aCAS, unitType)) {
for (Type classType : classTypes) {
for (AnnotationFS classAnnotation : CasUtil.select(aCAS,
classType)) {
if (isIntersect(unit, classAnnotation)) {
unit.setStringValue(classFeature, classType.getName());
}
}
}
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:14,代码来源:UnitClassifier.java
注:本文中的org.apache.uima.fit.util.CasUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论