use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AnnotationDetailEditorPanel method loadFeatureEditorModelsCommon.
private void loadFeatureEditorModelsCommon(AjaxRequestTarget aTarget, JCas aJCas, AnnotationLayer aLayer, FeatureStructure aFS, Map<AnnotationFeature, Serializable> aRemembered) {
clearFeatureEditorModels(aTarget);
AnnotatorState state = AnnotationDetailEditorPanel.this.getModelObject();
// Populate from feature structure
for (AnnotationFeature feature : annotationService.listAnnotationFeature(aLayer)) {
if (!feature.isEnabled()) {
continue;
}
Serializable value = null;
if (aFS != null) {
value = annotationService.getAdapter(aLayer).getFeatureValue(feature, aFS);
} else if (aRemembered != null) {
value = aRemembered.get(feature);
}
FeatureState featureState = null;
if (WebAnnoConst.CHAIN_TYPE.equals(feature.getLayer().getType())) {
if (state.getSelection().isArc()) {
if (feature.getLayer().isLinkedListBehavior() && WebAnnoConst.COREFERENCE_RELATION_FEATURE.equals(feature.getName())) {
featureState = new FeatureState(feature, value);
}
} else {
if (WebAnnoConst.COREFERENCE_TYPE_FEATURE.equals(feature.getName())) {
featureState = new FeatureState(feature, value);
}
}
} else {
featureState = new FeatureState(feature, value);
}
if (featureState != null) {
state.getFeatureStates().add(featureState);
// verification to check whether constraints exist for this project or NOT
if (state.getConstraints() != null && state.getSelection().getAnnotation().isSet()) {
// indicator.setRulesExist(true);
populateTagsBasedOnRules(aJCas, featureState);
} else {
// indicator.setRulesExist(false);
featureState.tagset = annotationService.listTags(featureState.feature.getTagset());
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AnnotationFeatureForm method updateLayersDropdown.
public void updateLayersDropdown() {
editorPanel.getLog().trace("updateLayersDropdown()");
AnnotatorState state = getModelObject();
annotationLayers.clear();
AnnotationLayer l = null;
for (AnnotationLayer layer : state.getAnnotationLayers()) {
if (!layer.isEnabled() || layer.isReadonly() || layer.getName().equals(Token.class.getName())) {
continue;
}
if (layer.getType().equals(WebAnnoConst.SPAN_TYPE)) {
annotationLayers.add(layer);
l = layer;
} else // manage chain type
if (layer.getType().equals(WebAnnoConst.CHAIN_TYPE)) {
for (AnnotationFeature feature : annotationService.listAnnotationFeature(layer)) {
if (!feature.isEnabled()) {
continue;
}
if (feature.getName().equals(WebAnnoConst.COREFERENCE_TYPE_FEATURE)) {
annotationLayers.add(layer);
}
}
}
// chain
}
if (state.getDefaultAnnotationLayer() != null) {
state.setSelectedAnnotationLayer(state.getDefaultAnnotationLayer());
} else if (l != null) {
state.setSelectedAnnotationLayer(l);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AutomationUtil method deleteRelationAnnotation.
public static void deleteRelationAnnotation(AnnotatorState aBModel, DocumentService aDocumentService, CorrectionDocumentService aCorrectionDocumentService, AnnotationSchemaService aAnnotationService, AnnotationFS fs, AnnotationFeature aFeature, String aValue) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
for (SourceDocument d : aDocumentService.listSourceDocuments(aBModel.getProject())) {
loadDocument(d, aAnnotationService, aDocumentService, aCorrectionDocumentService, aBModel.getUser());
JCas jCas = aCorrectionDocumentService.readCorrectionCas(d);
ArcAdapter adapter = (ArcAdapter) aAnnotationService.getAdapter(aFeature.getLayer());
String sourceFName = adapter.getSourceFeatureName();
String targetFName = adapter.getTargetFeatureName();
Type type = getType(jCas.getCas(), aFeature.getLayer().getName());
Type spanType = getType(jCas.getCas(), adapter.getAttachTypeName());
Feature arcSpanFeature = spanType.getFeatureByBaseName(adapter.getAttachFeatureName());
Feature dependentFeature = type.getFeatureByBaseName(targetFName);
Feature governorFeature = type.getFeatureByBaseName(sourceFName);
AnnotationFS dependentFs = null;
AnnotationFS governorFs = null;
if (adapter.getAttachFeatureName() != null) {
dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
} else {
dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature);
governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature);
}
int beginOffset = 0;
int endOffset = jCas.getDocumentText().length() - 1;
String depCoveredText = dependentFs.getCoveredText();
String govCoveredText = governorFs.getCoveredText();
adapter.delete(aBModel, jCas, aFeature, beginOffset, endOffset, depCoveredText, govCoveredText, aValue);
aCorrectionDocumentService.writeCorrectionCas(jCas, d);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AutomationUtil method addOtherFeatureTrainDocument.
// generates training document that will be used to predict the training document
// to add extra features, for example add POS tag as a feature for NE classifier
public static void addOtherFeatureTrainDocument(MiraTemplate aTemplate, AnnotationSchemaService aAnnotationService, AutomationService aAutomationService, UserDao aUserDao) throws IOException, UIMAException, ClassNotFoundException {
File miraDir = aAutomationService.getMiraDir(aTemplate.getTrainFeature());
if (!miraDir.exists()) {
FileUtils.forceMkdir(miraDir);
}
AutomationStatus status = aAutomationService.getAutomationStatus(aTemplate);
for (AnnotationFeature feature : aTemplate.getOtherFeatures()) {
File trainFile = new File(miraDir, feature.getId() + ".train");
boolean documentChanged = false;
for (TrainingDocument document : aAutomationService.listTrainingDocuments(feature.getProject())) {
if (!document.isProcessed() && (document.getFeature() != null && document.getFeature().equals(feature))) {
documentChanged = true;
break;
}
}
if (!documentChanged && trainFile.exists()) {
continue;
}
BufferedWriter trainOut = new BufferedWriter(new FileWriter(trainFile));
AutomationTypeAdapter adapter = (AutomationTypeAdapter) aAnnotationService.getAdapter(feature.getLayer());
for (TrainingDocument trainingDocument : aAutomationService.listTrainingDocuments(feature.getProject())) {
if ((trainingDocument.getFeature() != null && trainingDocument.getFeature().equals(feature))) {
JCas jCas = aAutomationService.readTrainingAnnotationCas(trainingDocument);
for (Sentence sentence : select(jCas, Sentence.class)) {
trainOut.append(getMiraLine(sentence, feature, adapter).toString()).append("\n");
}
trainingDocument.setProcessed(false);
status.setTrainDocs(status.getTrainDocs() - 1);
}
}
trainOut.close();
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class AutomationUtil method getFeatureOtherLayer.
private static void getFeatureOtherLayer(MiraTemplate aTemplate, DocumentService aRepository, AutomationService aAutomationService, AnnotationSchemaService aAnnotationService, UserDao aUserDao, int beamSize, boolean maxPosteriors, List<List<String>> predictions, Mira mira, File predFtFile, File predcitedFile, SourceDocument document) throws IOException, ClassNotFoundException, UIMAException {
// other layers as training document
for (AnnotationFeature feature : aTemplate.getOtherFeatures()) {
int shiftColumns = 0;
int nbest = 1;
String modelName = aAutomationService.getMiraModel(feature, true, null).getAbsolutePath();
if (!new File(modelName).exists()) {
addOtherFeatureFromAnnotation(feature, aRepository, aAutomationService, aAnnotationService, aUserDao, predictions, document);
continue;
}
String testName = predFtFile.getAbsolutePath();
PrintStream stream = new PrintStream(predcitedFile);
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
if (testName != null) {
input = new BufferedReader(new FileReader(testName));
}
mira.loadModel(modelName);
mira.setShiftColumns(shiftColumns);
mira.nbest = nbest;
mira.beamSize = beamSize;
mira.maxPosteriors = maxPosteriors;
mira.test(input, stream);
LineIterator it = IOUtils.lineIterator(new FileReader(predcitedFile));
List<String> annotations = new ArrayList<>();
while (it.hasNext()) {
String line = it.next();
if (line.trim().equals("")) {
continue;
}
StringTokenizer st = new StringTokenizer(line, " ");
String tag = "";
while (st.hasMoreTokens()) {
tag = st.nextToken();
}
annotations.add(tag);
}
predictions.add(annotations);
}
}
Aggregations