<?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>