MtasCRMParser.java.html 57.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
<?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>MtasCRMParser.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">MtasCRMParser.java</span></div><h1>MtasCRMParser.java</h1><pre class="source lang-java linenums">package mtas.analysis.parser;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
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.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

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

/**
 * The Class MtasCRMParser.
 */

<span class="nc bnc" id="L32" title="All 2 branches missed.">public class MtasCRMParser extends MtasBasicParser {</span>

  /** The Constant log. */
<span class="nc" id="L35">  private static final Log log = LogFactory.getLog(MtasCRMParser.class);</span>

  /** The word type. */
<span class="nc" id="L38">  private MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; wordType = null;</span>

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

  /** The crm sentence types. */
<span class="nc" id="L44">  private HashMap&lt;String, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; crmSentenceTypes = new HashMap&lt;&gt;();</span>

  /** The crm clause types. */
<span class="nc" id="L47">  private HashMap&lt;String, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; crmClauseTypes = new HashMap&lt;&gt;();</span>

  /** The crm pair types. */
<span class="nc" id="L50">  private HashMap&lt;String, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; crmPairTypes = new HashMap&lt;&gt;();</span>

  /** The functions. */
<span class="nc" id="L53">  private HashMap&lt;String, HashMap&lt;String, MtasCRMParserFunction&gt;&gt; functions = new HashMap&lt;&gt;();</span>

  /** The Constant MAPPING_TYPE_CRM_SENTENCE. */
  protected static final String MAPPING_TYPE_CRM_SENTENCE = &quot;crmSentence&quot;;

  /** The Constant MAPPING_TYPE_CRM_CLAUSE. */
  protected static final String MAPPING_TYPE_CRM_CLAUSE = &quot;crmClause&quot;;

  /** The Constant MAPPING_TYPE_CRM_PAIR. */
  protected static final String MAPPING_TYPE_CRM_PAIR = &quot;crmPair&quot;;

  /** The history pair. */
<span class="nc" id="L65">  private HashMap&lt;String, HashMap&lt;String, MtasParserObject&gt;&gt; historyPair = new HashMap&lt;&gt;();</span>

  /** The pair pattern. */
<span class="nc" id="L68">  Pattern pairPattern = Pattern.compile(&quot;^([b|e])([a-z])([0-9]+)$&quot;);</span>

  /**
   * Instantiates a new mtas CRM parser.
   *
   * @param config the config
   */
  public MtasCRMParser(MtasConfiguration config) {
<span class="nc" id="L76">    super(config);</span>
    try {
<span class="nc" id="L78">      initParser();</span>
      // System.out.print(printConfig());
<span class="nc" id="L80">    } catch (MtasConfigException e) {</span>
<span class="nc" id="L81">      log.error(e);</span>
<span class="nc" id="L82">    }</span>
<span class="nc" id="L83">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.analysis.parser.MtasParser#initParser()
   */
  @SuppressWarnings(&quot;unchecked&quot;)
  @Override
  protected void initParser() throws MtasConfigException {
<span class="nc" id="L93">    super.initParser();</span>
<span class="nc bnc" id="L94" title="All 2 branches missed.">    if (config != null) {</span>
      // always word, no mappings
<span class="nc" id="L96">      wordType = new MtasParserType&lt;&gt;(MAPPING_TYPE_WORD, null, false);</span>
<span class="nc bnc" id="L97" title="All 2 branches missed.">      for (int i = 0; i &lt; config.children.size(); i++) {</span>
<span class="nc" id="L98">        MtasConfiguration current = config.children.get(i);</span>
<span class="nc bnc" id="L99" title="All 2 branches missed.">        if (current.name.equals(&quot;mappings&quot;)) {</span>
<span class="nc bnc" id="L100" title="All 2 branches missed.">          for (int j = 0; j &lt; current.children.size(); j++) {</span>
<span class="nc bnc" id="L101" title="All 2 branches missed.">            if (current.children.get(j).name.equals(&quot;mapping&quot;)) {</span>
<span class="nc" id="L102">              MtasConfiguration mapping = current.children.get(j);</span>
<span class="nc" id="L103">              String typeMapping = mapping.attributes.get(&quot;type&quot;);</span>
<span class="nc" id="L104">              String nameMapping = mapping.attributes.get(&quot;name&quot;);</span>
<span class="nc bnc" id="L105" title="All 2 branches missed.">              if ((typeMapping != null)) {</span>
<span class="nc bnc" id="L106" title="All 2 branches missed.">                if (typeMapping.equals(MAPPING_TYPE_WORD)) {</span>
<span class="nc" id="L107">                  MtasCRMParserMappingWordAnnotation m = new MtasCRMParserMappingWordAnnotation();</span>
<span class="nc" id="L108">                  m.processConfig(mapping);</span>
<span class="nc" id="L109">                  wordType.addItem(m);</span>
<span class="nc bnc" id="L110" title="All 4 branches missed.">                } else if (typeMapping.equals(MAPPING_TYPE_WORD_ANNOTATION)</span>
                    &amp;&amp; (nameMapping != null)) {
<span class="nc" id="L112">                  MtasCRMParserMappingWordAnnotation m = new MtasCRMParserMappingWordAnnotation();</span>
<span class="nc" id="L113">                  m.processConfig(mapping);</span>
<span class="nc bnc" id="L114" title="All 2 branches missed.">                  if (wordAnnotationTypes.containsKey(nameMapping)) {</span>
<span class="nc" id="L115">                    wordAnnotationTypes.get(nameMapping).addItem(m);</span>
                  } else {
<span class="nc" id="L117">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;&gt;(</span>
                        typeMapping, nameMapping, false);
<span class="nc" id="L119">                    t.addItem(m);</span>
<span class="nc" id="L120">                    wordAnnotationTypes.put(nameMapping, t);</span>
                  }
<span class="nc bnc" id="L122" title="All 2 branches missed.">                } else if (typeMapping.equals(MAPPING_TYPE_CRM_SENTENCE)) {</span>
<span class="nc" id="L123">                  MtasCRMParserMappingCRMSentence m = new MtasCRMParserMappingCRMSentence();</span>
<span class="nc" id="L124">                  m.processConfig(mapping);</span>
<span class="nc bnc" id="L125" title="All 2 branches missed.">                  if (crmSentenceTypes.containsKey(nameMapping)) {</span>
<span class="nc" id="L126">                    crmSentenceTypes.get(nameMapping).addItem(m);</span>
                  } else {
<span class="nc" id="L128">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;&gt;(</span>
                        MAPPING_TYPE_GROUP, nameMapping, true);
<span class="nc" id="L130">                    t.addItem(m);</span>
<span class="nc" id="L131">                    crmSentenceTypes.put(nameMapping, t);</span>
                  }
<span class="nc bnc" id="L133" title="All 2 branches missed.">                } else if (typeMapping.equals(MAPPING_TYPE_CRM_CLAUSE)) {</span>
<span class="nc" id="L134">                  MtasCRMParserMappingCRMSentence m = new MtasCRMParserMappingCRMSentence();</span>
<span class="nc" id="L135">                  m.processConfig(mapping);</span>
<span class="nc bnc" id="L136" title="All 2 branches missed.">                  if (crmClauseTypes.containsKey(nameMapping)) {</span>
<span class="nc" id="L137">                    crmClauseTypes.get(nameMapping).addItem(m);</span>
                  } else {
<span class="nc" id="L139">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;&gt;(</span>
                        MAPPING_TYPE_GROUP, nameMapping, true);
<span class="nc" id="L141">                    t.addItem(m);</span>
<span class="nc" id="L142">                    crmClauseTypes.put(nameMapping, t);</span>
                  }
<span class="nc bnc" id="L144" title="All 2 branches missed.">                } else if (typeMapping.equals(MAPPING_TYPE_CRM_PAIR)) {</span>
<span class="nc" id="L145">                  MtasCRMParserMappingCRMPair m = new MtasCRMParserMappingCRMPair();</span>
<span class="nc" id="L146">                  m.processConfig(mapping);</span>
<span class="nc bnc" id="L147" title="All 2 branches missed.">                  if (crmPairTypes.containsKey(nameMapping)) {</span>
<span class="nc" id="L148">                    crmPairTypes.get(nameMapping).addItem(m);</span>
                  } else {
<span class="nc" id="L150">                    MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt; t = new MtasParserType&lt;&gt;(</span>
                        MAPPING_TYPE_RELATION, nameMapping, true);
<span class="nc" id="L152">                    t.addItem(m);</span>
<span class="nc" id="L153">                    crmPairTypes.put(nameMapping, t);</span>
                  }
<span class="nc" id="L155">                } else {</span>
<span class="nc" id="L156">                  throw new MtasConfigException(&quot;unknown mapping type &quot;</span>
                      + typeMapping + &quot; or missing name&quot;);
                }
              }
            }
          }
<span class="nc bnc" id="L162" title="All 2 branches missed.">        } else if (current.name.equals(&quot;functions&quot;)) {</span>
<span class="nc bnc" id="L163" title="All 2 branches missed.">          for (int j = 0; j &lt; current.children.size(); j++) {</span>
<span class="nc bnc" id="L164" title="All 2 branches missed.">            if (current.children.get(j).name.equals(&quot;function&quot;)) {</span>
<span class="nc" id="L165">              MtasConfiguration function = current.children.get(j);</span>
<span class="nc" id="L166">              String nameFunction = function.attributes.get(&quot;name&quot;);</span>
<span class="nc" id="L167">              String typeFunction = function.attributes.get(&quot;type&quot;);</span>
<span class="nc" id="L168">              String splitFunction = function.attributes.get(&quot;split&quot;);</span>
<span class="nc bnc" id="L169" title="All 4 branches missed.">              if (nameFunction != null &amp;&amp; typeFunction != null) {</span>
<span class="nc" id="L170">                MtasCRMParserFunction mtasCRMParserFunction = new MtasCRMParserFunction(</span>
                    typeFunction, splitFunction);
<span class="nc bnc" id="L172" title="All 2 branches missed.">                if (!functions.containsKey(typeFunction)) {</span>
<span class="nc" id="L173">                  functions.put(typeFunction,</span>
                      new HashMap&lt;String, MtasCRMParserFunction&gt;());
                }
<span class="nc" id="L176">                functions.get(typeFunction).put(nameFunction,</span>
                    mtasCRMParserFunction);
<span class="nc" id="L178">                MtasConfiguration subCurrent = current.children.get(j);</span>
<span class="nc bnc" id="L179" title="All 2 branches missed.">                for (int k = 0; k &lt; subCurrent.children.size(); k++) {</span>
<span class="nc bnc" id="L180" title="All 2 branches missed.">                  if (subCurrent.children.get(k).name.equals(&quot;condition&quot;)) {</span>
<span class="nc" id="L181">                    MtasConfiguration subSubCurrent = subCurrent.children</span>
<span class="nc" id="L182">                        .get(k);</span>
<span class="nc bnc" id="L183" title="All 2 branches missed.">                    if (subSubCurrent.attributes.containsKey(&quot;value&quot;)) {</span>
<span class="nc" id="L184">                      String[] valuesCondition = subSubCurrent.attributes</span>
<span class="nc" id="L185">                          .get(&quot;value&quot;).split(Pattern.quote(&quot;,&quot;));</span>
<span class="nc" id="L186">                      ArrayList&lt;MtasCRMParserFunctionOutput&gt; valueOutputList = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L187" title="All 2 branches missed.">                      for (int l = 0; l &lt; subSubCurrent.children.size(); l++) {</span>
<span class="nc" id="L188">                        if (subSubCurrent.children.get(l).name</span>
<span class="nc bnc" id="L189" title="All 2 branches missed.">                            .equals(&quot;output&quot;)) {</span>
<span class="nc" id="L190">                          String valueOutput = subSubCurrent.children</span>
<span class="nc" id="L191">                              .get(l).attributes.get(&quot;value&quot;);</span>
<span class="nc" id="L192">                          String nameOutput = subSubCurrent.children</span>
<span class="nc" id="L193">                              .get(l).attributes.get(&quot;name&quot;);</span>
<span class="nc bnc" id="L194" title="All 2 branches missed.">                          if (nameOutput != null) {</span>
<span class="nc" id="L195">                            MtasCRMParserFunctionOutput o = new MtasCRMParserFunctionOutput(</span>
                                nameOutput, valueOutput);
<span class="nc" id="L197">                            valueOutputList.add(o);</span>
                          }
                        }
                      }
<span class="nc bnc" id="L201" title="All 2 branches missed.">                      if (!valueOutputList.isEmpty()) {</span>
<span class="nc bnc" id="L202" title="All 2 branches missed.">                        for (String valueCondition : valuesCondition) {</span>
<span class="nc" id="L203">                          if (mtasCRMParserFunction.output</span>
<span class="nc bnc" id="L204" title="All 2 branches missed.">                              .containsKey(valueCondition)) {</span>
<span class="nc" id="L205">                            mtasCRMParserFunction.output.get(valueCondition)</span>
<span class="nc" id="L206">                                .addAll(</span>
                                    (Collection&lt;? extends MtasCRMParserFunctionOutput&gt;) valueOutputList
<span class="nc" id="L208">                                        .clone());</span>
                          } else {
<span class="nc" id="L210">                            mtasCRMParserFunction.output.put(valueCondition,</span>
                                (ArrayList&lt;MtasCRMParserFunctionOutput&gt;) valueOutputList
<span class="nc" id="L212">                                    .clone());</span>
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
<span class="nc" id="L225">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.analysis.parser.MtasParser#createTokenCollection(java.io.Reader)
   */
  @Override
  public MtasTokenCollection createTokenCollection(Reader reader)
      throws MtasParserException, MtasConfigException {
<span class="nc" id="L235">    AtomicInteger position = new AtomicInteger(0);</span>
<span class="nc" id="L236">    MtasCRMAncestors unknownAncestors = new MtasCRMAncestors();</span>

<span class="nc" id="L238">    Map&lt;String, Set&lt;Integer&gt;&gt; idPositions = new HashMap&lt;&gt;();</span>
<span class="nc" id="L239">    Map&lt;String, Integer[]&gt; idOffsets = new HashMap&lt;&gt;();</span>

<span class="nc" id="L241">    Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList = createUpdateList();</span>
<span class="nc" id="L242">    Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList = createCurrentList();</span>

<span class="nc" id="L244">    tokenCollection = new MtasTokenCollection();</span>
<span class="nc" id="L245">    MtasTokenIdFactory mtasTokenIdFactory = new MtasTokenIdFactory();</span>
<span class="nc" id="L246">    try (MtasBufferedReader br = new MtasBufferedReader(reader)) {</span>
      String line;
      int currentOffset;
<span class="nc" id="L249">      int previousOffset = br.getPosition();</span>
      MtasParserObject currentObject;
<span class="nc" id="L251">      Pattern headerPattern = Pattern.compile(&quot;^@ @ @(.*)$&quot;);</span>
<span class="nc" id="L252">      Pattern regularPattern = Pattern.compile(</span>
          &quot;^([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)$&quot;);
      Matcher matcherHeader;
<span class="nc" id="L255">      Matcher matcherRegular = null;</span>
<span class="nc" id="L256">      Set&lt;MtasParserObject&gt; newPreviousSentence = new HashSet&lt;&gt;();</span>
<span class="nc" id="L257">      Set&lt;MtasParserObject&gt; previousSentence = new HashSet&lt;&gt;();</span>
<span class="nc" id="L258">      Set&lt;MtasParserObject&gt; newPreviousClause = new HashSet&lt;&gt;();</span>
<span class="nc" id="L259">      Set&lt;MtasParserObject&gt; previousClause = new HashSet&lt;&gt;();</span>
<span class="nc bnc" id="L260" title="All 2 branches missed.">      while ((line = br.readLine()) != null) {</span>
<span class="nc" id="L261">        currentOffset = br.getPosition();</span>
<span class="nc" id="L262">        matcherHeader = headerPattern.matcher(line.trim());</span>
<span class="nc" id="L263">        matcherRegular = regularPattern.matcher(line.trim());</span>
<span class="nc bnc" id="L264" title="All 2 branches missed.">        if (matcherRegular.matches()) {</span>
<span class="nc" id="L265">          newPreviousSentence.clear();</span>
<span class="nc bnc" id="L266" title="All 2 branches missed.">          for (int i = 4; i &lt; 8; i++) {</span>
<span class="nc" id="L267">            List&lt;MtasCRMParserFunctionOutput&gt; functionOutputList = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L268">            Set&lt;MtasParserObject&gt; tmpList = processCRMSentence(</span>
<span class="nc" id="L269">                mtasTokenIdFactory, String.valueOf(i),</span>
<span class="nc" id="L270">                matcherRegular.group((i + 1)), currentOffset,</span>
                functionOutputList, unknownAncestors, currentList, updateList,
                idPositions, idOffsets, previousSentence, previousClause);
<span class="nc bnc" id="L273" title="All 2 branches missed.">            if (tmpList != null) {</span>
<span class="nc" id="L274">              newPreviousSentence.addAll(tmpList);</span>
            }
<span class="nc bnc" id="L276" title="All 2 branches missed.">            for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {</span>
<span class="nc" id="L277">              tmpList = processCRMSentence(mtasTokenIdFactory,</span>
<span class="nc" id="L278">                  functionOutput.name, functionOutput.value, currentOffset,</span>
                  functionOutputList, unknownAncestors, currentList, updateList,
                  idPositions, idOffsets, previousSentence, previousClause);
<span class="nc bnc" id="L281" title="All 2 branches missed.">              if (tmpList != null) {</span>
<span class="nc" id="L282">                newPreviousSentence.addAll(tmpList);</span>
              }
<span class="nc" id="L284">            }</span>
          }
<span class="nc bnc" id="L286" title="All 2 branches missed.">          if (!newPreviousSentence.isEmpty()) {</span>
<span class="nc" id="L287">            previousSentence.clear();</span>
<span class="nc" id="L288">            previousSentence.addAll(newPreviousSentence);</span>
          }
<span class="nc" id="L290">          newPreviousClause.clear();</span>
<span class="nc bnc" id="L291" title="All 2 branches missed.">          for (int i = 4; i &lt; 8; i++) {</span>
<span class="nc" id="L292">            ArrayList&lt;MtasCRMParserFunctionOutput&gt; functionOutputList = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L293">            Set&lt;MtasParserObject&gt; tmpList = processCRMClause(mtasTokenIdFactory,</span>
<span class="nc" id="L294">                String.valueOf(i), matcherRegular.group((i + 1)), currentOffset,</span>
                functionOutputList, unknownAncestors, currentList, updateList,
                idPositions, idOffsets, previousClause);
<span class="nc bnc" id="L297" title="All 2 branches missed.">            if (tmpList != null) {</span>
<span class="nc" id="L298">              newPreviousClause.addAll(tmpList);</span>
            }
<span class="nc bnc" id="L300" title="All 2 branches missed.">            for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {</span>
<span class="nc" id="L301">              tmpList = processCRMClause(mtasTokenIdFactory,</span>
<span class="nc" id="L302">                  functionOutput.name, functionOutput.value, currentOffset,</span>
                  functionOutputList, unknownAncestors, currentList, updateList,
                  idPositions, idOffsets, previousClause);
<span class="nc bnc" id="L305" title="All 2 branches missed.">              if (tmpList != null) {</span>
<span class="nc" id="L306">                newPreviousClause.addAll(tmpList);</span>
              }
<span class="nc" id="L308">            }</span>
          }
<span class="nc bnc" id="L310" title="All 2 branches missed.">          if (!newPreviousClause.isEmpty()) {</span>
<span class="nc" id="L311">            previousClause.clear();</span>
<span class="nc" id="L312">            previousClause.addAll(newPreviousClause);</span>
          }
        }

<span class="nc bnc" id="L316" title="All 4 branches missed.">        if (matcherRegular.matches() &amp;&amp; !matcherHeader.matches()) {</span>
<span class="nc" id="L317">          matcherRegular = regularPattern.matcher(line.trim());</span>
<span class="nc bnc" id="L318" title="All 2 branches missed.">          if (matcherRegular.matches()) {</span>
            // regular line - start word
<span class="nc" id="L320">            currentObject = new MtasParserObject(wordType);</span>
<span class="nc" id="L321">            currentObject.setOffsetStart(previousOffset);</span>
<span class="nc" id="L322">            currentObject.setRealOffsetStart(previousOffset);</span>
<span class="nc" id="L323">            currentObject.setUnknownAncestorNumber(unknownAncestors.unknown);</span>
<span class="nc bnc" id="L324" title="All 2 branches missed.">            if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L325">              unknownAncestors.unknown++;</span>
            } else {
<span class="nc" id="L327">              int p = position.getAndIncrement();</span>
<span class="nc" id="L328">              currentObject.addPosition(p);</span>
<span class="nc" id="L329">              currentObject.objectId = &quot;word_&quot; + p;</span>
<span class="nc" id="L330">              currentList.get(MAPPING_TYPE_WORD).add(currentObject);</span>
<span class="nc" id="L331">              unknownAncestors.unknown = 0;</span>
              // check for crmPair
<span class="nc bnc" id="L333" title="All 2 branches missed.">              for (int i = 0; i &lt; 8; i++) {</span>
<span class="nc" id="L334">                List&lt;MtasCRMParserFunctionOutput&gt; functionOutputList = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L335">                processCRMPair(mtasTokenIdFactory, p, String.valueOf(i),</span>
<span class="nc" id="L336">                    matcherRegular.group((i + 1)), currentOffset,</span>
                    functionOutputList, unknownAncestors, currentList,
                    updateList, idPositions, idOffsets);
<span class="nc bnc" id="L339" title="All 2 branches missed.">                for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {</span>
<span class="nc" id="L340">                  processCRMPair(mtasTokenIdFactory, p, functionOutput.name,</span>
<span class="nc" id="L341">                      functionOutput.value, currentOffset, functionOutputList,</span>
                      unknownAncestors, currentList, updateList, idPositions,
                      idOffsets);
<span class="nc" id="L344">                }</span>
              }
              // compute word annotations
<span class="nc bnc" id="L347" title="All 2 branches missed.">              for (int i = 0; i &lt; 8; i++) {</span>
<span class="nc" id="L348">                ArrayList&lt;MtasCRMParserFunctionOutput&gt; functionOutputList = new ArrayList&lt;&gt;();</span>
<span class="nc" id="L349">                functionOutputList</span>
<span class="nc" id="L350">                    .addAll(processWordAnnotation(mtasTokenIdFactory,</span>
<span class="nc" id="L351">                        String.valueOf(i), matcherRegular.group((i + 1)),</span>
<span class="nc" id="L352">                        previousOffset, currentOffset, unknownAncestors,</span>
                        currentList, updateList, idPositions, idOffsets));
<span class="nc bnc" id="L354" title="All 2 branches missed.">                for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {</span>
<span class="nc" id="L355">                  processWordAnnotation(mtasTokenIdFactory, functionOutput.name,</span>
<span class="nc" id="L356">                      functionOutput.value, previousOffset, currentOffset,</span>
                      unknownAncestors, currentList, updateList, idPositions,
                      idOffsets);
<span class="nc" id="L359">                }</span>
              }
            }
            // finish word
<span class="nc bnc" id="L363" title="All 2 branches missed.">            if (unknownAncestors.unknown &gt; 0) {</span>
<span class="nc" id="L364">              unknownAncestors.unknown--;</span>
            } else {
<span class="nc" id="L366">              currentObject = currentList.get(MAPPING_TYPE_WORD)</span>
<span class="nc" id="L367">                  .remove(currentList.get(MAPPING_TYPE_WORD).size() - 1);</span>
<span class="nc bnc" id="L368" title="All 4 branches missed.">              assert unknownAncestors.unknown == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L369">                  + currentObject.getType().getName();</span>
<span class="nc" id="L370">              currentObject.setText(null);</span>
<span class="nc" id="L371">              currentObject.setOffsetEnd(currentOffset - 1);</span>
<span class="nc" id="L372">              currentObject.setRealOffsetEnd(currentOffset - 1);</span>
              // update ancestor groups with position and offset
              for (MtasParserObject currentGroup : currentList
<span class="nc bnc" id="L375" title="All 2 branches missed.">                  .get(MAPPING_TYPE_GROUP)) {</span>
<span class="nc" id="L376">                currentGroup.addPositions(currentObject.getPositions());</span>
<span class="nc" id="L377">                currentGroup.addOffsetStart(currentObject.getOffsetStart());</span>
<span class="nc" id="L378">                currentGroup.addOffsetEnd(currentObject.getOffsetEnd());</span>
<span class="nc" id="L379">              }</span>
<span class="nc" id="L380">              idPositions.put(currentObject.getId(),</span>
<span class="nc" id="L381">                  currentObject.getPositions());</span>
<span class="nc" id="L382">              idOffsets.put(currentObject.getId(), currentObject.getOffset());</span>
<span class="nc" id="L383">              currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="nc" id="L384">              unknownAncestors.unknown = currentObject</span>
<span class="nc" id="L385">                  .getUnknownAncestorNumber();</span>
<span class="nc" id="L386">              computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
                  currentList, updateList);
            }

          } else {
            // System.out.println(&quot;PROBLEM: &quot; + line);
          }
        }
<span class="nc" id="L394">        previousOffset = br.getPosition();</span>
      }
<span class="nc" id="L396">      closePrevious(mtasTokenIdFactory, previousSentence, previousOffset,</span>
          unknownAncestors, currentList, updateList, idPositions, idOffsets);
<span class="nc" id="L398">      closePrevious(mtasTokenIdFactory, previousClause, previousOffset,</span>
          unknownAncestors, currentList, updateList, idPositions, idOffsets);
<span class="nc bnc" id="L400" title="All 8 branches missed.">    } catch (IOException e) {</span>
<span class="nc" id="L401">      log.debug(e);</span>
<span class="nc" id="L402">      throw new MtasParserException(e.getMessage());</span>
<span class="nc" id="L403">    }</span>
    // final check
<span class="nc" id="L405">    tokenCollection.check(autorepair, makeunique);</span>
<span class="nc" id="L406">    return tokenCollection;</span>

  }

  /**
   * Process word annotation.
   *
   * @param mtasTokenIdFactory the mtas token id factory
   * @param name the name
   * @param text the text
   * @param previousOffset the previous offset
   * @param currentOffset the current offset
   * @param unknownAncestors the unknown ancestors
   * @param currentList the current list
   * @param updateList the update list
   * @param idPositions the id positions
   * @param idOffsets the id offsets
   * @return the list
   * @throws MtasParserException the mtas parser exception
   * @throws MtasConfigException the mtas config exception
   */
  private List&lt;MtasCRMParserFunctionOutput&gt; processWordAnnotation(
      MtasTokenIdFactory mtasTokenIdFactory, String name, String text,
      Integer previousOffset, Integer currentOffset,
      MtasCRMAncestors unknownAncestors,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList,
      Map&lt;String, Set&lt;Integer&gt;&gt; idPositions, Map&lt;String, Integer[]&gt; idOffsets)
      throws MtasParserException, MtasConfigException {
    MtasParserType tmpCurrentType;
    MtasParserObject currentObject;
<span class="nc" id="L437">    List&lt;MtasCRMParserFunctionOutput&gt; functionOutputList = new ArrayList&lt;&gt;();</span>
<span class="nc bnc" id="L438" title="All 2 branches missed.">    if ((tmpCurrentType = wordAnnotationTypes.get(name)) != null) {</span>
      // start word annotation
<span class="nc" id="L440">      currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="nc" id="L441">      currentObject.setRealOffsetStart(previousOffset);</span>
<span class="nc" id="L442">      currentObject.addPositions(currentList.get(MAPPING_TYPE_WORD)</span>
<span class="nc" id="L443">          .get((currentList.get(MAPPING_TYPE_WORD).size() - 1)).getPositions());</span>
<span class="nc" id="L444">      currentObject.setUnknownAncestorNumber(unknownAncestors.unknown);</span>
<span class="nc bnc" id="L445" title="All 2 branches missed.">      if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L446">        unknownAncestors.unknown++;</span>
      } else {
<span class="nc" id="L448">        currentList.get(MAPPING_TYPE_WORD_ANNOTATION).add(currentObject);</span>
<span class="nc" id="L449">        unknownAncestors.unknown = 0;</span>
      }
      // finish word annotation
<span class="nc bnc" id="L452" title="All 2 branches missed.">      if (unknownAncestors.unknown &gt; 0) {</span>
<span class="nc" id="L453">        unknownAncestors.unknown--;</span>
      } else {
<span class="nc" id="L455">        currentObject = currentList.get(MAPPING_TYPE_WORD_ANNOTATION)</span>
<span class="nc" id="L456">            .remove(currentList.get(MAPPING_TYPE_WORD_ANNOTATION).size() - 1);</span>
<span class="nc bnc" id="L457" title="All 4 branches missed.">        assert unknownAncestors.unknown == 0 : &quot;error in administration &quot;</span>
<span class="nc" id="L458">            + currentObject.getType().getName();</span>
<span class="nc bnc" id="L459" title="All 2 branches missed.">        if (functions.containsKey(MAPPING_TYPE_WORD_ANNOTATION)</span>
<span class="nc bnc" id="L460" title="All 4 branches missed.">            &amp;&amp; functions.get(MAPPING_TYPE_WORD_ANNOTATION).containsKey(name)</span>
            &amp;&amp; text != null) {
<span class="nc" id="L462">          MtasCRMParserFunction function = functions</span>
<span class="nc" id="L463">              .get(MAPPING_TYPE_WORD_ANNOTATION).get(name);</span>
          String[] value;
<span class="nc bnc" id="L465" title="All 2 branches missed.">          if (function.split != null) {</span>
<span class="nc" id="L466">            value = text.split(Pattern.quote(function.split));</span>
          } else {
<span class="nc" id="L468">            value = new String[] { text };</span>
          }
<span class="nc bnc" id="L470" title="All 2 branches missed.">          for (int c = 0; c &lt; value.length; c++) {</span>
<span class="nc bnc" id="L471" title="All 2 branches missed.">            if (function.output.containsKey(value[c])) {</span>
<span class="nc" id="L472">              functionOutputList.addAll(function.output.get(value[c]));</span>
            }
          }
        }
<span class="nc" id="L476">        currentObject.setText(text);</span>
<span class="nc" id="L477">        currentObject.setRealOffsetEnd(currentOffset - 1);</span>
<span class="nc" id="L478">        idPositions.put(currentObject.getId(), currentObject.getPositions());</span>
<span class="nc" id="L479">        idOffsets.put(currentObject.getId(), currentObject.getOffset());</span>
        // offset always null, so update later with word (should be possible)
<span class="nc bnc" id="L481" title="All 2 branches missed.">        if ((currentObject.getId() != null)</span>
<span class="nc bnc" id="L482" title="All 2 branches missed.">            &amp;&amp; (!currentList.get(MAPPING_TYPE_WORD).isEmpty())) {</span>
<span class="nc" id="L483">          currentList.get(MAPPING_TYPE_WORD)</span>
<span class="nc" id="L484">              .get((currentList.get(MAPPING_TYPE_WORD).size() - 1))</span>
<span class="nc" id="L485">              .addUpdateableIdWithOffset(currentObject.getId());</span>
        }
<span class="nc" id="L487">        currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="nc" id="L488">        unknownAncestors.unknown = currentObject.getUnknownAncestorNumber();</span>
<span class="nc" id="L489">        computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
            currentList, updateList);
      }
    }
<span class="nc" id="L493">    return functionOutputList;</span>
  }

  /**
   * Process CRM sentence.
   *
   * @param mtasTokenIdFactory the mtas token id factory
   * @param name the name
   * @param text the text
   * @param currentOffset the current offset
   * @param functionOutputList the function output list
   * @param unknownAncestors the unknown ancestors
   * @param currentList the current list
   * @param updateList the update list
   * @param idPositions the id positions
   * @param idOffsets the id offsets
   * @param previous the previous
   * @param previousClause the previous clause
   * @return the sets the
   * @throws MtasParserException the mtas parser exception
   * @throws MtasConfigException the mtas config exception
   */
  private Set&lt;MtasParserObject&gt; processCRMSentence(
      MtasTokenIdFactory mtasTokenIdFactory, String name, String text,
      Integer currentOffset,
      List&lt;MtasCRMParserFunctionOutput&gt; functionOutputList,
      MtasCRMAncestors unknownAncestors,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList,
      Map&lt;String, Set&lt;Integer&gt;&gt; idPositions, Map&lt;String, Integer[]&gt; idOffsets,
      Set&lt;MtasParserObject&gt; previous, Set&lt;MtasParserObject&gt; previousClause)
      throws MtasParserException, MtasConfigException {
    MtasParserType tmpCurrentType;
    MtasParserObject currentObject;
<span class="nc bnc" id="L527" title="All 2 branches missed.">    if ((tmpCurrentType = crmSentenceTypes.get(name)) != null) {</span>
<span class="nc" id="L528">      String filteredText = text.replaceAll(&quot;[^0-9\\-]&quot;, &quot;&quot;);</span>
<span class="nc" id="L529">      currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="nc" id="L530">      currentObject.setUnknownAncestorNumber(unknownAncestors.unknown);</span>
<span class="nc" id="L531">      currentObject.setRealOffsetStart(currentOffset);</span>
<span class="nc" id="L532">      currentObject.setText(filteredText);</span>
<span class="nc bnc" id="L533" title="All 2 branches missed.">      if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L534">        return new HashSet&lt;&gt;();</span>
      } else {
<span class="nc" id="L536">        closePrevious(mtasTokenIdFactory, previousClause, currentOffset,</span>
            unknownAncestors, currentList, updateList, idPositions, idOffsets);
<span class="nc" id="L538">        closePrevious(mtasTokenIdFactory, previous, currentOffset,</span>
            unknownAncestors, currentList, updateList, idPositions, idOffsets);
<span class="nc" id="L540">        previous.clear();</span>
<span class="nc" id="L541">        currentList.get(MAPPING_TYPE_GROUP).add(currentObject);</span>
<span class="nc" id="L542">        unknownAncestors.unknown = 0;</span>
<span class="nc" id="L543">        return new HashSet&lt;&gt;(Arrays.asList(currentObject));</span>
      }
    }
<span class="nc" id="L546">    return new HashSet&lt;&gt;();</span>
  }

  /**
   * Process CRM clause.
   *
   * @param mtasTokenIdFactory the mtas token id factory
   * @param name the name
   * @param text the text
   * @param currentOffset the current offset
   * @param functionOutputList the function output list
   * @param unknownAncestors the unknown ancestors
   * @param currentList the current list
   * @param updateList the update list
   * @param idPositions the id positions
   * @param idOffsets the id offsets
   * @param previous the previous
   * @return the sets the
   * @throws MtasParserException the mtas parser exception
   * @throws MtasConfigException the mtas config exception
   */
  private Set&lt;MtasParserObject&gt; processCRMClause(
      MtasTokenIdFactory mtasTokenIdFactory, String name, String text,
      Integer currentOffset,
      List&lt;MtasCRMParserFunctionOutput&gt; functionOutputList,
      MtasCRMAncestors unknownAncestors,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList,
      Map&lt;String, Set&lt;Integer&gt;&gt; idPositions, Map&lt;String, Integer[]&gt; idOffsets,
      Set&lt;MtasParserObject&gt; previous)
      throws MtasParserException, MtasConfigException {
    MtasParserType tmpCurrentType;
    MtasParserObject currentObject;
<span class="nc bnc" id="L579" title="All 2 branches missed.">    if ((tmpCurrentType = crmClauseTypes.get(name)) != null) {</span>
<span class="nc" id="L580">      String filteredText = text.replaceAll(&quot;[^0-9\\-]&quot;, &quot;&quot;);</span>
<span class="nc" id="L581">      currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="nc" id="L582">      currentObject.setUnknownAncestorNumber(unknownAncestors.unknown);</span>
<span class="nc" id="L583">      currentObject.setRealOffsetStart(currentOffset);</span>
<span class="nc" id="L584">      currentObject.setText(filteredText);</span>
<span class="nc bnc" id="L585" title="All 2 branches missed.">      if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L586">        return new HashSet&lt;&gt;();</span>
      } else {
<span class="nc" id="L588">        closePrevious(mtasTokenIdFactory, previous, currentOffset,</span>
            unknownAncestors, currentList, updateList, idPositions, idOffsets);
<span class="nc" id="L590">        previous.clear();</span>
<span class="nc" id="L591">        currentList.get(MAPPING_TYPE_GROUP).add(currentObject);</span>
<span class="nc" id="L592">        unknownAncestors.unknown = 0;</span>
<span class="nc" id="L593">        return new HashSet&lt;&gt;(Arrays.asList(currentObject));</span>
      }
    }
<span class="nc" id="L596">    return new HashSet&lt;&gt;();</span>
  }

  /**
   * Close previous.
   *
   * @param mtasTokenIdFactory the mtas token id factory
   * @param previous the previous
   * @param currentOffset the current offset
   * @param unknownAncestors the unknown ancestors
   * @param currentList the current list
   * @param updateList the update list
   * @param idPositions the id positions
   * @param idOffsets the id offsets
   * @throws MtasParserException the mtas parser exception
   * @throws MtasConfigException the mtas config exception
   */
  private void closePrevious(MtasTokenIdFactory mtasTokenIdFactory,
      Set&lt;MtasParserObject&gt; previous, Integer currentOffset,
      MtasCRMAncestors unknownAncestors,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList,
      Map&lt;String, Set&lt;Integer&gt;&gt; idPositions, Map&lt;String, Integer[]&gt; idOffsets)
      throws MtasParserException, MtasConfigException {
<span class="nc bnc" id="L620" title="All 2 branches missed.">    for (MtasParserObject previousObject : previous) {</span>
<span class="nc" id="L621">      previousObject.setRealOffsetEnd(currentOffset);</span>
<span class="nc" id="L622">      idPositions.put(previousObject.getId(), previousObject.getPositions());</span>
<span class="nc" id="L623">      idOffsets.put(previousObject.getId(), previousObject.getOffset());</span>
<span class="nc" id="L624">      previousObject.updateMappings(idPositions, idOffsets);</span>
<span class="nc" id="L625">      unknownAncestors.unknown = previousObject.getUnknownAncestorNumber();</span>
<span class="nc" id="L626">      computeMappingsFromObject(mtasTokenIdFactory, previousObject, currentList,</span>
          updateList);
<span class="nc" id="L628">      currentList.get(MAPPING_TYPE_GROUP).remove(previousObject);</span>
<span class="nc" id="L629">    }</span>
<span class="nc" id="L630">  }</span>

  /**
   * Process CRM pair.
   *
   * @param mtasTokenIdFactory the mtas token id factory
   * @param position the position
   * @param name the name
   * @param text the text
   * @param currentOffset the current offset
   * @param functionOutputList the function output list
   * @param unknownAncestors the unknown ancestors
   * @param currentList the current list
   * @param updateList the update list
   * @param idPositions the id positions
   * @param idOffsets the id offsets
   * @throws MtasParserException the mtas parser exception
   * @throws MtasConfigException the mtas config exception
   */
  private void processCRMPair(MtasTokenIdFactory mtasTokenIdFactory,
      int position, String name, String text, Integer currentOffset,
      List&lt;MtasCRMParserFunctionOutput&gt; functionOutputList,
      MtasCRMAncestors unknownAncestors,
      Map&lt;String, List&lt;MtasParserObject&gt;&gt; currentList,
      Map&lt;String, Map&lt;Integer, Set&lt;String&gt;&gt;&gt; updateList,
      Map&lt;String, Set&lt;Integer&gt;&gt; idPositions, Map&lt;String, Integer[]&gt; idOffsets)
      throws MtasParserException, MtasConfigException {

    MtasParserType tmpCurrentType;
    MtasParserObject currentObject;

<span class="nc bnc" id="L661" title="All 2 branches missed.">    if ((tmpCurrentType = crmPairTypes.get(name)) != null) {</span>
      // get history
      HashMap&lt;String, MtasParserObject&gt; currentNamePairHistory;
<span class="nc bnc" id="L664" title="All 2 branches missed.">      if (!historyPair.containsKey(name)) {</span>
<span class="nc" id="L665">        currentNamePairHistory = new HashMap&lt;&gt;();</span>
<span class="nc" id="L666">        historyPair.put(name, currentNamePairHistory);</span>
      } else {
<span class="nc" id="L668">        currentNamePairHistory = historyPair.get(name);</span>
      }
<span class="nc" id="L670">      Matcher m = pairPattern.matcher(text);</span>
<span class="nc bnc" id="L671" title="All 2 branches missed.">      if (m.find()) {</span>
<span class="nc" id="L672">        String thisKey = m.group(1) + m.group(2);</span>
<span class="nc bnc" id="L673" title="All 2 branches missed.">        String otherKey = (m.group(1).equals(&quot;b&quot;) ? &quot;e&quot; : &quot;b&quot;) + m.group(2);</span>
<span class="nc bnc" id="L674" title="All 2 branches missed.">        if (currentNamePairHistory.containsKey(otherKey)) {</span>
<span class="nc" id="L675">          currentObject = currentNamePairHistory.remove(otherKey);</span>
<span class="nc" id="L676">          currentObject.setText(currentObject.getText() + &quot;+&quot; + text);</span>
<span class="nc" id="L677">          currentObject.addPosition(position);</span>
<span class="nc" id="L678">          processFunctions(name, text, MAPPING_TYPE_CRM_PAIR,</span>
              functionOutputList);
<span class="nc" id="L680">          currentObject.setRealOffsetEnd(currentOffset + 1);</span>
<span class="nc" id="L681">          currentObject.setOffsetEnd(currentOffset + 1);</span>
<span class="nc" id="L682">          idPositions.put(currentObject.getId(), currentObject.getPositions());</span>
<span class="nc" id="L683">          idOffsets.put(currentObject.getId(), currentObject.getOffset());</span>
<span class="nc" id="L684">          currentObject.updateMappings(idPositions, idOffsets);</span>
<span class="nc" id="L685">          unknownAncestors.unknown = currentObject.getUnknownAncestorNumber();</span>
<span class="nc" id="L686">          computeMappingsFromObject(mtasTokenIdFactory, currentObject,</span>
              currentList, updateList);
        } else {
<span class="nc" id="L689">          currentObject = new MtasParserObject(tmpCurrentType);</span>
<span class="nc" id="L690">          currentObject.setUnknownAncestorNumber(unknownAncestors.unknown);</span>
<span class="nc" id="L691">          currentObject.setRealOffsetStart(currentOffset);</span>
<span class="nc" id="L692">          currentObject.setOffsetStart(currentOffset);</span>
<span class="nc" id="L693">          currentObject.setText(text);</span>
<span class="nc" id="L694">          currentObject.addPosition(position);</span>
<span class="nc bnc" id="L695" title="All 2 branches missed.">          if (!prevalidateObject(currentObject, currentList)) {</span>
<span class="nc" id="L696">            unknownAncestors.unknown++;</span>
          } else {
<span class="nc" id="L698">            currentNamePairHistory.put(thisKey, currentObject);</span>
<span class="nc" id="L699">            processFunctions(name, text, MAPPING_TYPE_CRM_PAIR,</span>
                functionOutputList);
<span class="nc" id="L701">            currentObject.setRealOffsetEnd(currentOffset + 1);</span>
<span class="nc" id="L702">            currentObject.setOffsetEnd(currentOffset + 1);</span>
<span class="nc" id="L703">            idPositions.put(currentObject.getId(),</span>
<span class="nc" id="L704">                currentObject.getPositions());</span>
<span class="nc" id="L705">            idOffsets.put(currentObject.getId(), currentObject.getOffset());</span>
            // offset always null, so update later with word (should be
            // possible)
<span class="nc bnc" id="L708" title="All 2 branches missed.">            if ((currentObject.getId() != null)</span>
<span class="nc bnc" id="L709" title="All 2 branches missed.">                &amp;&amp; (!currentList.get(MAPPING_TYPE_WORD).isEmpty())) {</span>
<span class="nc" id="L710">              currentList.get(MAPPING_TYPE_WORD)</span>
<span class="nc" id="L711">                  .get((currentList.get(MAPPING_TYPE_WORD).size() - 1))</span>
<span class="nc" id="L712">                  .addUpdateableIdWithOffset(currentObject.getId());</span>
            }

          }
        }
      }

    }

<span class="nc" id="L721">  }</span>

  /**
   * Process functions.
   *
   * @param name the name
   * @param text the text
   * @param type the type
   * @param functionOutputList the function output list
   */
  private void processFunctions(String name, String text, String type,
      List&lt;MtasCRMParserFunctionOutput&gt; functionOutputList) {
<span class="nc bnc" id="L733" title="All 6 branches missed.">    if (functions.containsKey(type) &amp;&amp; functions.get(type).containsKey(name)</span>
        &amp;&amp; text != null) {
<span class="nc" id="L735">      MtasCRMParserFunction function = functions.get(type).get(name);</span>
      String[] value;
<span class="nc bnc" id="L737" title="All 2 branches missed.">      if (function.split != null) {</span>
<span class="nc" id="L738">        value = text.split(Pattern.quote(function.split));</span>
      } else {
<span class="nc" id="L740">        value = new String[] { text };</span>
      }
<span class="nc bnc" id="L742" title="All 2 branches missed.">      for (int c = 0; c &lt; value.length; c++) {</span>
<span class="nc" id="L743">        boolean checkedEmpty = false;</span>
<span class="nc bnc" id="L744" title="All 2 branches missed.">        if (value[c].equals(&quot;&quot;)) {</span>
<span class="nc" id="L745">          checkedEmpty = true;</span>
        }
<span class="nc bnc" id="L747" title="All 2 branches missed.">        if (function.output.containsKey(value[c])) {</span>
<span class="nc" id="L748">          ArrayList&lt;MtasCRMParserFunctionOutput&gt; list = function.output</span>
<span class="nc" id="L749">              .get(value[c]);</span>
<span class="nc bnc" id="L750" title="All 2 branches missed.">          for (MtasCRMParserFunctionOutput listItem : list) {</span>
<span class="nc" id="L751">            functionOutputList.add(listItem.create(value[c]));</span>
<span class="nc" id="L752">          }</span>
        }
<span class="nc bnc" id="L754" title="All 4 branches missed.">        if (!checkedEmpty &amp;&amp; function.output.containsKey(&quot;&quot;)) {</span>
<span class="nc" id="L755">          ArrayList&lt;MtasCRMParserFunctionOutput&gt; list = function.output.get(&quot;&quot;);</span>
<span class="nc bnc" id="L756" title="All 2 branches missed.">          for (MtasCRMParserFunctionOutput listItem : list) {</span>
<span class="nc" id="L757">            functionOutputList.add(listItem.create(value[c]));</span>
<span class="nc" id="L758">          }</span>
        }
      }
    }
<span class="nc" id="L762">  }</span>

  /*
   * (non-Javadoc)
   * 
   * @see mtas.analysis.parser.MtasParser#printConfig()
   */
  @Override
  public String printConfig() {
<span class="nc" id="L771">    StringBuilder text = new StringBuilder();</span>
<span class="nc" id="L772">    text.append(&quot;=== CONFIGURATION ===\n&quot;);</span>
<span class="nc" id="L773">    text.append(&quot;type: &quot; + wordAnnotationTypes.size() + &quot; x wordAnnotation&quot;);</span>
<span class="nc" id="L774">    text.append(printConfigTypes(wordAnnotationTypes));</span>
<span class="nc" id="L775">    text.append(&quot;=== CONFIGURATION ===\n&quot;);</span>
<span class="nc" id="L776">    return text.toString();</span>
  }

  /**
   * Prints the config types.
   *
   * @param types the types
   * @return the string
   */
  private String printConfigTypes(
      HashMap&lt;?, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; types) {
<span class="nc" id="L787">    StringBuilder text = new StringBuilder();</span>
<span class="nc bnc" id="L788" title="All 2 branches missed.">    for (Entry&lt;?, MtasParserType&lt;MtasParserMapping&lt;?&gt;&gt;&gt; entry : types</span>
<span class="nc" id="L789">        .entrySet()) {</span>
<span class="nc" id="L790">      text.append(&quot;- &quot; + entry.getKey() + &quot;: &quot; + entry.getValue().items.size()</span>
          + &quot; mapping(s)\n&quot;);
<span class="nc bnc" id="L792" title="All 2 branches missed.">      for (int i = 0; i &lt; entry.getValue().items.size(); i++) {</span>
<span class="nc" id="L793">        text.append(&quot;\t&quot; + entry.getValue().items.get(i) + &quot;\n&quot;);</span>
      }
<span class="nc" id="L795">    }</span>
<span class="nc" id="L796">    return text.toString();</span>
  }

  /**
   * The Class MtasCRMAncestors.
   */
<span class="nc" id="L802">  private static class MtasCRMAncestors {</span>

    /** The unknown. */
<span class="nc" id="L805">    public int unknown = 0;</span>
  }

  /**
   * The Class MtasCRMParserFunction.
   */
  private static class MtasCRMParserFunction {

    /** The split. */
    public String split;

    /** The output. */
    public Map&lt;String, ArrayList&lt;MtasCRMParserFunctionOutput&gt;&gt; output;

    /**
     * Instantiates a new mtas CRM parser function.
     *
     * @param type the type
     * @param split the split
     */
<span class="nc" id="L825">    public MtasCRMParserFunction(String type, String split) {</span>
<span class="nc" id="L826">      this.split = split;</span>
<span class="nc" id="L827">      output = new HashMap&lt;&gt;();</span>
<span class="nc" id="L828">    }</span>

  }

  /**
   * The Class MtasCRMParserFunctionOutput.
   */
  private class MtasCRMParserFunctionOutput {

    /** The name. */
    public String name;

    /** The value. */
    public String value;

    /**
     * Instantiates a new mtas CRM parser function output.
     *
     * @param name the name
     * @param value the value
     */
<span class="nc" id="L849">    public MtasCRMParserFunctionOutput(String name, String value) {</span>
<span class="nc" id="L850">      this.name = name;</span>
<span class="nc" id="L851">      this.value = value;</span>
<span class="nc" id="L852">    }</span>

    /**
     * Creates the.
     *
     * @param originalValue the original value
     * @return the mtas CRM parser function output
     */
    public MtasCRMParserFunctionOutput create(String originalValue) {
<span class="nc bnc" id="L861" title="All 2 branches missed.">      if (value != null) {</span>
<span class="nc" id="L862">        return this;</span>
      } else {
<span class="nc" id="L864">        return new MtasCRMParserFunctionOutput(name, originalValue);</span>
      }
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
<span class="nc" id="L875">      return &quot;MtasCRMParserFunctionOutput[&quot; + name + &quot;,&quot; + value + &quot;]&quot;;</span>
    }
  }

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

    /**
     * Instantiates a new mtas CRM parser mapping word annotation.
     */
<span class="nc" id="L888">    public MtasCRMParserMappingWordAnnotation() {</span>
<span class="nc" id="L889">      super();</span>
<span class="nc" id="L890">      this.position = SOURCE_OWN;</span>
<span class="nc" id="L891">      this.realOffset = SOURCE_OWN;</span>
<span class="nc" id="L892">      this.offset = SOURCE_ANCESTOR_WORD;</span>
<span class="nc" id="L893">      this.type = MAPPING_TYPE_WORD_ANNOTATION;</span>
<span class="nc" id="L894">    }</span>

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

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

    /**
     * Instantiates a new mtas CRM parser mapping CRM sentence.
     */
<span class="nc" id="L916">    public MtasCRMParserMappingCRMSentence() {</span>
<span class="nc" id="L917">      super();</span>
<span class="nc" id="L918">      this.position = SOURCE_OWN;</span>
<span class="nc" id="L919">      this.realOffset = SOURCE_OWN;</span>
<span class="nc" id="L920">      this.offset = SOURCE_OWN;</span>
<span class="nc" id="L921">      this.type = MAPPING_TYPE_GROUP;</span>
<span class="nc" id="L922">    }</span>

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

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

    /**
     * Instantiates a new mtas CRM parser mapping CRM pair.
     */
<span class="nc" id="L944">    public MtasCRMParserMappingCRMPair() {</span>
<span class="nc" id="L945">      super();</span>
<span class="nc" id="L946">      this.position = SOURCE_OWN;</span>
<span class="nc" id="L947">      this.realOffset = SOURCE_OWN;</span>
<span class="nc" id="L948">      this.offset = SOURCE_OWN;</span>
<span class="nc" id="L949">      this.type = MAPPING_TYPE_RELATION;</span>
<span class="nc" id="L950">    }</span>

    /*
     * (non-Javadoc)
     * 
     * @see mtas.analysis.parser.MtasBasicParser.MtasParserMapping#self()
     */
    @Override
    protected MtasCRMParserMappingCRMPair self() {
<span class="nc" id="L959">      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>