use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.
the class ComplexTypeTest method testCountryType.
@Test
public void testCountryType() throws Exception {
TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");
CAS cas = CasCreationUtils.createCas(tsd, null, null);
cas.setDocumentText("Asia is the largest continent on Earth. Asia is subdivided into 48 countries, two of them (Russia and Turkey) having part of their land in Europe. The most active place on Earth for tropical cyclone activity lies northeast of the Philippines and south of Japan. The Gobi Desert is in Mongolia and the Arabian Desert stretches across much of the Middle East. The Yangtze River in China is the longest river in the continent. The Himalayas between Nepal and China is the tallest mountain range in the world. Tropical rainforests stretch across much of southern Asia and coniferous and deciduous forests lie farther north.");
TypeSystem ts = cas.getTypeSystem();
Type continentType = ts.getType("de.Continent");
Feature continentName = continentType.getFeatureByBaseName("name");
AnnotationFS asiaContinent = cas.createAnnotation(continentType, 0, 4);
asiaContinent.setStringValue(continentName, "Asia");
cas.addFsToIndexes(asiaContinent);
Type countryType = ts.getType("de.Country");
Feature countryName = countryType.getFeatureByBaseName("name");
AnnotationFS russia = cas.createAnnotation(countryType, 56, 62);
russia.setStringValue(countryName, "Russian Federation");
Feature continentFeature = countryType.getFeatureByBaseName("continent");
russia.setFeatureValue(continentFeature, asiaContinent);
cas.addFsToIndexes(russia);
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/region.rules"));
Parse p = parser.Parse();
ParsedConstraints constraints = p.accept(new ParserVisitor());
Evaluator constraintsEvaluator = new ValuesGenerator();
List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(russia, "regionType", constraints);
List<PossibleValue> exValues = new LinkedList<>();
exValues.add(new PossibleValue("cold", true));
assertEquals(possibleValues, exValues);
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.
the class ComplexTypeTest method testProfType.
@Test
public void testProfType() throws Exception {
TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");
CAS cas = CasCreationUtils.createCas(tsd, null, null);
cas.setDocumentText("I listen to lectures by Prof. Gurevych sometimes.");
TypeSystem ts = cas.getTypeSystem();
Type profType = ts.getType("de.tud.Prof");
Feature profNameFeature = profType.getFeatureByBaseName("fullName");
Feature profBossFeature = profType.getFeatureByBaseName("boss");
AnnotationFS proemel = cas.createAnnotation(profType, 0, 0);
proemel.setStringValue(profNameFeature, "Hans Juergen Proeml");
cas.addFsToIndexes(proemel);
AnnotationFS gurevych = cas.createAnnotation(profType, 24, 38);
gurevych.setStringValue(profNameFeature, "Iryna Gurevych");
gurevych.setFeatureValue(profBossFeature, proemel);
cas.addFsToIndexes(gurevych);
/*
* for (String feature : Arrays.asList("fullName", "boss")) { Feature someFeature =
* gurevych.getType().getFeatureByBaseName(feature); if
* (someFeature.getRange().isPrimitive()) { String value =
* gurevych.getFeatureValueAsString(someFeature); System.out.println(value); } else {
* FeatureStructure value = gurevych.getFeatureValue(someFeature);
* System.out.printf("%s (%s)%n", value.getFeatureValueAsString(profNameFeature),
* value.getType()); } }
*/
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/prof.rules"));
Parse p = parser.Parse();
ParsedConstraints constraints = p.accept(new ParserVisitor());
Evaluator constraintsEvaluator = new ValuesGenerator();
List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(gurevych, "professorName", constraints);
List<PossibleValue> exValues = new LinkedList<>();
exValues.add(new PossibleValue("Iryna Gurevych", false));
assertEquals(possibleValues, exValues);
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.
the class LinkFeatureEditor method autoAddImportantTags.
private void autoAddImportantTags(List<Tag> aTagset, List<PossibleValue> aPossibleValues) {
if (aTagset == null || aTagset.isEmpty() || aPossibleValues == null || aPossibleValues.isEmpty()) {
return;
}
// Construct a quick index for tags
Set<String> tagset = new HashSet<>();
for (Tag t : aTagset) {
tagset.add(t.getName());
}
// Get links list and build role index
@SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) getModelObject().value;
Set<String> roles = new HashSet<>();
for (LinkWithRoleModel l : links) {
roles.add(l.role);
}
// Loop over values to see which of the tags are important and add them.
for (PossibleValue value : aPossibleValues) {
if (!value.isImportant() || !tagset.contains(value.getValue())) {
continue;
}
// Check if there is already a slot with the given name
if (roles.contains(value.getValue())) {
continue;
}
// Add empty slot in UI with that name.
LinkWithRoleModel m = new LinkWithRoleModel();
m.role = value.getValue();
// Marking so that can be ignored later.
m.autoCreated = true;
links.add(m);
// NOT arming the slot here!
}
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.
the class AnnotationDetailEditorPanel method compareSortAndAdd.
/*
* Compares existing tagset with possible values resulted from rule evaluation Adds only which
* exist in tagset and is suggested by rules. The remaining values from tagset are added
* afterwards.
*/
private static List<Tag> compareSortAndAdd(List<PossibleValue> possibleValues, List<Tag> valuesFromTagset, RulesIndicator rulesIndicator) {
// if no possible values, means didn't satisfy conditions
if (possibleValues.isEmpty()) {
rulesIndicator.didntMatchAnyRule();
}
List<Tag> returnList = new ArrayList<>();
// tagset and adding them first in list.
for (PossibleValue value : possibleValues) {
for (Tag tag : valuesFromTagset) {
if (value.getValue().equalsIgnoreCase(tag.getName())) {
// Matching values found in tagset and shown in dropdown
rulesIndicator.rulesApplied();
// HACK BEGIN
tag.setReordered(true);
// Avoid duplicate entries
if (!returnList.contains(tag)) {
returnList.add(tag);
}
}
}
}
// If no matching tags found
if (returnList.isEmpty()) {
rulesIndicator.didntMatchAnyTag();
}
return returnList;
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue in project webanno by webanno.
the class ConstraintsGeneratorTest method testSimpleFeature.
@Test
public void testSimpleFeature() throws Exception {
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/9.rules"));
Parse p = parser.Parse();
ParsedConstraints constraints = p.accept(new ParserVisitor());
JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText("is");
Lemma lemma = new Lemma(jcas, 0, 2);
lemma.setValue("be");
lemma.addToIndexes();
Evaluator constraintsEvaluator = new ValuesGenerator();
List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(lemma, "value", constraints);
List<PossibleValue> expectedOutput = new LinkedList<>();
expectedOutput.add(new PossibleValue("be", true));
assertEquals(expectedOutput, possibleValues);
}
Aggregations