MtasXMLParser.java.html 77.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasXMLParser.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> &gt; <a href="index.source.html" class="el_package">mtas.analysis.parser</a> &gt; <span class="el_source">MtasXMLParser.java</span></div><h1>MtasXMLParser.java</h1><pre class="source lang-java linenums">package mtas.analysis.parser;

import java.io.Reader;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import mtas.analysis.token.MtasToken;
import mtas.analysis.token.MtasTokenCollection;
import mtas.analysis.token.MtasTokenIdFactory;
import mtas.analysis.util.MtasConfigException;
import mtas.analysis.util.MtasParserException;
import mtas.analysis.util.MtasConfiguration;

/**
 * The Class MtasXMLParser.
 */
<span class="pc bpc" id="L34" title="1 of 2 branches missed.">abstract class MtasXMLParser extends MtasBasicParser {</span>

  /** The Constant log. */
<span class="fc" id="L37">  private static final Log log = LogFactory.getLog(MtasXMLParser.class);</span>

  /** The namespace URI. */
<span class="fc" id="L40">  protected String namespaceURI = null;</span>

  /** The namespace UR I id. */
<span class="fc" id="L43">  protected String namespaceURI_id = null;</span>

  /** The root tag. */
<span class="fc" id="L46">  protected String rootTag = null;</span>

  /** The content tag. */
<span class="fc" id="L49">  protected String contentTag = null;</span>

  /** The allow non content. */
<span class="fc" id="L52">  protected boolean allowNonContent = false;</span>

  /** The relation key map. */
<span class="fc" id="L55">  private Map&lt;String, SortedSet&lt;String&gt;&gt; relationKeyMap = new HashMap&lt;String, SortedSet&lt;String&gt;&gt;();</span>

  /** The q names. */
<span class="fc" id="L58">  private Map&lt;String, QName&gt; qNames = new HashMap&lt;String, QName&gt;();</span>

  /** The relation types. */
<span class="fc" id="L61">  private Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; relationTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt;();</span>

  /** The relation annotation types. */
<span class="fc" id="L64">  private Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; relationAnnotationTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt;();</span>

  /** The ref types. */
<span class="fc" id="L67">  private Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; refTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt;();</span>

  /** The group types. */
<span class="fc" id="L70">  private Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; groupTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt;();</span>

  /** The group annotation types. */
<span class="fc" id="L73">  private Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; groupAnnotationTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt;();</span>

  /** The word types. */
<span class="fc" id="L76">  private Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; wordTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt;();</span>

  /** The word annotation types. */
<span class="fc" id="L79">  private Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; wordAnnotationTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt;();</span>

  /** The variable types. */
<span class="fc" id="L82">  private Map&lt;QName, MtasParserType&lt;MtasParserVariable&gt;&gt; variableTypes = new HashMap&lt;QName, MtasParserType&lt;MtasParserVariable&gt;&gt;();</span>

  /** The xml variables. */
<span class="fc" id="L85">  private static String XML_VARIABLES = &quot;variables&quot;;</span>

  /** The xml variable. */
<span class="fc" id="L88">  private static String XML_VARIABLE = &quot;variable&quot;;</span>

  /** The xml variable name. */
<span class="fc" id="L91">  private static String XML_VARIABLE_NAME = &quot;name&quot;;</span>

  /** The xml variable value. */
<span class="fc" id="L94">  private static String XML_VARIABLE_VALUE = &quot;value&quot;;</span>

  /** The xml references. */
<span class="fc" id="L97">  private static String XML_REFERENCES = &quot;references&quot;;</span>

  /** The xml reference. */
<span class="fc" id="L100">  private static String XML_REFERENCE = &quot;reference&quot;;</span>

  /** The xml reference name. */
<span class="fc" id="L103">  private static String XML_REFERENCE_NAME = &quot;name&quot;;</span>

  /** The xml reference ref. */
<span class="fc" id="L106">  private static String XML_REFERENCE_REF = &quot;ref&quot;;</span>

  /** The xml mappings. */
<span class="fc" id="L109">  private static String XML_MAPPINGS = &quot;mappings&quot;;</span>

  /** The xml mapping. */
<span class="fc" id="L112">  private static String XML_MAPPING = &quot;mapping&quot;;</span>

  /** The xml mapping type. */
<span class="fc" id="L115">  private static String XML_MAPPING_TYPE = &quot;type&quot;;</span>

  /** The xml mapping name. */
<span class="fc" id="L118">  private static String XML_MAPPING_NAME = &quot;name&quot;;</span>

  /**
   * Instantiates a new mtas XML parser.
   *
   * @param config the config
   */
  public MtasXMLParser(MtasConfiguration config) {
<span class="fc" id="L126">    super(config);</span>
    try {
<span class="fc" id="L128">      initParser();</span>
      // System.out.print(printConfig());
<span class="nc" id="L130">    } catch (MtasConfigException e) {</span>
<span class="nc" id="L131">      log.error(e);</span>
<span class="fc" id="L132">    }</span>
<span class="fc" id="L133">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.analysis.parser.MtasParser#printConfig()
   */
  @Override
  public String printConfig() {
<span class="nc" id="L142">    StringBuilder text = new StringBuilder();</span>
<span class="nc" id="L143">    text.append(&quot;=== CONFIGURATION ===\n&quot;);</span>
<span class="nc" id="L144">    text.append(&quot;type: &quot; + variableTypes.size() + &quot; x variable\n&quot;);</span>
<span class="nc" id="L145">    text.append(printConfigVariableTypes(variableTypes));</span>
<span class="nc" id="L146">    text.append(&quot;type: &quot; + groupTypes.size() + &quot; x group\n&quot;);</span>
<span class="nc" id="L147">    text.append(printConfigMappingTypes(groupTypes));</span>
<span class="nc" id="L148">    text.append(&quot;type: &quot; + groupAnnotationTypes.size() + &quot; x groupAnnotation&quot;);</span>
<span class="nc" id="L149">    text.append(printConfigMappingTypes(groupAnnotationTypes));</span>
<span class="nc" id="L150">    text.append(&quot;type: &quot; + wordTypes.size() + &quot; x word\n&quot;);</span>
<span class="nc" id="L151">    text.append(printConfigMappingTypes(wordTypes));</span>
<span class="nc" id="L152">    text.append(&quot;type: &quot; + wordAnnotationTypes.size() + &quot; x wordAnnotation&quot;);</span>
<span class="nc" id="L153">    text.append(printConfigMappingTypes(wordAnnotationTypes));</span>
<span class="nc" id="L154">    text.append(&quot;type: &quot; + relationTypes.size() + &quot; x relation\n&quot;);</span>
<span class="nc" id="L155">    text.append(printConfigMappingTypes(relationTypes));</span>
<span class="nc" id="L156">    text.append(</span>
<span class="nc" id="L157">        &quot;type: &quot; + relationAnnotationTypes.size() + &quot; x relationAnnotation\n&quot;);</span>
<span class="nc" id="L158">    text.append(printConfigMappingTypes(relationAnnotationTypes));</span>
<span class="nc" id="L159">    text.append(&quot;type: &quot; + refTypes.size() + &quot; x references\n&quot;);</span>
<span class="nc" id="L160">    text.append(printConfigMappingTypes(refTypes));</span>
<span class="nc" id="L161">    text.append(&quot;=== CONFIGURATION ===\n&quot;);</span>
<span class="nc" id="L162">    return text.toString();</span>
  }

  /**
   * Prints the config mapping types.
   *
   * @param types the types
   * @return the string
   */
  private String printConfigMappingTypes(
      Map&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; types) {
<span class="nc" id="L173">    StringBuilder text = new StringBuilder();</span>
<span class="nc bnc" id="L174" title="All 2 branches missed.">    for (Entry&lt;QName, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; entry : types</span>
<span class="nc" id="L175">        .entrySet()) {</span>
<span class="nc" id="L176">      text.append(&quot;- &quot; + entry.getKey().getLocalPart() + &quot;: &quot;</span>
<span class="nc" id="L177">          + entry.getValue().items.size() + &quot; mapping(s)\n&quot;);</span>
<span class="nc bnc" id="L178" title="All 2 branches missed.">      for (int i = 0; i &lt; entry.getValue().items.size(); i++) {</span>
<span class="nc" id="L179">        text.append(&quot;\t&quot; + entry.getValue().items.get(i) + &quot;\n&quot;);</span>
      }
<span class="nc" id="L181">    }</span>
<span class="nc" id="L182">    return text.toString();</span>
  }

  /**
   * Prints the config variable types.
   *
   * @param types the types
   * @return the string
   */
  private String printConfigVariableTypes(
      Map&lt;QName, MtasParserType&lt;MtasParserVariable&gt;&gt; types) {
<span class="nc" id="L193">    StringBuilder text = new StringBuilder();</span>
<span class="nc bnc" id="L194" title="All 2 branches missed.">    for (Entry&lt;QName, MtasParserType&lt;MtasParserVariable&gt;&gt; entry : types</span>
<span class="nc" id="L195">        .entrySet()) {</span>
<span class="nc" id="L196">      text.append(&quot;- &quot; + entry.getKey().getLocalPart() + &quot;: &quot;</span>
<span class="nc" id="L197">          + entry.getValue().items.size() + &quot; variables(s)\n&quot;);</span>
<span class="nc bnc" id="L198" title="All 2 branches missed.">      for (int i = 0; i &lt; entry.getValue().items.size(); i++) {</span>
<span class="nc" id="L199">        text.append(&quot;\t&quot; + entry.getValue().items.get(i) + &quot;\n&quot;);</span>
      }
<span class="nc" id="L201">    }</span>
<span class="nc" id="L202">    return text.toString();</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see mtas.analysis.parser.MtasParser#initParser()
   */
  @Override
  protected void initParser() throws MtasConfigException {
<span class="fc" id="L212">    super.initParser();</span>
<span class="pc bpc" id="L213" title="1 of 2 branches missed.">    if (config != null) {</span>
      // find namespaceURI
<span class="fc bfc" id="L215" title="All 2 branches covered.">      for (int i = 0; i &lt; config.children.size(); i++) {</span>
<span class="fc" id="L216">        MtasConfiguration current = config.children.get(i);</span>
<span class="pc bpc" id="L217" title="1 of 2 branches missed.">        if (current.name.equals(&quot;namespaceURI&quot;)) {</span>
<span class="nc" id="L218">          namespaceURI = current.attributes.get(&quot;value&quot;);</span>
        }
      }
      // loop again
<span class="fc bfc" id="L222" title="All 2 branches covered.">      for (int i = 0; i &lt; config.children.size(); i++) {</span>
<span class="fc" id="L223">        MtasConfiguration current = config.children.get(i);</span>
<span class="pc bpc" id="L224" title="1 of 2 branches missed.">        if (current.name.equals(XML_VARIABLES)) {</span>
<span class="nc bnc" id="L225" title="All 2 branches missed.">          for (int j = 0; j &lt; current.children.size(); j++) {</span>
<span class="nc bnc" id="L226" title="All 2 branches missed.">            if (current.children.get(j).name.equals(XML_VARIABLE)) {</span>
<span class="nc" id="L227">              MtasConfiguration variable = current.children.get(j);</span>
<span class="nc" id="L228">              String nameVariable = variable.attributes.get(XML_VARIABLE_NAME);</span>
<span class="nc" id="L229">              String valueVariable = variable.attributes</span>
<span class="nc" id="L230">                  .get(XML_VARIABLE_VALUE);</span>
<span class="nc bnc" id="L231" title="All 4 branches missed.">              if ((nameVariable != null) &amp;&amp; (valueVariable != null)) {</span>
<span class="nc" id="L232">                MtasParserVariable v = new MtasParserVariable(nameVariable,</span>
                    valueVariable);
<span class="nc" id="L234">                v.processConfig(variable);</span>
<span class="nc" id="L235">                QName qn = getQName(nameVariable);</span>
<span class="nc bnc" id="L236" title="All 2 branches missed.">                if (variableTypes.containsKey(qn)) {</span>
<span class="nc" id="L237">                  variableTypes.get(qn).addItem(v);</span>
                } else {
<span class="nc" id="L239">                  MtasParserType&lt;MtasParserVariable&gt; t = new MtasParserType&lt;MtasParserVariable&gt;(</span>
                      nameVariable, valueVariable, false);
<span class="nc" id="L241">                  t.addItem(v);</span>
<span class="nc" id="L242">                  variableTypes.put(qn, t);</span>
                }
              }
            }
          }
<span class="fc bfc" id="L247" title="All 2 branches covered.">        } else if (current.name.equals(XML_REFERENCES)) {</span>
<span class="fc bfc" id="L248" title="All 2 branches covered.">          for (int j = 0; j &lt; current.children.size(); j++) {</span>
<span class="pc bpc" id="L249" title="1 of 2 branches missed.">            if (current.children.get(j).name.equals(XML_REFERENCE)) {</span>
<span class="fc" id="L250">              MtasConfiguration reference = current.children.get(j);</span>
<span class="fc" id="L251">              String name = reference.attributes.get(XML_REFERENCE_NAME);</span>
<span class="fc" id="L252">              String ref = reference.attributes.get(XML_REFERENCE_REF);</span>
<span class="pc bpc" id="L253" title="2 of 4 branches missed.">              if ((name != null) &amp;&amp; (ref != null)) {</span>
<span class="fc" id="L254">                MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;(</span>
                    MAPPING_TYPE_REF, name, false, ref);
<span class="fc" id="L256">                refTypes.put(getQName(t.getName()), t);</span>
              }
            }
          }
<span class="fc bfc" id="L260" title="All 2 branches covered.">        } else if (current.name.equals(XML_MAPPINGS)) {</span>
<span class="fc bfc" id="L261" title="All 2 branches covered.">          for (int j = 0; j &lt; current.children.size(); j++) {</span>
<span class="pc bpc" id="L262" title="1 of 2 branches missed.">            if (current.children.get(j).name.equals(XML_MAPPING)) {</span>
<span class="fc" id="L263">              MtasConfiguration mapping = current.children.get(j);</span>
<span class="fc" id="L264">              String typeMapping = mapping.attributes.get(XML_MAPPING_TYPE);</span>
<span class="fc" id="L265">              String nameMapping = mapping.attributes.get(XML_MAPPING_NAME);</span>
<span class="pc bpc" id="L266" title="2 of 4 branches missed.">              if ((typeMapping != null) &amp;&amp; (nameMapping != null)) {</span>
<span class="fc bfc" id="L267" title="All 2 branches covered.">                if (typeMapping.equals(MAPPING_TYPE_RELATION)) {</span>
<span class="fc" id="L268">                  MtasXMLParserMappingRelation m = new MtasXMLParserMappingRelation();</span>
<span class="fc" id="L269">                  m.processConfig(mapping);</span>
<span class="fc" id="L270">                  QName qn = getQName(nameMapping);</span>
<span class="pc bpc" id="L271" title="1 of 2 branches missed.">                  if (relationTypes.containsKey(qn)) {</span>
<span class="nc" id="L272">                    relationTypes.get(qn).addItem(m);</span>
                  } else {
<span class="fc" id="L274">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;(</span>
                        typeMapping, nameMapping, false);
<span class="fc" id="L276">                    t.addItem(m);</span>
<span class="fc" id="L277">                    relationTypes.put(qn, t);</span>
                  }
<span class="fc" id="L279">                } else if (typeMapping</span>
<span class="pc bpc" id="L280" title="1 of 2 branches missed.">                    .equals(MAPPING_TYPE_RELATION_ANNOTATION)) {</span>
<span class="nc" id="L281">                  MtasXMLParserMappingRelationAnnotation m = new MtasXMLParserMappingRelationAnnotation();</span>
<span class="nc" id="L282">                  m.processConfig(mapping);</span>
<span class="nc" id="L283">                  QName qn = getQName(nameMapping);</span>
<span class="nc bnc" id="L284" title="All 2 branches missed.">                  if (relationAnnotationTypes.containsKey(qn)) {</span>
<span class="nc" id="L285">                    relationAnnotationTypes.get(qn).addItem(m);</span>
                  } else {
<span class="nc" id="L287">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;(</span>
                        typeMapping, nameMapping, false);
<span class="nc" id="L289">                    t.addItem(m);</span>
<span class="nc" id="L290">                    relationAnnotationTypes.put(qn, t);</span>
                  }
<span class="pc bfc" id="L292" title="All 2 branches covered.">                } else if (typeMapping.equals(MAPPING_TYPE_WORD)) {</span>
<span class="fc" id="L293">                  MtasXMLParserMappingWord m = new MtasXMLParserMappingWord();</span>
<span class="fc" id="L294">                  m.processConfig(mapping);</span>
<span class="fc" id="L295">                  QName qn = getQName(nameMapping);</span>
<span class="fc bfc" id="L296" title="All 2 branches covered.">                  if (wordTypes.containsKey(qn)) {</span>
<span class="fc" id="L297">                    wordTypes.get(qn).addItem(m);</span>
                  } else {
<span class="fc" id="L299">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;(</span>
                        typeMapping, nameMapping, false);
<span class="fc" id="L301">                    t.addItem(m);</span>
<span class="fc" id="L302">                    wordTypes.put(qn, t);</span>
                  }
<span class="fc bfc" id="L304" title="All 2 branches covered.">                } else if (typeMapping.equals(MAPPING_TYPE_WORD_ANNOTATION)) {</span>
<span class="fc" id="L305">                  MtasXMLParserMappingWordAnnotation m = new MtasXMLParserMappingWordAnnotation();</span>
<span class="fc" id="L306">                  m.processConfig(mapping);</span>
<span class="fc" id="L307">                  QName qn = getQName(nameMapping);</span>
<span class="fc bfc" id="L308" title="All 2 branches covered.">                  if (wordAnnotationTypes.containsKey(qn)) {</span>
<span class="fc" id="L309">                    wordAnnotationTypes.get(qn).addItem(m);</span>
                  } else {
<span class="fc" id="L311">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;(</span>
                        typeMapping, nameMapping, false);
<span class="fc" id="L313">                    t.addItem(m);</span>
<span class="fc" id="L314">                    wordAnnotationTypes.put(qn, t);</span>
                  }
<span class="fc bfc" id="L316" title="All 2 branches covered.">                } else if (typeMapping.equals(MAPPING_TYPE_GROUP)) {</span>
<span class="fc" id="L317">                  MtasXMLParserMappingGroup m = new MtasXMLParserMappingGroup();</span>
<span class="fc" id="L318">                  m.processConfig(mapping);</span>
<span class="fc" id="L319">                  QName qn = getQName(nameMapping);</span>
<span class="pc bpc" id="L320" title="1 of 2 branches missed.">                  if (groupTypes.containsKey(qn)) {</span>
<span class="nc" id="L321">                    groupTypes.get(qn).addItem(m);</span>
                  } else {
<span class="fc" id="L323">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;(</span>
                        typeMapping, nameMapping, false);
<span class="fc" id="L325">                    t.addItem(m);</span>
<span class="fc" id="L326">                    groupTypes.put(qn, t);</span>
                  }
<span class="pc bpc" id="L328" title="1 of 2 branches missed.">                } else if (typeMapping.equals(MAPPING_TYPE_GROUP_ANNOTATION)) {</span>
<span class="fc" id="L329">                  MtasXMLParserMappingGroupAnnotation m = new MtasXMLParserMappingGroupAnnotation();</span>
<span class="fc" id="L330">                  m.processConfig(mapping);</span>
<span class="fc" id="L331">                  QName qn = getQName(nameMapping);</span>
<span class="pc bpc" id="L332" title="1 of 2 branches missed.">                  if (groupAnnotationTypes.containsKey(qn)) {</span>
<span class="nc" id="L333">                    groupAnnotationTypes.get(qn).addItem(m);</span>
                  } else {
<span class="fc" id="L335">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;(</span>
                        typeMapping, nameMapping, false);
<span class="fc" id="L337">                    t.addItem(m);</span>
<span class="fc" id="L338">                    groupAnnotationTypes.put(qn, t);</span>
                  }
<span class="fc" id="L340">                } else {</span>
<span class="nc" id="L341">                  throw new MtasConfigException(</span>
                      &quot;unknown mapping type &quot; + typeMapping);
                }
              }
            }
          }
        }
      }
    }
<span class="fc" id="L350">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.analysis.parser.MtasParser#createTokenCollection(java.io.Reader)
   */
  @Override
  public MtasTokenCollection createTokenCollection(Reader reader)
      throws MtasParserException, MtasConfigException {
<span class="pc bpc" id="L360" title="1 of 2 branches missed.">    Boolean hasRoot = rootTag == null ? true : false;</span>
<span class="pc bpc" id="L361" title="1 of 2 branches missed.">    Boolean parsingContent = contentTag == null ? true : false;</span>
<span class="fc" id="L362">    String textContent = null;</span>
<span class="fc" id="L363">    Integer unknownAncestors = 0;</span>
<span class="fc" id="L364">    Integer lastOffset = 0;</span>

<span class="fc" id="L366">    AtomicInteger position = new AtomicInteger(0);</span>
<span class="fc" id="L367">    Map&lt;String, Set&lt;Integer&gt;&gt; idPositions = new HashMap&lt;&gt;();</span>
<span class="fc" id="L368">    Map&lt;String, Integer[]&gt; idOffsets = new HashMap&lt;&gt;();</span>

<span class="fc" id="L370">    Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList = createUpdateList();</span>
<span class="fc" id="L371">    Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList = createCurrentList();</span>
<span class="fc" id="L372">    Map&lt;String, Map&lt;String, String&gt;&gt; variables = createVariables();</span>

<span class="fc" id="L374">    tokenCollection = new MtasTokenCollection();</span>
<span class="fc" id="L375">    MtasTokenIdFactory mtasTokenIdFactory = new MtasTokenIdFactory();</span>
<span class="fc" id="L376">    XMLInputFactory factory = XMLInputFactory.newInstance();</span>
    try {
<span class="fc" id="L378">      XMLStreamReader streamReader = factory.createXMLStreamReader(reader);</span>
      QName qname;
      try {
<span class="fc" id="L381">        int event = streamReader.getEventType();</span>
        MtasParserType&lt;?&gt; currentType;
        MtasParserType&lt;?&gt; tmpCurrentType;
        MtasParserType&lt;?&gt; tmpVariableType;
<span class="fc" id="L385">        MtasParserObject currentObject = null;</span>
<span class="fc" id="L386">        MtasParserObject variableObject = null;</span>
        while (true) {
<span class="pc bpc" id="L388" title="1 of 7 branches missed.">          switch (event) {</span>
          case XMLStreamConstants.START_DOCUMENT:
<span class="fc" id="L390">            log.debug(&quot;start of document&quot;);</span>
<span class="fc" id="L391">            String encodingScheme = streamReader.getCharacterEncodingScheme();</span>
<span class="pc bpc" id="L392" title="1 of 2 branches missed.">            if (encodingScheme == null) {</span>
<span class="nc" id="L393">              throw new MtasParserException(&quot;No encodingScheme found&quot;);</span>
<span class="pc bpc" id="L394" title="1 of 2 branches missed.">            } else if (!encodingScheme.equalsIgnoreCase(&quot;utf-8&quot;)) {</span>
<span class="nc" id="L395">              throw new MtasParserException(</span>
                  &quot;XML not UTF-8 encoded but '&quot; + encodingScheme + &quot;'&quot;);
            }
            break;
          case XMLStreamConstants.END_DOCUMENT:
<span class="fc" id="L400">            log.debug(&quot;end of document&quot;);</span>
<span class="fc" id="L401">            break;</span>
          case XMLStreamConstants.SPACE:
            // set offset (end of start-element)
<span class="nc" id="L404">            lastOffset = streamReader.getLocation().getCharacterOffset();</span>
<span class="nc" id="L405">            break;</span>
          case XMLStreamConstants.START_ELEMENT:
            // get data
<span class="fc" id="L408">            qname = streamReader.getName();</span>
            // check for rootTag
<span class="fc bfc" id="L410" title="All 2 branches covered.">            if (!hasRoot) {</span>
<span class="pc bpc" id="L411" title="1 of 2 branches missed.">              if (qname.equals(getQName(rootTag))) {</span>
<span class="fc" id="L412">                hasRoot = true;</span>
              } else {
<span class="nc" id="L414">                throw new MtasParserException(&quot;No &quot; + rootTag);</span>
              }
              // parse content
            } else {
<span class="pc bpc" id="L418" title="1 of 2 branches missed.">              if ((tmpVariableType = variableTypes.get(qname)) != null) {</span>
<span class="nc" id="L419">                variableObject = new MtasParserObject(tmpVariableType);</span>
<span class="nc" id="L420">                collectAttributes(variableObject, streamReader);</span>
<span class="nc" id="L421">                computeVariablesFromObject(variableObject, currentList,</span>
                    variables);
              }
<span class="fc bfc" id="L424" title="All 2 branches covered.">              if (parsingContent) {</span>
                // check for relation : not within word, not within
                // groupAnnotation
<span class="fc bfc" id="L427" title="All 2 branches covered.">                if ((currentList.get(MAPPING_TYPE_WORD).isEmpty())</span>
<span class="fc" id="L428">                    &amp;&amp; (currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L429" title="1 of 2 branches missed.">                        .isEmpty())</span>
<span class="fc bfc" id="L430" title="All 2 branches covered.">                    &amp;&amp; (tmpCurrentType = relationTypes.get(qname)) != null) {</span>
<span class="fc" id="L431">                  currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="fc" id="L432">                  collectAttributes(currentObject, streamReader);</span>
<span class="fc" id="L433">                  currentObject.setUnknownAncestorNumber(unknownAncestors);</span>
<span class="fc" id="L434">                  currentObject.setRealOffsetStart(lastOffset);</span>
<span class="pc bpc" id="L435" title="1 of 2 branches missed.">                  if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L436">                    unknownAncestors++;</span>
                  } else {
<span class="fc" id="L438">                    currentType = tmpCurrentType;</span>
<span class="fc" id="L439">                    currentList.get(MAPPING_TYPE_RELATION).add(currentObject);</span>
<span class="fc" id="L440">                    unknownAncestors = 0;</span>
                  }
                  // check for relation annotation: not within word, but within
                  // relation
<span class="fc bfc" id="L444" title="All 2 branches covered.">                } else if ((currentList.get(MAPPING_TYPE_WORD).isEmpty())</span>
<span class="fc bfc" id="L445" title="All 2 branches covered.">                    &amp;&amp; (!currentList.get(MAPPING_TYPE_RELATION).isEmpty())</span>
                    &amp;&amp; (tmpCurrentType = relationAnnotationTypes
<span class="pc bpc" id="L447" title="1 of 2 branches missed.">                        .get(qname)) != null) {</span>
<span class="nc" id="L448">                  currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="nc" id="L449">                  collectAttributes(currentObject, streamReader);</span>
<span class="nc" id="L450">                  currentObject.setUnknownAncestorNumber(unknownAncestors);</span>
<span class="nc" id="L451">                  currentObject.setRealOffsetStart(lastOffset);</span>
<span class="nc bnc" id="L452" title="All 2 branches missed.">                  if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L453">                    unknownAncestors++;</span>
                  } else {
<span class="nc" id="L455">                    currentType = tmpCurrentType;</span>
<span class="nc" id="L456">                    currentList.get(MAPPING_TYPE_RELATION_ANNOTATION)</span>
<span class="nc" id="L457">                        .add(currentObject);</span>
<span class="nc" id="L458">                    unknownAncestors = 0;</span>
                  }
                  // check for group: not within word, not within relation, not
                  // within groupAnnotation
<span class="fc bfc" id="L462" title="All 2 branches covered.">                } else if ((currentList.get(MAPPING_TYPE_WORD).isEmpty())</span>
<span class="fc bfc" id="L463" title="All 2 branches covered.">                    &amp;&amp; (currentList.get(MAPPING_TYPE_RELATION).isEmpty())</span>
<span class="fc" id="L464">                    &amp;&amp; (currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L465" title="1 of 2 branches missed.">                        .isEmpty())</span>
<span class="fc bfc" id="L466" title="All 2 branches covered.">                    &amp;&amp; (tmpCurrentType = groupTypes.get(qname)) != null) {</span>
<span class="fc" id="L467">                  currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="fc" id="L468">                  collectAttributes(currentObject, streamReader);</span>
<span class="fc" id="L469">                  currentObject.setUnknownAncestorNumber(unknownAncestors);</span>
<span class="fc" id="L470">                  currentObject.setRealOffsetStart(lastOffset);</span>
<span class="pc bpc" id="L471" title="1 of 2 branches missed.">                  if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L472">                    unknownAncestors++;</span>
                  } else {
<span class="fc" id="L474">                    currentType = tmpCurrentType;</span>
<span class="fc" id="L475">                    currentList.get(MAPPING_TYPE_GROUP).add(currentObject);</span>
<span class="fc" id="L476">                    unknownAncestors = 0;</span>
                  }
                  // check for group annotation: not within word, not within
                  // relation, but within group
<span class="fc bfc" id="L480" title="All 2 branches covered.">                } else if ((currentList.get(MAPPING_TYPE_WORD).isEmpty())</span>
<span class="fc bfc" id="L481" title="All 2 branches covered.">                    &amp;&amp; (currentList.get(MAPPING_TYPE_RELATION).isEmpty())</span>
<span class="pc bpc" id="L482" title="1 of 2 branches missed.">                    &amp;&amp; (!currentList.get(MAPPING_TYPE_GROUP).isEmpty())</span>
                    &amp;&amp; (tmpCurrentType = groupAnnotationTypes
<span class="pc bpc" id="L484" title="1 of 2 branches missed.">                        .get(qname)) != null) {</span>
<span class="nc" id="L485">                  currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="nc" id="L486">                  collectAttributes(currentObject, streamReader);</span>
<span class="nc" id="L487">                  currentObject.setUnknownAncestorNumber(unknownAncestors);</span>
<span class="nc" id="L488">                  currentObject.setRealOffsetStart(lastOffset);</span>
<span class="nc bnc" id="L489" title="All 2 branches missed.">                  if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L490">                    unknownAncestors++;</span>
                  } else {
<span class="nc" id="L492">                    currentType = tmpCurrentType;</span>
<span class="nc" id="L493">                    currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="nc" id="L494">                        .add(currentObject);</span>
<span class="nc" id="L495">                    unknownAncestors = 0;</span>
                  }
                  // check for word: not within relation, not within
                  // groupAnnotation, not within word, not within wordAnnotation
<span class="fc bfc" id="L499" title="All 2 branches covered.">                } else if ((currentList.get(MAPPING_TYPE_RELATION).isEmpty())</span>
<span class="fc" id="L500">                    &amp;&amp; (currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L501" title="1 of 2 branches missed.">                        .isEmpty())</span>
<span class="fc bfc" id="L502" title="All 2 branches covered.">                    &amp;&amp; (currentList.get(MAPPING_TYPE_WORD).isEmpty())</span>
<span class="pc bpc" id="L503" title="1 of 2 branches missed.">                    &amp;&amp; (currentList.get(MAPPING_TYPE_WORD_ANNOTATION).isEmpty())</span>
<span class="fc bfc" id="L504" title="All 2 branches covered.">                    &amp;&amp; (tmpCurrentType = wordTypes.get(qname)) != null) {</span>
<span class="fc" id="L505">                  currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="fc" id="L506">                  collectAttributes(currentObject, streamReader);</span>
<span class="fc" id="L507">                  currentObject.setUnknownAncestorNumber(unknownAncestors);</span>
<span class="fc" id="L508">                  currentObject.setOffsetStart(lastOffset);</span>
<span class="fc" id="L509">                  currentObject.setRealOffsetStart(lastOffset);</span>
<span class="pc bpc" id="L510" title="1 of 2 branches missed.">                  if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L511">                    unknownAncestors++;</span>
                  } else {
<span class="fc" id="L513">                    currentType = tmpCurrentType;</span>
<span class="fc" id="L514">                    currentObject.addPosition(position.getAndIncrement());</span>
<span class="fc" id="L515">                    currentList.get(MAPPING_TYPE_WORD).add(currentObject);</span>
<span class="fc" id="L516">                    unknownAncestors = 0;</span>
                  }
                  // check for word annotation: not within relation, not within
                  // groupAnnotation, but within word
<span class="fc bfc" id="L520" title="All 2 branches covered.">                } else if ((currentList.get(MAPPING_TYPE_RELATION).size() == 0)</span>
<span class="fc" id="L521">                    &amp;&amp; (currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L522" title="1 of 2 branches missed.">                        .size() == 0)</span>
<span class="fc bfc" id="L523" title="All 2 branches covered.">                    &amp;&amp; (currentList.get(MAPPING_TYPE_WORD).size() &gt; 0)</span>
                    &amp;&amp; (tmpCurrentType = wordAnnotationTypes
<span class="fc bfc" id="L525" title="All 2 branches covered.">                        .get(qname)) != null) {</span>
<span class="fc" id="L526">                  currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="fc" id="L527">                  collectAttributes(currentObject, streamReader);</span>
<span class="fc" id="L528">                  currentObject.addPositions(currentList.get(MAPPING_TYPE_WORD)</span>
<span class="fc" id="L529">                      .get((currentList.get(MAPPING_TYPE_WORD).size() - 1))</span>
<span class="fc" id="L530">                      .getPositions());</span>
<span class="fc" id="L531">                  currentObject.setUnknownAncestorNumber(unknownAncestors);</span>
<span class="fc" id="L532">                  currentObject.setRealOffsetStart(lastOffset);</span>
<span class="fc bfc" id="L533" title="All 2 branches covered.">                  if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="fc" id="L534">                    unknownAncestors++;</span>
                  } else {
<span class="fc" id="L536">                    currentType = tmpCurrentType;</span>
<span class="fc" id="L537">                    currentList.get(MAPPING_TYPE_WORD_ANNOTATION)</span>
<span class="fc" id="L538">                        .add(currentObject);</span>
<span class="fc" id="L539">                    unknownAncestors = 0;</span>
                  }
                  // check for references: within relation
<span class="fc bfc" id="L542" title="All 2 branches covered.">                } else if (!currentList.get(MAPPING_TYPE_RELATION).isEmpty()</span>
<span class="pc bpc" id="L543" title="1 of 2 branches missed.">                    &amp;&amp; (tmpCurrentType = refTypes.get(qname)) != null) {</span>
<span class="fc" id="L544">                  currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="fc" id="L545">                  collectAttributes(currentObject, streamReader);</span>
<span class="fc" id="L546">                  currentObject.setUnknownAncestorNumber(unknownAncestors);</span>
<span class="fc" id="L547">                  currentObject.setRealOffsetStart(lastOffset);</span>
<span class="pc bpc" id="L548" title="1 of 2 branches missed.">                  if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L549">                    unknownAncestors++;</span>
                  } else {
<span class="fc" id="L551">                    currentType = tmpCurrentType;</span>
<span class="fc" id="L552">                    currentList.get(MAPPING_TYPE_REF).add(currentObject);</span>
<span class="fc" id="L553">                    unknownAncestors = 0;</span>
                    // add reference to ancestor relations
                    for (MtasParserObject currentRelation : currentList
<span class="fc bfc" id="L556" title="All 2 branches covered.">                        .get(MAPPING_TYPE_RELATION)) {</span>
<span class="fc" id="L557">                      currentRelation.addRefId(currentObject</span>
<span class="fc" id="L558">                          .getAttribute(currentType.getRefAttributeName()));</span>
                      // register mapping for relation (for recursive relations)
                      SortedSet&lt;String&gt; keyMapList;
<span class="fc bfc" id="L561" title="All 2 branches covered.">                      if (currentRelation.getId() != null) {</span>
<span class="fc" id="L562">                        if (relationKeyMap</span>
<span class="fc bfc" id="L563" title="All 2 branches covered.">                            .containsKey(currentRelation.getId())) {</span>
<span class="fc" id="L564">                          keyMapList = relationKeyMap</span>
<span class="fc" id="L565">                              .get(currentRelation.getId());</span>
                        } else {
<span class="fc" id="L567">                          keyMapList = new TreeSet&lt;&gt;();</span>
<span class="fc" id="L568">                          relationKeyMap.put(currentRelation.getId(),</span>
                              keyMapList);
                        }
<span class="fc" id="L571">                        keyMapList.add(currentObject</span>
<span class="fc" id="L572">                            .getAttribute(currentType.getRefAttributeName()));</span>
                      }
<span class="fc" id="L574">                    }</span>
                  }
                } else {
<span class="fc" id="L577">                  unknownAncestors++;</span>
                }
                // check for start content
<span class="fc bfc" id="L580" title="All 2 branches covered.">              } else if (qname.equals(getQName(contentTag))) {</span>
<span class="fc" id="L581">                parsingContent = true;</span>
                // unexpected
<span class="pc bpc" id="L583" title="1 of 2 branches missed.">              } else if (!allowNonContent) {</span>
<span class="nc" id="L584">                throw new MtasParserException(</span>
<span class="nc" id="L585">                    &quot;Unexpected &quot; + qname.getLocalPart() + &quot; in document&quot;);</span>
              }
            }
            // set offset (end of start-element)
<span class="fc" id="L589">            lastOffset = streamReader.getLocation().getCharacterOffset();</span>
<span class="fc" id="L590">            break;</span>
          case XMLStreamConstants.END_ELEMENT:
            // set offset (end of end-element)
<span class="fc" id="L593">            lastOffset = streamReader.getLocation().getCharacterOffset();</span>
            // get data
<span class="fc" id="L595">            qname = streamReader.getName();</span>
            // parse content
<span class="fc bfc" id="L597" title="All 2 branches covered.">            if (parsingContent) {</span>
<span class="fc bfc" id="L598" title="All 2 branches covered.">              if (unknownAncestors &gt; 0) {</span>
<span class="fc" id="L599">                unknownAncestors--;</span>
                // check for reference: because otherwise currentList should
                // contain no references
<span class="fc bfc" id="L602" title="All 2 branches covered.">              } else if (!currentList.get(MAPPING_TYPE_REF).isEmpty()) {</span>
<span class="pc bpc" id="L603" title="1 of 2 branches missed.">                if ((currentType = refTypes.get(qname)) != null) {</span>
<span class="fc" id="L604">                  currentObject = currentList.get(MAPPING_TYPE_REF)</span>
<span class="fc" id="L605">                      .remove(currentList.get(MAPPING_TYPE_REF).size() - 1);</span>
<span class="pc bpc" id="L606" title="1 of 2 branches missed.">                  assert currentObject.getType()</span>
<span class="pc bpc" id="L607" title="1 of 2 branches missed.">                      .equals(currentType) : &quot;object expected to be &quot;</span>
<span class="nc" id="L608">                          + currentObject.getType().getName() + &quot;, not &quot;</span>
<span class="nc" id="L609">                          + currentType.getName();</span>
<span class="pc bpc" id="L610" title="2 of 4 branches missed.">                  assert unknownAncestors == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L611">                      + currentObject.getType().getName();</span>
                  // ignore text and realOffset: not relevant
<span class="fc" id="L613">                  idPositions.put(currentObject.getId(),</span>
<span class="fc" id="L614">                      currentObject.getPositions());</span>
<span class="fc" id="L615">                  idOffsets.put(currentObject.getId(),</span>
<span class="fc" id="L616">                      currentObject.getOffset());</span>
<span class="fc" id="L617">                  currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="fc" id="L618">                  unknownAncestors = currentObject.getUnknownAncestorNumber();</span>
<span class="fc" id="L619">                  computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                      currentList, updateList);
                } else {
                  // this shouldn't happen
                }
                // check for wordAnnotation: because otherwise currentList
                // should contain no wordAnnotations
<span class="fc" id="L626">              } else if (!currentList.get(MAPPING_TYPE_WORD_ANNOTATION)</span>
<span class="fc bfc" id="L627" title="All 2 branches covered.">                  .isEmpty()) {</span>
<span class="pc bpc" id="L628" title="1 of 2 branches missed.">                if ((currentType = wordAnnotationTypes.get(qname)) != null) {</span>
<span class="fc" id="L629">                  currentObject = currentList.get(MAPPING_TYPE_WORD_ANNOTATION)</span>
<span class="fc" id="L630">                      .remove(</span>
<span class="fc" id="L631">                          currentList.get(MAPPING_TYPE_WORD_ANNOTATION).size()</span>
                              - 1);
<span class="pc bpc" id="L633" title="1 of 2 branches missed.">                  assert currentObject.getType()</span>
<span class="pc bpc" id="L634" title="1 of 2 branches missed.">                      .equals(currentType) : &quot;object expected to be &quot;</span>
<span class="nc" id="L635">                          + currentObject.getType().getName() + &quot;, not &quot;</span>
<span class="nc" id="L636">                          + currentType.getName();</span>
<span class="pc bpc" id="L637" title="2 of 4 branches missed.">                  assert unknownAncestors == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L638">                      + currentObject.getType().getName();</span>
<span class="fc" id="L639">                  currentObject.setRealOffsetEnd(lastOffset);</span>
<span class="fc" id="L640">                  idPositions.put(currentObject.getId(),</span>
<span class="fc" id="L641">                      currentObject.getPositions());</span>
<span class="fc" id="L642">                  idOffsets.put(currentObject.getId(),</span>
<span class="fc" id="L643">                      currentObject.getOffset());</span>
                  // offset always null, so update later with word (should be
                  // possible)
<span class="pc bpc" id="L646" title="1 of 2 branches missed.">                  if ((currentObject.getId() != null)</span>
<span class="nc bnc" id="L647" title="All 2 branches missed.">                      &amp;&amp; (!currentList.get(MAPPING_TYPE_WORD).isEmpty())) {</span>
<span class="nc" id="L648">                    currentList.get(MAPPING_TYPE_WORD)</span>
<span class="nc" id="L649">                        .get((currentList.get(MAPPING_TYPE_WORD).size() - 1))</span>
<span class="nc" id="L650">                        .addUpdateableIdWithOffset(currentObject.getId());</span>
                  }
<span class="fc" id="L652">                  currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="fc" id="L653">                  unknownAncestors = currentObject.getUnknownAncestorNumber();</span>
<span class="fc" id="L654">                  computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                      currentList, updateList);
                } else {
                  // this shouldn't happen
                }
                // check for word: because otherwise currentList should contain
                // no words
<span class="fc bfc" id="L661" title="All 2 branches covered.">              } else if (!currentList.get(MAPPING_TYPE_WORD).isEmpty()) {</span>
<span class="pc bpc" id="L662" title="1 of 2 branches missed.">                if ((currentType = wordTypes.get(qname)) != null) {</span>
<span class="fc" id="L663">                  currentObject = currentList.get(MAPPING_TYPE_WORD)</span>
<span class="fc" id="L664">                      .remove(currentList.get(MAPPING_TYPE_WORD).size() - 1);</span>
<span class="pc bpc" id="L665" title="1 of 2 branches missed.">                  assert currentObject.getType()</span>
<span class="pc bpc" id="L666" title="1 of 2 branches missed.">                      .equals(currentType) : &quot;object expected to be &quot;</span>
<span class="nc" id="L667">                          + currentObject.getType().getName() + &quot;, not &quot;</span>
<span class="nc" id="L668">                          + currentType.getName();</span>
<span class="pc bpc" id="L669" title="2 of 4 branches missed.">                  assert unknownAncestors == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L670">                      + currentObject.getType().getName();</span>
<span class="fc" id="L671">                  currentObject.setOffsetEnd(lastOffset);</span>
<span class="fc" id="L672">                  currentObject.setRealOffsetEnd(lastOffset);</span>
                  // update ancestor groups with position and offset
                  for (MtasParserObject currentGroup : currentList
<span class="fc bfc" id="L675" title="All 2 branches covered.">                      .get(MAPPING_TYPE_GROUP)) {</span>
<span class="fc" id="L676">                    currentGroup.addPositions(currentObject.getPositions());</span>
<span class="fc" id="L677">                    currentGroup.addOffsetStart(currentObject.getOffsetStart());</span>
<span class="fc" id="L678">                    currentGroup.addOffsetEnd(currentObject.getOffsetEnd());</span>
<span class="fc" id="L679">                  }</span>
<span class="fc" id="L680">                  idPositions.put(currentObject.getId(),</span>
<span class="fc" id="L681">                      currentObject.getPositions());</span>
<span class="fc" id="L682">                  idOffsets.put(currentObject.getId(),</span>
<span class="fc" id="L683">                      currentObject.getOffset());</span>
<span class="fc" id="L684">                  currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="fc" id="L685">                  unknownAncestors = currentObject.getUnknownAncestorNumber();</span>
<span class="fc" id="L686">                  computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                      currentList, updateList);
                } else {
                  // this shouldn't happen
                }
                // check for group annotation: because otherwise currentList
                // should contain no groupAnnotations
<span class="fc" id="L693">              } else if (!currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L694" title="1 of 2 branches missed.">                  .isEmpty()) {</span>
<span class="nc bnc" id="L695" title="All 2 branches missed.">                if ((currentType = groupAnnotationTypes.get(qname)) != null) {</span>
<span class="nc" id="L696">                  currentObject = currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="nc" id="L697">                      .remove(</span>
<span class="nc" id="L698">                          currentList.get(MAPPING_TYPE_GROUP_ANNOTATION).size()</span>
                              - 1);
<span class="nc bnc" id="L700" title="All 2 branches missed.">                  assert currentObject.getType()</span>
<span class="nc bnc" id="L701" title="All 2 branches missed.">                      .equals(currentType) : &quot;object expected to be &quot;</span>
<span class="nc" id="L702">                          + currentObject.getType().getName() + &quot;, not &quot;</span>
<span class="nc" id="L703">                          + currentType.getName();</span>
<span class="nc bnc" id="L704" title="All 4 branches missed.">                  assert unknownAncestors == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L705">                      + currentObject.getType().getName();</span>
<span class="nc" id="L706">                  currentObject.setRealOffsetEnd(lastOffset);</span>
<span class="nc" id="L707">                  idPositions.put(currentObject.getId(),</span>
<span class="nc" id="L708">                      currentObject.getPositions());</span>
<span class="nc" id="L709">                  idOffsets.put(currentObject.getId(),</span>
<span class="nc" id="L710">                      currentObject.getOffset());</span>
<span class="nc" id="L711">                  currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="nc" id="L712">                  unknownAncestors = currentObject.getUnknownAncestorNumber();</span>
<span class="nc" id="L713">                  computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                      currentList, updateList);
                } else {
                  // this shouldn't happen
                }
                // check for relation annotation
<span class="fc" id="L719">              } else if (!currentList.get(MAPPING_TYPE_RELATION_ANNOTATION)</span>
<span class="pc bpc" id="L720" title="1 of 2 branches missed.">                  .isEmpty()) {</span>
<span class="nc" id="L721">                if ((currentType = relationAnnotationTypes</span>
<span class="nc bnc" id="L722" title="All 2 branches missed.">                    .get(qname)) != null) {</span>
<span class="nc" id="L723">                  currentObject = currentList</span>
<span class="nc" id="L724">                      .get(MAPPING_TYPE_RELATION_ANNOTATION).remove(currentList</span>
<span class="nc" id="L725">                          .get(MAPPING_TYPE_RELATION_ANNOTATION).size() - 1);</span>
<span class="nc bnc" id="L726" title="All 2 branches missed.">                  assert currentObject.getType()</span>
<span class="nc bnc" id="L727" title="All 2 branches missed.">                      .equals(currentType) : &quot;object expected to be &quot;</span>
<span class="nc" id="L728">                          + currentObject.getType().getName() + &quot;, not &quot;</span>
<span class="nc" id="L729">                          + currentType.getName();</span>
<span class="nc bnc" id="L730" title="All 4 branches missed.">                  assert unknownAncestors == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L731">                      + currentObject.getType().getName();</span>
<span class="nc" id="L732">                  currentObject.setRealOffsetEnd(lastOffset);</span>
<span class="nc" id="L733">                  idPositions.put(currentObject.getId(),</span>
<span class="nc" id="L734">                      currentObject.getPositions());</span>
<span class="nc" id="L735">                  idOffsets.put(currentObject.getId(),</span>
<span class="nc" id="L736">                      currentObject.getOffset());</span>
<span class="nc" id="L737">                  currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="nc" id="L738">                  unknownAncestors = currentObject.getUnknownAncestorNumber();</span>
<span class="nc" id="L739">                  computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                      currentList, updateList);
                } else {
                  // this shouldn't happen
                }
                // check for relation
<span class="fc bfc" id="L745" title="All 2 branches covered.">              } else if (!currentList.get(MAPPING_TYPE_RELATION).isEmpty()) {</span>
<span class="pc bpc" id="L746" title="1 of 2 branches missed.">                if ((currentType = relationTypes.get(qname)) != null) {</span>
<span class="fc" id="L747">                  currentObject = currentList.get(MAPPING_TYPE_RELATION).remove(</span>
<span class="fc" id="L748">                      currentList.get(MAPPING_TYPE_RELATION).size() - 1);</span>
<span class="pc bpc" id="L749" title="1 of 2 branches missed.">                  assert currentObject.getType()</span>
<span class="pc bpc" id="L750" title="1 of 2 branches missed.">                      .equals(currentType) : &quot;object expected to be &quot;</span>
<span class="nc" id="L751">                          + currentObject.getType().getName() + &quot;, not &quot;</span>
<span class="nc" id="L752">                          + currentType.getName();</span>
<span class="pc bpc" id="L753" title="2 of 4 branches missed.">                  assert unknownAncestors == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L754">                      + currentObject.getType().getName();</span>
                  // ignore text: should not occur
<span class="fc" id="L756">                  currentObject.setRealOffsetEnd(lastOffset);</span>
<span class="fc" id="L757">                  idPositions.put(currentObject.getId(),</span>
<span class="fc" id="L758">                      currentObject.getPositions());</span>
<span class="fc" id="L759">                  idOffsets.put(currentObject.getId(),</span>
<span class="fc" id="L760">                      currentObject.getOffset());</span>
<span class="fc" id="L761">                  currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="fc" id="L762">                  unknownAncestors = currentObject.getUnknownAncestorNumber();</span>
<span class="fc" id="L763">                  computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                      currentList, updateList);
                } else {
                  // this shouldn't happen
                }
                // check for group
<span class="fc bfc" id="L769" title="All 2 branches covered.">              } else if (!currentList.get(MAPPING_TYPE_GROUP).isEmpty()) {</span>
<span class="pc bpc" id="L770" title="1 of 2 branches missed.">                if ((currentType = groupTypes.get(qname)) != null) {</span>
<span class="fc" id="L771">                  currentObject = currentList.get(MAPPING_TYPE_GROUP)</span>
<span class="fc" id="L772">                      .remove(currentList.get(MAPPING_TYPE_GROUP).size() - 1);</span>
<span class="pc bpc" id="L773" title="1 of 2 branches missed.">                  assert currentObject.getType()</span>
<span class="pc bpc" id="L774" title="1 of 2 branches missed.">                      .equals(currentType) : &quot;object expected to be &quot;</span>
<span class="nc" id="L775">                          + currentObject.getType().getName() + &quot;, not &quot;</span>
<span class="nc" id="L776">                          + currentType.getName();</span>
<span class="pc bpc" id="L777" title="2 of 4 branches missed.">                  assert unknownAncestors == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L778">                      + currentObject.getType().getName();</span>
                  // ignore text: should not occur
<span class="fc" id="L780">                  currentObject.setRealOffsetEnd(lastOffset);</span>
<span class="fc" id="L781">                  idPositions.put(currentObject.getId(),</span>
<span class="fc" id="L782">                      currentObject.getPositions());</span>
<span class="fc" id="L783">                  idOffsets.put(currentObject.getId(),</span>
<span class="fc" id="L784">                      currentObject.getOffset());</span>
<span class="fc" id="L785">                  currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="fc" id="L786">                  unknownAncestors = currentObject.getUnknownAncestorNumber();</span>
<span class="fc" id="L787">                  computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                      currentList, updateList);
                } else {
<span class="nc" id="L790">                  unknownAncestors--;</span>
                }
<span class="pc bpc" id="L792" title="1 of 2 branches missed.">              } else if (qname.equals(getQName(&quot;text&quot;))) {</span>
<span class="fc" id="L793">                parsingContent = false;</span>
<span class="pc bpc" id="L794" title="2 of 4 branches missed.">                assert unknownAncestors == 0 : &quot;error in administration unknownAncestors&quot;;</span>
<span class="pc bpc" id="L795" title="1 of 2 branches missed.">                assert currentList.get(MAPPING_TYPE_REF)</span>
<span class="pc bpc" id="L796" title="1 of 2 branches missed.">                    .isEmpty() : &quot;error in administration references&quot;;</span>
<span class="pc bpc" id="L797" title="1 of 2 branches missed.">                assert currentList.get(MAPPING_TYPE_GROUP)</span>
<span class="pc bpc" id="L798" title="1 of 2 branches missed.">                    .isEmpty() : &quot;error in administration groups&quot;;</span>
<span class="pc bpc" id="L799" title="1 of 2 branches missed.">                assert currentList.get(MAPPING_TYPE_GROUP_ANNOTATION)</span>
<span class="pc bpc" id="L800" title="1 of 2 branches missed.">                    .isEmpty() : &quot;error in administration groupAnnotations&quot;;</span>
<span class="pc bpc" id="L801" title="1 of 2 branches missed.">                assert currentList.get(MAPPING_TYPE_WORD)</span>
<span class="pc bpc" id="L802" title="1 of 2 branches missed.">                    .isEmpty() : &quot;error in administration words&quot;;</span>
<span class="pc bpc" id="L803" title="1 of 2 branches missed.">                assert currentList.get(MAPPING_TYPE_WORD_ANNOTATION)</span>
<span class="pc bpc" id="L804" title="1 of 2 branches missed.">                    .isEmpty() : &quot;error in administration wordAnnotations&quot;;</span>
<span class="pc bpc" id="L805" title="1 of 2 branches missed.">                assert currentList.get(MAPPING_TYPE_RELATION)</span>
<span class="pc bpc" id="L806" title="1 of 2 branches missed.">                    .isEmpty() : &quot;error in administration relations&quot;;</span>
<span class="pc bpc" id="L807" title="1 of 2 branches missed.">                assert currentList.get(MAPPING_TYPE_RELATION_ANNOTATION)</span>
<span class="pc bpc" id="L808" title="1 of 2 branches missed.">                    .isEmpty() : &quot;error in administration relationAnnotations&quot;;</span>
              }
            }
            // forget text
<span class="fc" id="L812">            textContent = null;</span>
<span class="fc" id="L813">            break;</span>
          case XMLStreamConstants.CHARACTERS:
            // set offset (end of start-element)
<span class="fc" id="L816">            lastOffset = streamReader.getLocation().getCharacterOffset();</span>
            // check for text
<span class="pc bpc" id="L818" title="1 of 2 branches missed.">            if (streamReader.hasText()) {</span>
<span class="fc" id="L819">              textContent = streamReader.getText();</span>
            }
<span class="fc bfc" id="L821" title="All 2 branches covered.">            if (currentObject != null) {</span>
<span class="fc" id="L822">              currentObject.addText(textContent);</span>
            }
            break;
          default:
            break;
          }
<span class="fc bfc" id="L828" title="All 2 branches covered.">          if (!streamReader.hasNext()) {</span>
<span class="fc" id="L829">            break;</span>
          }
<span class="fc" id="L831">          event = streamReader.next();</span>
        }
      } finally {
<span class="pc" id="L834">        streamReader.close();</span>
<span class="fc" id="L835">      }</span>
      // final checks
<span class="pc bpc" id="L837" title="2 of 4 branches missed.">      assert unknownAncestors == 0 : &quot;error in administration unknownAncestors&quot;;</span>
<span class="pc bpc" id="L838" title="2 of 4 branches missed.">      assert hasRoot : &quot;no &quot; + rootTag;</span>
<span class="nc" id="L839">    } catch (XMLStreamException e) {</span>
<span class="nc" id="L840">      log.debug(e);</span>
<span class="nc" id="L841">      throw new MtasParserException(&quot;No valid XML: &quot; + e.getMessage());</span>
<span class="fc" id="L842">    }</span>

    // update tokens with variable
    for (Entry&lt;Integer, Set&lt;String&gt;&gt; updateItem : updateList
<span class="pc bpc" id="L846" title="1 of 2 branches missed.">        .get(UPDATE_TYPE_VARIABLE).entrySet()) {</span>
<span class="nc" id="L847">      MtasToken token = tokenCollection.get(updateItem.getKey());</span>
<span class="nc" id="L848">      String encodedPrefix = token.getPrefix();</span>
<span class="nc" id="L849">      String encodedPostfix = token.getPostfix();</span>
<span class="nc" id="L850">      token.setValue(decodeAndUpdateWithVariables(encodedPrefix, encodedPostfix,</span>
          variables));
<span class="nc" id="L852">    }</span>
    // update tokens with offset
    for (Entry&lt;Integer, Set&lt;String&gt;&gt; updateItem : updateList
<span class="fc bfc" id="L855" title="All 2 branches covered.">        .get(UPDATE_TYPE_OFFSET).entrySet()) {</span>
<span class="fc" id="L856">      Set&lt;String&gt; refIdList = new HashSet&lt;&gt;();</span>
<span class="fc bfc" id="L857" title="All 2 branches covered.">      for (String refId : updateItem.getValue()) {</span>
<span class="pc bpc" id="L858" title="1 of 2 branches missed.">        if (idPositions.containsKey(refId)) {</span>
<span class="fc" id="L859">          refIdList.add(refId);</span>
        }
<span class="pc bpc" id="L861" title="1 of 2 branches missed.">        if (relationKeyMap.containsKey(refId)) {</span>
<span class="nc" id="L862">          refIdList.addAll(recursiveCollect(refId, relationKeyMap, 10));</span>
        }
<span class="fc" id="L864">      }</span>
<span class="fc bfc" id="L865" title="All 2 branches covered.">      for (String refId : refIdList) {</span>
<span class="fc" id="L866">        Integer[] refOffset = idOffsets.get(refId);</span>
<span class="fc" id="L867">        Integer tokenId = updateItem.getKey();</span>
<span class="pc bpc" id="L868" title="2 of 4 branches missed.">        if (tokenId != null &amp;&amp; refOffset != null) {</span>
<span class="fc" id="L869">          MtasToken token = tokenCollection.get(tokenId);</span>
<span class="fc" id="L870">          token.addOffset(refOffset[0], refOffset[1]);</span>
        }
<span class="fc" id="L872">      }</span>
<span class="fc" id="L873">    }</span>
    // update tokens with position
    for (Entry&lt;Integer, Set&lt;String&gt;&gt; updateItem : updateList
<span class="fc bfc" id="L876" title="All 2 branches covered.">        .get(UPDATE_TYPE_POSITION).entrySet()) {</span>
<span class="fc" id="L877">      HashSet&lt;String&gt; refIdList = new HashSet&lt;&gt;();</span>
<span class="fc bfc" id="L878" title="All 2 branches covered.">      for (String refId : updateItem.getValue()) {</span>
<span class="pc bpc" id="L879" title="1 of 2 branches missed.">        if (idPositions.containsKey(refId)) {</span>
<span class="fc" id="L880">          refIdList.add(refId);</span>
        }
<span class="pc bpc" id="L882" title="1 of 2 branches missed.">        if (relationKeyMap.containsKey(refId)) {</span>
<span class="nc" id="L883">          refIdList.addAll(recursiveCollect(refId, relationKeyMap, 10));</span>
        }
<span class="fc" id="L885">      }</span>
<span class="fc bfc" id="L886" title="All 2 branches covered.">      for (String refId : refIdList) {</span>
<span class="fc" id="L887">        Set&lt;Integer&gt; refPositions = idPositions.get(refId);</span>
<span class="fc" id="L888">        Integer tokenId = updateItem.getKey();</span>
<span class="pc bpc" id="L889" title="2 of 4 branches missed.">        if (tokenId != null &amp;&amp; refPositions != null) {</span>
<span class="fc" id="L890">          MtasToken token = tokenCollection.get(tokenId);</span>
<span class="fc" id="L891">          token.addPositions(refPositions);</span>
        }
<span class="fc" id="L893">      }</span>
<span class="fc" id="L894">    }</span>
    // final check
<span class="fc" id="L896">    tokenCollection.check(autorepair, makeunique);</span>
<span class="fc" id="L897">    return tokenCollection;</span>
  }

  /**
   * Recursive collect.
   *
   * @param refId the ref id
   * @param relationKeyMap the relation key map
   * @param maxRecursion the max recursion
   * @return the collection&lt;? extends string&gt;
   */
  private Collection&lt;? extends String&gt; recursiveCollect(String refId,
      Map&lt;String, SortedSet&lt;String&gt;&gt; relationKeyMap, int maxRecursion) {
<span class="nc" id="L910">    Set&lt;String&gt; list = new HashSet&lt;&gt;();</span>
<span class="nc bnc" id="L911" title="All 4 branches missed.">    if (maxRecursion &gt; 0 &amp;&amp; relationKeyMap.containsKey(refId)) {</span>
<span class="nc" id="L912">      SortedSet&lt;String&gt; subList = relationKeyMap.get(refId);</span>
<span class="nc bnc" id="L913" title="All 2 branches missed.">      for (String subRefId : subList) {</span>
<span class="nc" id="L914">        list.add(subRefId);</span>
<span class="nc" id="L915">        list.addAll(</span>
<span class="nc" id="L916">            recursiveCollect(subRefId, relationKeyMap, maxRecursion - 1));</span>
<span class="nc" id="L917">      }</span>
    }
<span class="nc" id="L919">    return list;</span>
  }

  /**
   * Gets the q name.
   *
   * @param key the key
   * @return the q name
   */
  private QName getQName(String key) {
    QName qname;
<span class="fc bfc" id="L930" title="All 2 branches covered.">    if ((qname = qNames.get(key)) == null) {</span>
<span class="fc" id="L931">      qname = new QName(namespaceURI, key);</span>
<span class="fc" id="L932">      qNames.put(key, qname);</span>
    }
<span class="fc" id="L934">    return qname;</span>
  }

  /**
   * Collect attributes.
   *
   * @param currentObject the current object
   * @param streamReader the stream reader
   */
  public void collectAttributes(MtasParserObject currentObject,
      XMLStreamReader streamReader) {
    String attributeNamespaceURI;
<span class="fc" id="L946">    currentObject.objectAttributes.clear();</span>
<span class="fc" id="L947">    currentObject.objectId = streamReader.getAttributeValue(namespaceURI_id,</span>
        &quot;id&quot;);
<span class="fc bfc" id="L949" title="All 2 branches covered.">    for (int i = 0; i &lt; streamReader.getAttributeCount(); i++) {</span>
<span class="fc" id="L950">      attributeNamespaceURI = streamReader.getAttributeNamespace(i);</span>
<span class="pc bpc" id="L951" title="1 of 4 branches missed.">      if (attributeNamespaceURI == null || attributeNamespaceURI.equals(&quot;&quot;)) {</span>
<span class="fc" id="L952">        attributeNamespaceURI = streamReader.getNamespaceURI();</span>
      }
<span class="pc bpc" id="L954" title="1 of 4 branches missed.">      if (namespaceURI == null || attributeNamespaceURI.equals(namespaceURI)) {</span>
<span class="fc" id="L955">        currentObject.objectAttributes.put(</span>
<span class="fc" id="L956">            streamReader.getAttributeLocalName(i),</span>
<span class="fc" id="L957">            streamReader.getAttributeValue(i));</span>
      }
    }
<span class="fc" id="L960">  }</span>

  /**
   * The Class MtasXMLParserMappingRelation.
   */
  private class MtasXMLParserMappingRelation
      extends MtasParserMapping&lt;MtasXMLParserMappingRelation&gt; {

    /**
     * Instantiates a new mtas XML parser mapping relation.
     */
<span class="fc" id="L971">    public MtasXMLParserMappingRelation() {</span>
<span class="fc" id="L972">      super();</span>
<span class="fc" id="L973">      this.position = SOURCE_REFS;</span>
<span class="fc" id="L974">      this.realOffset = SOURCE_OWN;</span>
<span class="fc" id="L975">      this.offset = SOURCE_REFS;</span>
<span class="fc" id="L976">      this.type = MAPPING_TYPE_RELATION;</span>
<span class="fc" id="L977">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see mtas.analysis.parser.MtasBasicParser.MtasParserMapping#self()
     */
    @Override
    protected MtasXMLParserMappingRelation self() {
<span class="nc" id="L986">      return this;</span>
    }
  }

  /**
   * The Class MtasXMLParserMappingRelationAnnotation.
   */
  private class MtasXMLParserMappingRelationAnnotation
      extends MtasParserMapping&lt;MtasXMLParserMappingRelationAnnotation&gt; {

    /**
     * Instantiates a new mtas XML parser mapping relation annotation.
     */
<span class="nc" id="L999">    public MtasXMLParserMappingRelationAnnotation() {</span>
<span class="nc" id="L1000">      super();</span>
<span class="nc" id="L1001">      this.position = SOURCE_ANCESTOR_RELATION;</span>
<span class="nc" id="L1002">      this.realOffset = SOURCE_OWN;</span>
<span class="nc" id="L1003">      this.offset = SOURCE_ANCESTOR_RELATION;</span>
<span class="nc" id="L1004">      this.type = MAPPING_TYPE_RELATION_ANNOTATION;</span>
<span class="nc" id="L1005">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see mtas.analysis.parser.MtasBasicParser.MtasParserMapping#self()
     */
    @Override
    protected MtasXMLParserMappingRelationAnnotation self() {
<span class="nc" id="L1014">      return this;</span>
    }

  }

  /**
   * The Class MtasXMLParserMappingGroup.
   */
  private class MtasXMLParserMappingGroup
      extends MtasParserMapping&lt;MtasXMLParserMappingGroup&gt; {

    /**
     * Instantiates a new mtas XML parser mapping group.
     */
<span class="fc" id="L1028">    public MtasXMLParserMappingGroup() {</span>
<span class="fc" id="L1029">      super();</span>
<span class="fc" id="L1030">      this.position = SOURCE_OWN;</span>
<span class="fc" id="L1031">      this.realOffset = SOURCE_OWN;</span>
<span class="fc" id="L1032">      this.offset = SOURCE_OWN;</span>
<span class="fc" id="L1033">      this.type = MAPPING_TYPE_GROUP;</span>
<span class="fc" id="L1034">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see mtas.analysis.parser.MtasBasicParser.MtasParserMapping#self()
     */
    @Override
    protected MtasXMLParserMappingGroup self() {
<span class="nc" id="L1043">      return this;</span>
    }
  }

  /**
   * The Class MtasXMLParserMappingGroupAnnotation.
   */
  private class MtasXMLParserMappingGroupAnnotation
      extends MtasParserMapping&lt;MtasXMLParserMappingGroupAnnotation&gt; {

    /**
     * Instantiates a new mtas XML parser mapping group annotation.
     */
<span class="fc" id="L1056">    public MtasXMLParserMappingGroupAnnotation() {</span>
<span class="fc" id="L1057">      super();</span>
<span class="fc" id="L1058">      this.position = SOURCE_ANCESTOR_GROUP;</span>
<span class="fc" id="L1059">      this.realOffset = SOURCE_OWN;</span>
<span class="fc" id="L1060">      this.offset = SOURCE_ANCESTOR_GROUP;</span>
<span class="fc" id="L1061">      this.type = MAPPING_TYPE_GROUP_ANNOTATION;</span>
<span class="fc" id="L1062">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see mtas.analysis.parser.MtasBasicParser.MtasParserMapping#self()
     */
    @Override
    protected MtasXMLParserMappingGroupAnnotation self() {
<span class="nc" id="L1071">      return this;</span>
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * mtas.analysis.parser.MtasBasicParser.MtasParserMapping#setStartEnd(java.
     * lang.String, java.lang.String)
     */
    @Override
    protected void setStartEnd(String start, String end) {
<span class="fc" id="L1083">      super.setStartEnd(start, end);</span>
<span class="pc bpc" id="L1084" title="3 of 4 branches missed.">      if (start != null &amp;&amp; end != null) {</span>
<span class="nc" id="L1085">        position = SOURCE_REFS;</span>
<span class="nc" id="L1086">        offset = SOURCE_REFS;</span>
      }
<span class="fc" id="L1088">    }</span>

  }

  /**
   * The Class MtasXMLParserMappingWord.
   */
  private class MtasXMLParserMappingWord
      extends MtasParserMapping&lt;MtasXMLParserMappingWord&gt; {

    /**
     * Instantiates a new mtas XML parser mapping word.
     */
<span class="fc" id="L1101">    public MtasXMLParserMappingWord() {</span>
<span class="fc" id="L1102">      super();</span>
<span class="fc" id="L1103">      this.position = SOURCE_OWN;</span>
<span class="fc" id="L1104">      this.realOffset = SOURCE_OWN;</span>
<span class="fc" id="L1105">      this.offset = SOURCE_OWN;</span>
<span class="fc" id="L1106">      this.type = MAPPING_TYPE_WORD;</span>
<span class="fc" id="L1107">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see mtas.analysis.parser.MtasBasicParser.MtasParserMapping#self()
     */
    @Override
    protected MtasXMLParserMappingWord self() {
<span class="nc" id="L1116">      return this;</span>
    }
  }

  /**
   * The Class MtasXMLParserMappingWordAnnotation.
   */
  private class MtasXMLParserMappingWordAnnotation
      extends MtasParserMapping&lt;MtasXMLParserMappingWordAnnotation&gt; {

    /**
     * Instantiates a new mtas XML parser mapping word annotation.
     */
<span class="fc" id="L1129">    public MtasXMLParserMappingWordAnnotation() {</span>
<span class="fc" id="L1130">      super();</span>
<span class="fc" id="L1131">      this.position = SOURCE_OWN;</span>
<span class="fc" id="L1132">      this.realOffset = SOURCE_OWN;</span>
<span class="fc" id="L1133">      this.offset = SOURCE_ANCESTOR_WORD;</span>
<span class="fc" id="L1134">      this.type = MAPPING_TYPE_WORD_ANNOTATION;</span>
<span class="fc" id="L1135">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see mtas.analysis.parser.MtasBasicParser.MtasParserMapping#self()
     */
    @Override
    protected MtasXMLParserMappingWordAnnotation self() {
<span class="nc" id="L1144">      return this;</span>
    }
  }

}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>