com.acmutv.ontoqa.core.parser.ParserState.java Source code

Java tutorial

Introduction

Here is the source code for com.acmutv.ontoqa.core.parser.ParserState.java

Source

/*
  The MIT License (MIT)
    
  Copyright (c) 2017 Antonella Botte, Giacomo Marciani and Debora Partigianoni
    
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
    
    
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
    
    
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
 */

package com.acmutv.ontoqa.core.parser;

import com.acmutv.ontoqa.core.semantics.base.statement.Statement;
import com.acmutv.ontoqa.core.semantics.base.term.Variable;
import com.acmutv.ontoqa.core.semantics.sltag.Sltag;
import lombok.Data;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;

import java.util.*;

/**
 * The parse stack.
 * @author Antonella Botte {@literal <abotte@acm.org>}
 * @author Giacomo Marciani {@literal <gmarciani@acm.org>}
 * @author Debora Partigianoni {@literal <dpartigianoni@acm.org>}
 * @since 1.0
 */
@Data
@Deprecated
public class ParserState {

    /**
     * Current SLTAG.
     */
    Sltag curr;

    /**
     * True if ASK semantics.
     */
    boolean ask = false;

    /**
     * The list of words.
     */
    private List<String> words = new ArrayList<>();

    /**
     * The id of the previous handled lexical entry.
     */
    private Integer idxPrev;

    /**
     * The substitutions vector.
     */
    private List<Pair<Sltag, Integer>> substitutions = new ArrayList<>();

    /**
     * The adjunctions vector.
     */
    private List<Pair<Sltag, Integer>> adjunctions = new ArrayList<>();

    /**
     * The waiting vector.
     */
    private WaitingList waitingList = new WaitingList();

    /**
     * Main variable miss.
     */
    Map<Integer, Triple<Variable, Variable, Set<Statement>>> missedMainVariables = new HashMap<>();

    public ParserState(String sentence) {
        this.words.addAll(Arrays.asList(sentence.split(" ")));
    }

    /**
     * Adds a waiting adjunction, found immediately after {@code prevLexicalEntry}.
     * @param candidate the SLTAG to adjunct.
     * @param prevIdx the previous lexical entry index.
     */
    public void addAdjunction(Sltag candidate, Integer prevIdx) {
        this.adjunctions.add(new ImmutablePair<>(candidate, prevIdx));
    }

    /**
     * Adds a waiting adjunction, found immediately after {@code prevLexicalEntry}.
     * @param candidate the SLTAG to adjunct.
     * @param prevIdx the previous lexical entry index.
     */
    public void addSubstitution(Sltag candidate, Integer prevIdx) {
        this.substitutions.add(new ImmutablePair<>(candidate, prevIdx));
    }
}