2010-07-18 03:23:09 +04:00
|
|
|
// $Id$
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_PCNTools
|
|
|
|
#define moses_PCNTools
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <vector>
|
2013-09-06 01:34:22 +04:00
|
|
|
#include <map>
|
2008-06-11 14:52:57 +04:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2008-10-17 01:14:38 +04:00
|
|
|
#include <cstdlib>
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
/** A couple of utilities to read .pcn files. A python-compatible format
|
2012-06-29 02:29:46 +04:00
|
|
|
* for encoding confusion networks and word lattices.
|
|
|
|
*/
|
2011-02-24 16:14:42 +03:00
|
|
|
namespace PCN
|
|
|
|
{
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-09-27 12:35:24 +04:00
|
|
|
struct CNAlt {
|
|
|
|
CNAlt()
|
|
|
|
{}
|
|
|
|
CNAlt(const std::string &word,
|
|
|
|
const std::vector<float> &denseFeatures,
|
|
|
|
const std::map<std::string, float> &sparseFeatures,
|
|
|
|
size_t next)
|
|
|
|
:m_word(word)
|
|
|
|
,m_denseFeatures(denseFeatures)
|
|
|
|
,m_sparseFeatures(sparseFeatures)
|
|
|
|
,m_next(next)
|
|
|
|
{}
|
2013-09-06 01:34:22 +04:00
|
|
|
|
2013-09-27 12:35:24 +04:00
|
|
|
std::string m_word;
|
|
|
|
std::vector<float> m_denseFeatures;
|
|
|
|
std::map<std::string, float> m_sparseFeatures;
|
|
|
|
size_t m_next;
|
2013-09-06 01:34:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//typedef std::pair<std::pair<std::string, std::vector<float> >, size_t> CNAlt;
|
2011-02-24 16:14:42 +03:00
|
|
|
typedef std::vector<CNAlt> CNCol;
|
|
|
|
typedef std::vector<CNCol> CN;
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
/** Given a string ((('foo',0.1,1),('bar',0.9,2)),...) representation of a
|
2012-06-29 02:29:46 +04:00
|
|
|
* word lattice in PCN format, return a CN object representing the lattice
|
|
|
|
*/
|
2011-02-24 16:14:42 +03:00
|
|
|
CN parsePCN(const std::string& in);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|