use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.
the class CopyAnnotationTest method copyLinkToExistingButDiffLinkTest.
@Test
public void copyLinkToExistingButDiffLinkTest() throws Exception {
JCas mergeCAs = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
Type type = mergeCAs.getTypeSystem().getType(DiffUtils.HOST_TYPE);
Feature feature = type.getFeatureByBaseName("f1");
AnnotationFS mergeFs = DiffUtils.makeLinkHostMultiSPanFeatureFS(mergeCAs, 0, 0, feature, "A", DiffUtils.makeLinkFS(mergeCAs, "slot1", 0, 0));
FeatureStructure copyFS = DiffUtils.makeLinkFS(mergeCAs, "slot2", 0, 0);
List<FeatureStructure> linkFs = new ArrayList<>();
linkFs.add(copyFS);
WebAnnoCasUtil.setLinkFeatureValue(mergeFs, type.getFeatureByBaseName("links"), linkFs);
JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
casByUser.put("user1", asList(mergeCAs));
casByUser.put("user2", asList(jcasA));
List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
CasDiff2.SpanDiffAdapter adapter = new CasDiff2.SpanDiffAdapter(DiffUtils.HOST_TYPE);
adapter.addLinkFeature("links", "role", "target");
List<? extends CasDiff2.DiffAdapter> diffAdapters = asList(adapter);
CasDiff2.DiffResult diff = CasDiff2.doDiff(entryTypes, diffAdapters, CasDiff2.LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
assertEquals(0, diff.getDifferingConfigurationSets().size());
assertEquals(2, diff.getIncompleteConfigurationSets().size());
}
use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.
the class MergeCasTest method multiLinkWithRoleTargetDifferenceTest.
@Test
public void multiLinkWithRoleTargetDifferenceTest() throws Exception {
JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot1", 10, 10));
Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
casByUser.put("user1", asList(jcasA));
casByUser.put("user2", asList(jcasB));
casByUser.put(CURATION_USER, asList(jcasA));
List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
adapter.addLinkFeature("links", "role", "target");
List<? extends DiffAdapter> diffAdapters = asList(adapter);
DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
result.print(System.out);
JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();
assertEquals(1, numHost);
for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
assertEquals(0, linkFss.toArray().length);
}
}
use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.
the class MergeCasTest method multiLinkWithRoleLabelDifferenceTest.
@Test
public void multiLinkWithRoleLabelDifferenceTest() throws Exception {
JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot2", 0, 0));
Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
casByUser.put("user1", asList(jcasA));
casByUser.put("user2", asList(jcasB));
casByUser.put(CURATION_USER, asList(jcasA));
List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
adapter.addLinkFeature("links", "role", "target");
List<? extends DiffAdapter> diffAdapters = asList(adapter);
DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
result.print(System.out);
JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();
assertEquals(1, numHost);
for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
assertEquals(0, linkFss.toArray().length);
}
}
use of org.apache.uima.cas.FeatureStructure in project webanno by webanno.
the class SuggestionViewPanel method addSuggestionColor.
/**
* For each {@link ConfigurationSet}, where there are some differences in users annotation and
* the curation annotation.
*/
private void addSuggestionColor(Project aProject, Mode aMode, Map<String, JCas> aCasMap, Map<String, Map<VID, AnnotationState>> aSuggestionColors, Collection<ConfigurationSet> aCfgSet, boolean aI, boolean aAgree) {
for (ConfigurationSet cs : aCfgSet) {
boolean use = false;
for (String u : cs.getCasGroupIds()) {
Map<VID, AnnotationState> colors = aSuggestionColors.get(u);
if (colors == null) {
colors = new HashMap<>();
aSuggestionColors.put(u, colors);
}
for (Configuration c : cs.getConfigurations(u)) {
FeatureStructure fs = c.getFs(u, aCasMap);
AnnotationLayer layer = annotationService.getLayer(fs.getType().getName(), aProject);
TypeAdapter typeAdapter = annotationService.getAdapter(layer);
VID vid;
// link FS
if (c.getPosition().getFeature() != null) {
int fi = 0;
for (AnnotationFeature f : typeAdapter.listFeatures()) {
if (f.getName().equals(c.getPosition().getFeature())) {
break;
}
fi++;
}
vid = new VID(WebAnnoCasUtil.getAddr(fs), fi, c.getAID(u).index);
} else {
vid = new VID(WebAnnoCasUtil.getAddr(fs));
}
if (aAgree) {
colors.put(vid, AnnotationState.AGREE);
continue;
}
// automation and correction projects
if (!aMode.equals(Mode.CURATION) && !aAgree) {
if (cs.getCasGroupIds().size() == 2) {
colors.put(vid, AnnotationState.DO_NOT_USE);
} else {
colors.put(vid, AnnotationState.DISAGREE);
}
continue;
}
// this set agree with the curation annotation
if (c.getCasGroupIds().contains(CURATION_USER)) {
use = true;
} else {
use = false;
}
// this curation view
if (u.equals(CURATION_USER)) {
continue;
}
if (aAgree) {
colors.put(vid, AnnotationState.AGREE);
} else if (use) {
colors.put(vid, AnnotationState.USE);
} else if (aI) {
colors.put(vid, AnnotationState.DISAGREE);
} else if (!cs.getCasGroupIds().contains(CURATION_USER)) {
colors.put(vid, AnnotationState.DISAGREE);
} else {
colors.put(vid, AnnotationState.DO_NOT_USE);
}
}
}
}
}
use of org.apache.uima.cas.FeatureStructure in project lucene-solr by apache.
the class UIMAToSolrMapper method map.
/**
* map features of a certain UIMA type to corresponding Solr fields based on the mapping
*
* @param typeName name of UIMA type to map
*/
void map(String typeName, Map<String, MapField> featureFieldsmapping) throws FieldMappingException {
try {
Type type = cas.getTypeSystem().getType(typeName);
for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator.hasNext(); ) {
FeatureStructure fs = iterator.next();
for (String featureName : featureFieldsmapping.keySet()) {
MapField mapField = featureFieldsmapping.get(featureName);
String fieldNameFeature = mapField.getFieldNameFeature();
String fieldNameFeatureValue = fieldNameFeature == null ? null : fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
String fieldName = mapField.getFieldName(fieldNameFeatureValue);
if (log.isInfoEnabled()) {
log.info("mapping {}@{} to {}", new Object[] { typeName, featureName, fieldName });
}
String featureValue;
if (fs instanceof Annotation && "coveredText".equals(featureName)) {
featureValue = ((Annotation) fs).getCoveredText();
} else {
featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
}
if (log.isDebugEnabled()) {
log.debug("writing {} in {}", new Object[] { featureValue, fieldName });
}
document.addField(fieldName, featureValue);
}
}
} catch (Exception e) {
throw new FieldMappingException(e);
}
}
Aggregations