Exemplo n.º 1
0
//! populate this InputType with data from in stream
int
TreeInput::
Read(std::istream& in, const std::vector<FactorType>& factorOrder,
     AllOptions const& opts)
{
    const StaticData &staticData = StaticData::Instance();

    string line;
    if (getline(in, line, '\n').eof())
        return 0;
    // remove extra spaces
    //line = Trim(line);

    m_labelledSpans.clear();
    ProcessAndStripXMLTags(line, m_labelledSpans, m_xmlOptions);

    // do words 1st - hack
    stringstream strme;
    strme << line << endl;

    Sentence::Read(strme, factorOrder, opts);

    // size input chart
    size_t sourceSize = GetSize();
    m_sourceChart.resize(sourceSize);

    for (size_t pos = 0; pos < sourceSize; ++pos) {
        m_sourceChart[pos].resize(sourceSize - pos);
    }

    // do source labels
    vector<XMLParseOutput>::const_iterator iterLabel;
    for (iterLabel = m_labelledSpans.begin(); iterLabel != m_labelledSpans.end(); ++iterLabel) {
        const XMLParseOutput &labelItem = *iterLabel;
        const Range &range = labelItem.m_range;
        const string &label = labelItem.m_label;
        AddChartLabel(range.GetStartPos() + 1, range.GetEndPos() + 1, label, factorOrder);
    }

    // default label
    for (size_t startPos = 0; startPos < sourceSize; ++startPos) {
        for (size_t endPos = startPos; endPos < sourceSize; ++endPos) {
            NonTerminalSet &list = GetLabelSet(startPos, endPos);
            if (list.size() == 0 || !staticData.GetDefaultNonTermOnlyForEmptyRange()) {
                AddChartLabel(startPos, endPos, staticData.GetInputDefaultNonTerminal(), factorOrder);
            }
        }
    }

    return 1;
}
Exemplo n.º 2
0
void TreeInput::AddChartLabel(size_t startPos, size_t endPos, const string &label
                              , const std::vector<FactorType>& factorOrder)
{
  Word word(true);
  const Factor *factor = FactorCollection::Instance().AddFactor(Input, factorOrder[0], label); // TODO - no factors
  word.SetFactor(0, factor);

  AddChartLabel(startPos, endPos, word, factorOrder);
}
Exemplo n.º 3
0
//! populate this InputType with data from in stream
int TreeInput::Read(std::istream& in,const std::vector<FactorType>& factorOrder)
{
  const StaticData &staticData = StaticData::Instance();

  string line;
  if (getline(in, line, '\n').eof())
    return 0;
  // remove extra spaces
  //line = Trim(line);

  std::vector<XMLParseOutput> sourceLabels;
  std::vector<XmlOption*> xmlOptionsList;
  ProcessAndStripXMLTags(line, sourceLabels, xmlOptionsList);

  // do words 1st - hack
  stringstream strme;
  strme << line << endl;

  Sentence::Read(strme, factorOrder);

  // size input chart
  size_t sourceSize = GetSize();
  m_sourceChart.resize(sourceSize);

  for (size_t pos = 0; pos < sourceSize; ++pos) {
    m_sourceChart[pos].resize(sourceSize - pos);
  }

  // do source labels
  vector<XMLParseOutput>::const_iterator iterLabel;
  for (iterLabel = sourceLabels.begin(); iterLabel != sourceLabels.end(); ++iterLabel) {
    const XMLParseOutput &labelItem = *iterLabel;
    const WordsRange &range = labelItem.m_range;
    const string &label = labelItem.m_label;
    AddChartLabel(range.GetStartPos() + 1, range.GetEndPos() + 1, label, factorOrder);
  }

  // default label
  for (size_t startPos = 0; startPos < sourceSize; ++startPos) {
    for (size_t endPos = startPos; endPos < sourceSize; ++endPos) {
      AddChartLabel(startPos, endPos, staticData.GetInputDefaultNonTerminal(), factorOrder);
    }
  }

  // XML Options

  //only fill the vector if we are parsing XML
  if (staticData.GetXmlInputType() != XmlPassThrough ) {
    //TODO: needed to handle exclusive
    //for (size_t i=0; i<GetSize(); i++) {
    //  m_xmlCoverageMap.push_back(false);
    //}

    //iterXMLOpts will be empty for XmlIgnore
    //look at each column
    for(std::vector<XmlOption*>::const_iterator iterXmlOpts = xmlOptionsList.begin();
        iterXmlOpts != xmlOptionsList.end(); iterXmlOpts++) {

      const XmlOption *xmlOption = *iterXmlOpts;
      TargetPhrase *targetPhrase = new TargetPhrase(xmlOption->targetPhrase);
      *targetPhrase = xmlOption->targetPhrase; // copy everything
      WordsRange *range = new WordsRange(xmlOption->range);
      const StackVec emptyStackVec; // hmmm... maybe dangerous, but it is never consulted

      TargetPhraseCollection *tpc = new TargetPhraseCollection;
      tpc->Add(targetPhrase);

      ChartTranslationOptions *transOpt = new ChartTranslationOptions(*tpc, emptyStackVec, *range, 0.0f);
      m_xmlChartOptionsList.push_back(transOpt);

      //TODO: needed to handle exclusive
      //for(size_t j=transOpt->GetSourceWordsRange().GetStartPos(); j<=transOpt->GetSourceWordsRange().GetEndPos(); j++) {
      //  m_xmlCoverageMap[j]=true;
      //}

      delete xmlOption;
    }

  }

  return 1;
}