Commit f78fef64787429b30db57491ee0be5bfdec97c8a

Authored by Matthijs Brouwer
1 parent 2ce77c0c

updates parser folia (relationAnnotation)

... ... @@ -24,7 +24,7 @@
24 24 <modelVersion>4.0.0</modelVersion>
25 25 <groupId>nl.knaw.meertens.mtas</groupId>
26 26 <artifactId>mtas</artifactId>
27   - <version>7.3.0.0-SNAPSHOT</version>
  27 + <version>7.3.0.1-SNAPSHOT</version>
28 28 <packaging>jar</packaging>
29 29 <licenses>
30 30 <license>
... ...
src/main/java/mtas/analysis/parser/MtasBasicParser.java
... ... @@ -205,6 +205,9 @@ public abstract class MtasBasicParser extends MtasParser {
205 205 /** The Constant MAPPING_VALUE_NAME. */
206 206 protected static final String MAPPING_VALUE_NAME = "name";
207 207  
  208 + /** The Constant MAPPING_VALUE_NAME. */
  209 + protected static final String MAPPING_VALUE_NAMESPACE = "namespace";
  210 +
208 211 /** The Constant MAPPING_VALUE_PREFIX. */
209 212 protected static final String MAPPING_VALUE_PREFIX = "prefix";
210 213  
... ... @@ -888,12 +891,18 @@ public abstract class MtasBasicParser extends MtasParser {
888 891 // add attribute to value
889 892 } else if (mappingValue.get(MAPPING_VALUE_TYPE)
890 893 .equals(MtasParserMapping.PARSER_TYPE_ATTRIBUTE)) {
891   - String tmpValue = null;
  894 + String tmpValue = null;
892 895 if (mappingValue.get(MAPPING_VALUE_NAME).equals("#")) {
893 896 tmpValue = checkObjects[0].getId();
894 897 } else {
895   - tmpValue = checkObjects[0]
  898 + String namespace = mappingValue.get(MAPPING_VALUE_NAMESPACE);
  899 + if(namespace==null) {
  900 + tmpValue = checkObjects[0]
896 901 .getAttribute(mappingValue.get(MAPPING_VALUE_NAME));
  902 + } else {
  903 + tmpValue = checkObjects[0]
  904 + .getOtherAttribute(namespace, mappingValue.get(MAPPING_VALUE_NAME));
  905 + }
897 906 }
898 907 String subvalue = computeFilteredPrefixedValue(
899 908 mappingValue.get(MAPPING_VALUE_TYPE), tmpValue,
... ... @@ -1293,8 +1302,13 @@ public abstract class MtasBasicParser extends MtasParser {
1293 1302 .equals(MtasParserMapping.PARSER_TYPE_ATTRIBUTE)) {
1294 1303 String attributeCondition = mappingCondition
1295 1304 .get(MAPPING_VALUE_CONDITION);
1296   - String attributeValue = checkObject
1297   - .getAttribute(mappingCondition.get("name"));
  1305 + String namespace = mappingCondition.get(MAPPING_VALUE_NAMESPACE);
  1306 + String attributeValue;
  1307 + if(namespace==null) {
  1308 + attributeValue = checkObject.getAttribute(mappingCondition.get(MAPPING_VALUE_NAME));
  1309 + } else {
  1310 + attributeValue = checkObject.getOtherAttribute(namespace, mappingCondition.get(MAPPING_VALUE_NAME));
  1311 + }
1298 1312 if ((attributeCondition == null) && (attributeValue == null)) {
1299 1313 if (!notCondition) {
1300 1314 throw new MtasParserException("attribute "
... ... @@ -1985,6 +1999,8 @@ public abstract class MtasBasicParser extends MtasParser {
1985 1999 .get(MAPPING_VALUE_TYPE);
1986 2000 String nameAttribute = items.children.get(l).attributes
1987 2001 .get(MAPPING_VALUE_NAME);
  2002 + String namespaceAttribute = items.children.get(l).attributes
  2003 + .get(MAPPING_VALUE_NAMESPACE);
1988 2004 String prefixAttribute = items.children.get(l).attributes
1989 2005 .get(MAPPING_VALUE_PREFIX);
1990 2006 String filterAttribute = items.children.get(l).attributes
... ... @@ -1999,7 +2015,7 @@ public abstract class MtasBasicParser extends MtasParser {
1999 2015 addName(mappingToken, items.name, prefixAttribute,
2000 2016 filterAttribute);
2001 2017 } else if (itemType.equals(ITEM_TYPE_ATTRIBUTE)) {
2002   - addAttribute(mappingToken, items.name, nameAttribute,
  2018 + addAttribute(mappingToken, items.name, nameAttribute, namespaceAttribute,
2003 2019 prefixAttribute, filterAttribute);
2004 2020 } else if (itemType.equals(ITEM_TYPE_TEXT)) {
2005 2021 addText(mappingToken, items.name, prefixAttribute,
... ... @@ -2175,6 +2191,8 @@ public abstract class MtasBasicParser extends MtasParser {
2175 2191 String itemType = items.children.get(l).attributes.get("type");
2176 2192 String nameAttribute = items.children.get(l).attributes
2177 2193 .get(MAPPING_VALUE_NAME);
  2194 + String namespaceAttribute = items.children.get(l).attributes
  2195 + .get(MAPPING_VALUE_NAMESPACE);
2178 2196 String conditionAttribute = items.children.get(l).attributes
2179 2197 .get(MAPPING_VALUE_CONDITION);
2180 2198 String filterAttribute = items.children.get(l).attributes
... ... @@ -2189,7 +2207,7 @@ public abstract class MtasBasicParser extends MtasParser {
2189 2207 notAttribute = null;
2190 2208 }
2191 2209 if (itemType.equals(ITEM_TYPE_ATTRIBUTE)) {
2192   - conditionAttribute(nameAttribute, conditionAttribute,
  2210 + conditionAttribute(nameAttribute, namespaceAttribute, conditionAttribute,
2193 2211 filterAttribute, notAttribute);
2194 2212 } else if (itemType.equals(ITEM_TYPE_NAME)) {
2195 2213 conditionName(conditionAttribute, notAttribute);
... ... @@ -2484,11 +2502,12 @@ public abstract class MtasBasicParser extends MtasParser {
2484 2502 * @param filter the filter
2485 2503 */
2486 2504 private void addAttribute(MtasParserMappingToken mappingToken, String type,
2487   - String name, String prefix, String filter) {
  2505 + String name, String namespace, String prefix, String filter) {
2488 2506 HashMap<String, String> mapConstructionItem = new HashMap<>();
2489 2507 mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);
2490 2508 mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);
2491 2509 mapConstructionItem.put(MAPPING_VALUE_NAME, name);
  2510 + mapConstructionItem.put(MAPPING_VALUE_NAMESPACE, namespace);
2492 2511 mapConstructionItem.put(MAPPING_VALUE_PREFIX, prefix);
2493 2512 mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);
2494 2513 if (name != null) {
... ... @@ -2534,12 +2553,13 @@ public abstract class MtasBasicParser extends MtasParser {
2534 2553 * @param filter the filter
2535 2554 * @param not the not
2536 2555 */
2537   - private void conditionAttribute(String name, String condition,
  2556 + private void conditionAttribute(String name, String namespace, String condition,
2538 2557 String filter, String not) {
2539 2558 HashMap<String, String> mapConstructionItem = new HashMap<>();
2540 2559 mapConstructionItem.put(MAPPING_VALUE_SOURCE, SOURCE_OWN);
2541 2560 mapConstructionItem.put(MAPPING_VALUE_TYPE, PARSER_TYPE_ATTRIBUTE);
2542 2561 mapConstructionItem.put(MAPPING_VALUE_NAME, name);
  2562 + mapConstructionItem.put(MAPPING_VALUE_NAMESPACE, namespace);
2543 2563 mapConstructionItem.put(MAPPING_VALUE_CONDITION, condition);
2544 2564 mapConstructionItem.put(MAPPING_VALUE_FILTER, filter);
2545 2565 mapConstructionItem.put(MAPPING_VALUE_NOT, not);
... ... @@ -2899,6 +2919,9 @@ public abstract class MtasBasicParser extends MtasParser {
2899 2919 /** The object attributes. */
2900 2920 protected HashMap<String, String> objectAttributes = null;
2901 2921  
  2922 + /** The other object attributes. */
  2923 + protected HashMap<String, HashMap<String, String>> objectOtherAttributes = null;
  2924 +
2902 2925 /** The object positions. */
2903 2926 private SortedSet<Integer> objectPositions = new TreeSet<>();
2904 2927  
... ... @@ -2940,6 +2963,7 @@ public abstract class MtasBasicParser extends MtasParser {
2940 2963 MtasParserObject(MtasParserType type) {
2941 2964 objectType = type;
2942 2965 objectAttributes = new HashMap<>();
  2966 + objectOtherAttributes = new HashMap<>();
2943 2967 }
2944 2968  
2945 2969 /**
... ... @@ -3051,6 +3075,22 @@ public abstract class MtasBasicParser extends MtasParser {
3051 3075 return null;
3052 3076 }
3053 3077 }
  3078 +
  3079 + public String getOtherAttribute(String other, String name) {
  3080 + if(other==null) {
  3081 + return getAttribute(name);
  3082 + } else {
  3083 + if(objectOtherAttributes.containsKey(other)) {
  3084 + if (name != null) {
  3085 + return objectOtherAttributes.get(other).get(name);
  3086 + } else {
  3087 + return null;
  3088 + }
  3089 + } else {
  3090 + return null;
  3091 + }
  3092 + }
  3093 + }
3054 3094  
3055 3095 /**
3056 3096 * Gets the id.
... ...
src/main/java/mtas/analysis/parser/MtasXMLParser.java
... ... @@ -39,7 +39,7 @@ abstract class MtasXMLParser extends MtasBasicParser {
39 39 /** The namespace URI. */
40 40 protected String namespaceURI = null;
41 41  
42   - /** The namespace UR I id. */
  42 + /** The namespace URI id. */
43 43 protected String namespaceURI_id = null;
44 44  
45 45 /** The root tag. */
... ... @@ -957,6 +957,17 @@ abstract class MtasXMLParser extends MtasBasicParser {
957 957 currentObject.objectAttributes.put(
958 958 streamReader.getAttributeLocalName(i),
959 959 streamReader.getAttributeValue(i));
  960 + } else {
  961 + HashMap<String, String> otherMap;
  962 + if(!currentObject.objectOtherAttributes.containsKey(attributeNamespaceURI)) {
  963 + otherMap = new HashMap<>();
  964 + currentObject.objectOtherAttributes.put(attributeNamespaceURI, otherMap);
  965 + } else {
  966 + otherMap = currentObject.objectOtherAttributes.get(attributeNamespaceURI);
  967 + }
  968 + otherMap.put(
  969 + streamReader.getAttributeLocalName(i),
  970 + streamReader.getAttributeValue(i));
960 971 }
961 972 }
962 973 }
... ...
src/site/markdown/indexing_formats_folia.md
... ... @@ -23,6 +23,7 @@ The [configuration file](indexing_configuration.html#configuration) defining the
23 23 * [groups](indexing_formats_folia.html#group) : containing one or multiple words
24 24 * [groupAnnotations](indexing_formats_folia.html#groupAnnotation) occurring within a group
25 25 * [relations](indexing_formats_folia.html#relation) : containing one or multiple references
  26 +* [relationAnnotations](indexing_formats_folia.html#relationAnnotation) : occuring within a relation
26 27 * [references](indexing_formats_folia.html#reference) : elements referring to (typically) words by id
27 28  
28 29 Inside the *mappings* part of the configuration file, all elements are defined that may be mapped onto the index structure : *words*, *wordAnnotations*, *groups*, *groupAnnotations* and *relations*. Outside the *mappings* part the references can be defined, since a reference itself will never be mapped directly onto the index structure.
... ... @@ -184,6 +185,27 @@ Elements containing one or multiple [references](index_formats_folia.html#refere
184 185 </mapping>
185 186 ```
186 187  
  188 +<a name="relationAnnotation"></a>**Relation annotations**
  189 +
  190 +Elements within a [relation](index_formats_folia.html#relation) can be defined as *relationAnnotation*.
  191 +
  192 +```xml
  193 +<mapping type="relationAnnotation" name="lang">
  194 + <token type="string" offset="false" realoffset="false" parent="false">
  195 + <pre>
  196 + <item type="name" />
  197 + </pre>
  198 + <post>
  199 + <item type="attribute" name="class" />
  200 + </post>
  201 + </token>
  202 + <condition>
  203 + <item type="attribute" name="href" />
  204 + </condition>
  205 +</mapping>
  206 +```
  207 +
  208 +
187 209 <a name="reference"></a>**References**
188 210  
189 211 Elements may be defined as *reference* to a word, for example *wref* elements referring in the *ref* attribute to the *id* of words.
... ...