wintermute-devel team mailing list archive
-
wintermute-devel team
-
Mailing list archive
-
Message #00071
[Merge] lp:~wintermute-devel/wintermute/linguistics into lp:~wintermute-devel/wintermute/linguistics-devel
Jacky Alciné has proposed merging lp:~wintermute-devel/wintermute/linguistics into lp:~wintermute-devel/wintermute/linguistics-devel.
Requested reviews:
Wintermute Developers (wintermute-devel): codebase
For more details, see:
https://code.launchpad.net/~wintermute-devel/wintermute/linguistics/+merge/54990
--
https://code.launchpad.net/~wintermute-devel/wintermute/linguistics/+merge/54990
Your team Wintermute Developers is requested to review the proposed merge of lp:~wintermute-devel/wintermute/linguistics into lp:~wintermute-devel/wintermute/linguistics-devel.
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2011-03-26 23:34:24 +0000
@@ -0,0 +1,2 @@
+build
+dist
=== renamed file '.bzrignore' => '.bzrignore.moved'
=== added file '.dep.inc'
--- .dep.inc 1970-01-01 00:00:00 +0000
+++ .dep.inc 2011-03-26 23:34:24 +0000
@@ -0,0 +1,5 @@
+# This code depends on make tool being used
+DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES}))
+ifneq (${DEPFILES},)
+include ${DEPFILES}
+endif
=== added file 'Makefile'
--- Makefile 1970-01-01 00:00:00 +0000
+++ Makefile 2011-03-26 23:34:24 +0000
@@ -0,0 +1,128 @@
+#
+# There exist several targets which are by default empty and which can be
+# used for execution of your targets. These targets are usually executed
+# before and after some main targets. They are:
+#
+# .build-pre: called before 'build' target
+# .build-post: called after 'build' target
+# .clean-pre: called before 'clean' target
+# .clean-post: called after 'clean' target
+# .clobber-pre: called before 'clobber' target
+# .clobber-post: called after 'clobber' target
+# .all-pre: called before 'all' target
+# .all-post: called after 'all' target
+# .help-pre: called before 'help' target
+# .help-post: called after 'help' target
+#
+# Targets beginning with '.' are not intended to be called on their own.
+#
+# Main targets can be executed directly, and they are:
+#
+# build build a specific configuration
+# clean remove built files from a configuration
+# clobber remove all built files
+# all build all configurations
+# help print help mesage
+#
+# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
+# .help-impl are implemented in nbproject/makefile-impl.mk.
+#
+# Available make variables:
+#
+# CND_BASEDIR base directory for relative paths
+# CND_DISTDIR default top distribution directory (build artifacts)
+# CND_BUILDDIR default top build directory (object files, ...)
+# CONF name of current configuration
+# CND_PLATFORM_${CONF} platform name (current configuration)
+# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
+# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
+# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
+# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
+# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
+# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
+#
+# NOCDDL
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+CCADMIN=CCadmin
+
+
+# build
+build: .build-post
+
+.build-pre:
+# Add your pre 'build' code here...
+
+.build-post: .build-impl
+# Add your post 'build' code here...
+
+
+# clean
+clean: .clean-post
+
+.clean-pre:
+# Add your pre 'clean' code here...
+
+.clean-post: .clean-impl
+# Add your post 'clean' code here...
+
+
+# clobber
+clobber: .clobber-post
+
+.clobber-pre:
+# Add your pre 'clobber' code here...
+
+.clobber-post: .clobber-impl
+# Add your post 'clobber' code here...
+
+
+# all
+all: .all-post
+
+.all-pre:
+# Add your pre 'all' code here...
+
+.all-post: .all-impl
+# Add your post 'all' code here...
+
+
+# build tests
+build-tests: .build-tests-post
+
+.build-tests-pre:
+# Add your pre 'build-tests' code here...
+
+.build-tests-post: .build-tests-impl
+# Add your post 'build-tests' code here...
+
+
+# run tests
+test: .test-post
+
+.test-pre:
+# Add your pre 'test' code here...
+
+.test-post: .test-impl
+# Add your post 'test' code here...
+
+
+# help
+help: .help-post
+
+.help-pre:
+# Add your pre 'help' code here...
+
+.help-post: .help-impl
+# Add your post 'help' code here...
+
+
+
+# include project implementation makefile
+include nbproject/Makefile-impl.mk
+
+# include project make variables
+include nbproject/Makefile-variables.mk
=== added file 'README'
--- README 1970-01-01 00:00:00 +0000
+++ README 2011-03-26 23:34:24 +0000
@@ -0,0 +1,18 @@
+ *
+ * The code within this directory is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU Library
+ * General Public License as published by the Free Software Foundation;
+ * either version 3 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+
+This is the core interactions of the Panlingua parser.
=== renamed file 'README' => 'README.moved'
=== added file 'config.cpp'
--- config.cpp 1970-01-01 00:00:00 +0000
+++ config.cpp 2011-03-26 23:34:24 +0000
@@ -0,0 +1,70 @@
+/*
+ * Author: $NAME <$EMAIL>
+ *
+ * Copyright 2011 $NAME
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.hpp"
+
+namespace Wintermute {
+ string Configuration::_locale = "en";
+ string Configuration::_root = "store";
+
+ void Configuration::setLocale(const string locale) {
+ if (locale.size() == 0)
+ return;
+
+ Configuration::_locale = locale;
+ }
+
+ void Configuration::setRootDirectory(const string root) {
+ if (root.size() == 0)
+ return;
+
+ Configuration::_root = root;
+ }
+
+ const string Configuration::getWordlist(const string locale) {
+ string theLocale = locale;
+ if (locale.size() == 0)
+ theLocale = Configuration::getLocale();
+
+ return Configuration::getRootDirectory() + string("/locale/") + theLocale + string("/wordlist.") + theLocale;
+ }
+
+ const string Configuration::getLexicalRoot(const string locale) {
+ string theLocale = locale;
+ if (locale.size() == 0)
+ theLocale = Configuration::getLocale();
+
+ return Configuration::getRootDirectory() + string("/locale/") + theLocale + string("/nods");
+ }
+
+ const string Configuration::getSemanticRoot() {
+ return Configuration::getRootDirectory() + string("/ontology");
+ }
+
+ const string Configuration::getLocale() {
+ return Configuration::_locale;
+ }
+
+ const string Configuration::getRootDirectory() {
+ return Configuration::_root;
+ }
+}
=== added file 'config.hpp'
--- config.hpp 1970-01-01 00:00:00 +0000
+++ config.hpp 2011-03-26 23:34:24 +0000
@@ -0,0 +1,79 @@
+/**
+ * @file config.hpp
+ * @author Jacky Alcine <jackyalcine@xxxxxxxxx>
+ * @created February 4, 2011, 12:07 AM
+ * @license GPL3
+ *
+ * Copyright (c) SII 2010 - 2011
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @todo Implement a Configuration object (or struct) that can be used
+ * in the nodes and links (when serialization is avialable) so that
+ * they can pull *default* settings from here, but transliterate
+ * across ontologies.
+ */
+
+#ifndef CONFIG_HPP
+#define CONFIG_HPP
+
+#define DEBUG_OUTPUT
+#ifdef DEBUG_OUTPUT
+#warning "This version of Panlingua will be outputting a bit more information."
+#else
+#warning "Output has been disabled."
+#endif
+
+#include "config.hpp"
+#include <string>
+#include <sstream>
+#include <cstdio>
+
+using namespace std;
+using std::ostringstream;
+using std::string;
+
+namespace Wintermute {
+
+ static const long filesize(const string &url) {
+ FILE *fileSize = fopen(url.c_str(),"r");
+ fseek(fileSize, 0L, SEEK_END);
+ long endPos = ftell(fileSize);
+ fclose(fileSize);
+ return endPos;
+ }
+
+ static const string itostr(const int value) {
+ ostringstream outString;
+ outString << value;
+ return outString.str();
+ }
+
+ class Configuration {
+ private:
+ static string _root;
+ static string _locale;
+ public:
+ Configuration();
+ ~Configuration();
+ static const string getRootDirectory();
+ static const string getWordlist(const string = "");
+ static const string getLocale();
+ static const string getSemanticRoot();
+ static const string getLexicalRoot(const string = "");
+ static void setLocale(const string = "");
+ static void setRootDirectory(const string = "");
+ };
+}
+
+#endif /* CONFIG_HPP */
+
=== added file 'core.cpp'
--- core.cpp 1970-01-01 00:00:00 +0000
+++ core.cpp 2011-03-26 23:34:24 +0000
@@ -0,0 +1,463 @@
+/**
+ * File: core.cpp
+ * Author: Jacky Alcine <jackyalcine@xxxxxxxxx>
+ * Created on January 19, 2011, 5:16 AM
+ *
+ * Copyright (c) SII 2010 - 2011
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include "config.hpp"
+#include "core.hpp"
+#include <iostream>
+#include <fstream>
+#include <cstdlib>
+#include <ctime>
+#include <cmath>
+#include <algorithm>
+
+using namespace std;
+using std::ios;
+using std::ifstream;
+using std::endl;
+
+namespace Wintermute {
+ namespace Linguistics {
+
+ using Wintermute::Linguistics::Configuration;
+
+ void node_cleanup() {
+ }
+
+ void Initialize(const string root = "store", const string locale = "en") {
+ Configuration::setLocale(locale);
+ Configuration::setRootDirectory(root);
+ }
+
+ NodeIndex* SemanticNode::_index = new NodeIndex;
+ NodeIndex* SyntacticNode::_index = new NodeIndex;
+ NodeIndex* LexicalNode::_index = new NodeIndex;
+ LinkIndex* RadicalLink::_index = new LinkIndex;
+ map<char, string>* SyntacticNode::_flgs = new map<char, string>;
+
+ Node::Node() {
+ this->id = -1;
+ }
+
+ Node::~Node() {
+ }
+
+ const int Node::getID() const {
+ return id;
+ }
+
+ void Node::setID(const int newID) {
+ this->id = newID;
+ }
+
+ bool Node::operator ==(const Node &toCheck) const {
+ if (&toCheck == NULL)
+ return false;
+ else {
+ Node* aNode = const_cast<Node*> (& toCheck);
+ return (id == aNode->id);
+ }
+ }
+
+ LexicalNode::LexicalNode(const int id, const string &locale) : Node() {
+ if (id != -1)
+ _parse(id);
+
+ if (locale.size() == 0)
+ _locale = Configuration::getLocale();
+ else
+ _locale = locale;
+ }
+
+ LexicalNode::~LexicalNode() {
+ //
+ }
+
+ const string LexicalNode::getLocale() const {
+ return this->_locale;
+ }
+
+ const int LexicalNode::count() {
+ return _index->size();
+ }
+
+ void LexicalNode::_parse(const int id) {
+ string lexnodUri = Configuration::getLexicalRoot(this->getLocale()), flags;
+ int semid;
+ lexnodUri += "/" + itostr(id);
+
+ ifstream inLexnod(lexnodUri.c_str(), ios::in);
+ if (!inLexnod) {
+#ifdef DEBUG_OUTPUT
+ cout << id << " not found." << endl;
+#endif
+ return;
+ }
+
+ this->setID(id);
+ inLexnod >> this->_strSymbol;
+
+ while (inLexnod >> flags >> semid)
+ LexicalLink::build(SemanticNode::fromID(semid), this, flags);
+
+ inLexnod.close();
+
+ LexicalNode::_index->insert(NodeIndex::value_type(id, this));
+ }
+
+ LexicalNode* LexicalNode::fromID(const int id) {
+ if (LexicalNode::exists(id))
+ return static_cast<LexicalNode*> (LexicalNode::_index->at(id));
+ else
+ return new LexicalNode(id);
+ }
+
+ const long LexicalNode::toID(const string &text) {
+ long value = 1;
+ if (text.empty() || text.size() == 0)
+ return value;
+
+ for (int i = 0; i < text.size(); i++) {
+ int charVal = ((int) text.at(i));
+ charVal *= (i + 1);
+ charVal *= text.size();
+ charVal += (i + 1) * text.size();
+ charVal *= (int) pow((i + 1), (text.size()));
+ value += charVal;
+ }
+
+ value += text.size();
+ return value;
+ }
+
+ const bool LexicalNode::exists(const int id) {
+ LexicalNode* aNode = new LexicalNode(id);
+ return (aNode->getID() != -1);
+ }
+
+ const string LexicalNode::getSymbol() const {
+ return this->_strSymbol;
+ }
+
+ SemanticNode::SemanticNode() : Node() {
+ }
+
+ SemanticNode::~SemanticNode() {
+ }
+
+ const bool SemanticNode::exists(const int id) {
+ return (_index->find(id) != _index->end());
+ }
+
+ SemanticNode* SemanticNode::fromID(const int id) {
+ if (SemanticNode::exists(id))
+ return static_cast<SemanticNode*> (SemanticNode::_index->at(id));
+ else {
+ string semnodUri = Configuration::getSemanticRoot(), semanticUri;
+ semnodUri += +"/" + id;
+ ifstream inSemnod(semnodUri.c_str(), ios::in);
+
+ if (!inSemnod)
+ return NULL;
+
+ inSemnod >> semanticUri;
+ SemanticNode* theNode = new SemanticNode;
+ theNode->setID(id);
+ theNode->__rdfUri = semanticUri;
+
+ while (!inSemnod.eof()) {
+ int rootID;
+ string relatedFlags;
+ inSemnod >> relatedFlags >> rootID;
+
+ if (relatedFlags.empty()) break;
+ else RadicalLink::build(theNode, SemanticNode::fromID(rootID), relatedFlags);
+ }
+
+ SemanticNode::_index->insert(NodeIndex::value_type(id, theNode));
+ }
+ }
+
+ SyntacticNode::SyntacticNode() : Node() {
+ this->_psu = false;
+ }
+
+ SyntacticNode* SyntacticNode::build(const int id, const string flags, const string text) {
+ SyntacticNode* aNode = new SyntacticNode();
+ aNode->setID(id);
+ aNode->_flg = flags;
+ aNode->_txt = text;
+ return aNode;
+ }
+
+ SyntacticNode* SyntacticNode::buildPsuedo(const string psuedoText) {
+ SyntacticNode *aNode = SyntacticNode::build(-1, "A", psuedoText);
+ aNode->_psu = true;
+ return aNode;
+ }
+
+ const string SyntacticNode::getFlags() const {
+ return this->_flg;
+ }
+
+ void SyntacticNode::setFlags(const string &flags) {
+ for (int i = 0; i < flags.size(); i++) {
+ char flg = flags.at(i);
+ if (!this->_flg.find(flg))
+ this->_flg += flg;
+ }
+ }
+
+ const bool SyntacticNode::isPsuedo() const {
+ return this->_psu;
+ }
+
+ const string SyntacticNode::getText() const {
+ return this->_txt;
+ }
+
+ const char SyntacticNode::getType() const {
+ for (int i = 0; i < _flg.size(); i++) {
+ if (isupper(_flg.at(i)))
+ return _flg.at(i);
+ }
+
+ return '?';
+ }
+
+ LexicalNode* SyntacticNode::getSymbol() const {
+ if (isPsuedo())
+ return NULL;
+ else
+ return LexicalNode::fromID(this->getID());
+ }
+
+ SemanticNode* SyntacticNode::getMeaning() const {
+ if (isPsuedo())
+ return NULL;
+ else
+ return LexicalLink::getExactMeaningOf(getSymbol(), getFlags());
+ }
+
+ const string SyntacticNode::hasTheFlag(const string &flags) const {
+ string theString = "";
+ for (int i = 0; i < flags.size(); i++) {
+ const char *theFlag = hasTheFlag(flags.at(i));
+ if (theFlag != NULL)
+ theString += *theFlag;
+ }
+
+ return theString;
+ }
+
+ const char* SyntacticNode::hasTheFlag(const char &flag) const {
+ if (!hasFlag(flag))
+ return &flag;
+ else
+ return NULL;
+ }
+
+ const bool SyntacticNode::hasFlag(const string &flgQuery) const {
+ for (int i = 0; i < flgQuery.size(); i++) {
+ if (!hasFlag(flgQuery.at(i)))
+ return false;
+ }
+
+ return true;
+ }
+
+ const bool SyntacticNode::hasFlag(const char &flgQuery) const {
+ return (_flg.find(flgQuery) != -1);
+ }
+
+ SyntacticNode::~SyntacticNode() {
+ }
+
+ Link::Link() {
+ }
+
+ Link::Link(const Node* nodeSrc, const Node* nodeDst) {
+ this->_nodeDest = const_cast<Node*> (nodeDst);
+ this->_nodeSrc = const_cast<Node*> (nodeSrc);
+ }
+
+ Link::~Link() {
+ delete this->_nodeDest;
+ delete this->_nodeSrc;
+ }
+
+ Node* Link::getDestination() const {
+ return this->_nodeDest;
+ }
+
+ Node* Link::getSource() const {
+ return this->_nodeSrc;
+ }
+
+ LinkIndex* LexicalLink::_index = new LinkIndex;
+
+ LexicalLink::LexicalLink() : Link() {
+ }
+
+ LexicalLink::LexicalLink(SemanticNode *snod, LexicalNode *lnod, const string flags) : Link(snod, lnod) {
+ this->_lnkType = flags;
+ string ID = flags + " " + lnod->getSymbol();
+ LexicalLink::_index->insert(LinkIndex::value_type(ID, this));
+ }
+
+ void LexicalLink::build(SemanticNode* snod, LexicalNode* lnod, const string flags) {
+ if (snod == NULL)
+ return;
+
+ LexicalLink *newLink;
+ newLink = new LexicalLink(snod, lnod, flags);
+ }
+
+ const bool LexicalLink::exists(LexicalNode *lnod) {
+ if (lnod == NULL)
+ return false;
+ else
+ return (LexicalLink::_index->lower_bound(lnod->getSymbol()) == LexicalLink::_index->end());
+ }
+
+ const bool LexicalLink::hasFlagsFor(LexicalNode* lnod, const string flags) {
+ if (flags.empty() || lnod == NULL)
+ return false;
+
+ string ID = flags + " " + itostr(lnod->getID());
+ return (LexicalLink::_index->find(ID) != LexicalLink::_index->end());
+ }
+
+ const StringVector LexicalLink::obtainFlagsFor(LexicalNode* lnod, SemanticNode* snod = NULL) {
+ StringVector flags;
+ if (lnod != NULL) {
+ for (LinkIndex::iterator itr = LexicalLink::_index->begin(); itr != LexicalLink::_index->end(); itr++) {
+ LexicalLink *link = reinterpret_cast<LexicalLink*> (itr->second);
+ if (link->getSymbol() == lnod && ((snod != NULL && link->getMeaning() == snod) || snod == NULL))
+ flags.push_back(link->_lnkType);
+ }
+ }
+ unique(flags.begin(), flags.end());
+ return flags;
+ }
+
+ SemanticNode* LexicalLink::getExactMeaningOf(LexicalNode* lnod, const string flags) {
+ LinkIndex::iterator itr = _index->find(flags + " " + itostr(lnod->getID()));
+ if (itr == _index->end())
+ return NULL;
+ else
+ return (reinterpret_cast<LexicalLink*> (itr->second))->getMeaning();
+ }
+
+ LexicalNode* LexicalLink::getExactSymbolOf(SemanticNode* snod, const string flags) {
+ NodeVector allSymbols = LexicalLink::getSymbolOf(snod);
+ for (NodeVector::const_iterator i = allSymbols.begin(); i != allSymbols.end(); i++) {
+ LexicalNode *lnod = reinterpret_cast<LexicalNode*> (*i);
+ if (LexicalLink::getExactMeaningOf(lnod, flags) == snod)
+ return lnod;
+ }
+
+ return NULL;
+ }
+
+ NodeVector LexicalLink::getMeaningOf(LexicalNode* lnod) {
+ NodeVector theList;
+
+ if (lnod != NULL) {
+ for (LinkIndex::iterator itr = LexicalLink::_index->begin(); itr != LexicalLink::_index->end(); itr++) {
+ string fullflag = itr->first;
+ LexicalLink *aLink = reinterpret_cast<LexicalLink*> (itr->second);
+ if (aLink->getSymbol() == lnod)
+ theList.push_back(aLink->getMeaning());
+ }
+
+ unique(theList.begin(), theList.end());
+ }
+ return theList;
+ }
+
+ NodeVector LexicalLink::getSymbolOf(SemanticNode* snod) {
+ NodeVector theList;
+
+ if (snod != NULL) {
+ for (LinkIndex::iterator itr = LexicalLink::_index->begin(); itr != LexicalLink::_index->end(); itr++) {
+ LexicalLink *aLink = reinterpret_cast<LexicalLink*> (itr->second);
+ if (aLink->getMeaning() == snod)
+ theList.push_back(aLink->getSymbol());
+ }
+
+ unique(theList.begin(), theList.end());
+ }
+
+ return theList;
+ }
+
+ const int LexicalLink::count() {
+ return LexicalLink::_index->size();
+ }
+
+ SemanticNode* LexicalLink::getMeaning() const {
+ return reinterpret_cast<SemanticNode*> (this->_nodeSrc);
+ }
+
+ LexicalNode* LexicalLink::getSymbol() const {
+ return reinterpret_cast<LexicalNode*> (this->_nodeDest);
+ }
+
+ LexicalLink::~LexicalLink() {
+ }
+
+ RadicalLink::RadicalLink() : Link() {
+ }
+
+ RadicalLink::RadicalLink(SemanticNode* subMeaning, SemanticNode* baseMeaning, string flags) : Link(subMeaning, baseMeaning) {
+ this->_lnkType = flags;
+ string ID = itostr(subMeaning->getID()) + string(" ") + flags + string(" ") + itostr(baseMeaning->getID());
+
+ RadicalLink::_index->insert(LinkIndex::value_type(ID, this));
+ }
+
+ void RadicalLink::build(SemanticNode* baseMeaning, SemanticNode* subMeaning, const string flags) {
+ RadicalLink *newLink;
+ newLink = new RadicalLink(baseMeaning, subMeaning, flags);
+ }
+
+ RadicalLink::~RadicalLink() {
+
+ }
+
+ SyntacticLink::SyntacticLink() : Link() {
+
+ }
+
+ SyntacticLink::SyntacticLink(SyntacticNode* word1, SyntacticNode* word2, const string flag, const NodeVector *modifiers) : Link(word1, word2) {
+ this->_lnkType = flag;
+ this->_mods = const_cast<NodeVector*> (modifiers);
+
+ cout << "Created a link with " << modifiers->size() << " modifiers and flags " << flag << endl;
+ }
+
+ SyntacticNode* SyntacticLink::getDependentWord() const {
+ return reinterpret_cast<SyntacticNode*> (this->_nodeDest);
+ }
+
+ SyntacticNode* SyntacticLink::getRegentWord() const {
+ return reinterpret_cast<SyntacticNode*> (this->_nodeSrc);
+ }
+ }
+}
\ No newline at end of file
=== added file 'core.hpp'
--- core.hpp 1970-01-01 00:00:00 +0000
+++ core.hpp 2011-03-26 23:34:24 +0000
@@ -0,0 +1,393 @@
+/**
+ * File: core.hpp
+ * Author: Jacky Alcine <jackyalcine@xxxxxxxxx>
+ * Created on January 19, 2011, 5:16 AM
+ *
+ * Copyright (c) SII 2010 - 2011
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * @consider: A storage template class for Nodes? To avoid run-time errors of
+ * conversion and instead have such errors be raised at compile-time?
+ * @description:Header information for the Panlingua network.
+ */
+
+#ifndef CORE_HPP
+#define CORE_HPP
+#include "config.hpp"
+#include <vector>
+#include <map>
+#include <string>
+
+using namespace std;
+using std::vector;
+using std::map;
+using std::string;
+
+namespace Wintermute {
+ namespace Linguistcs {
+ class Parser;
+ class Link;
+ class Node;
+ class SyntacticNode;
+ class SemanticNode;
+ class LexicalNode;
+ class SyntacticLink;
+ class SemanticLink;
+ class LexicalLink;
+ class RadicalLink;
+
+ /**
+ * @description Used throughout this application, a StringVector is
+ * merely a shorthand notation for std::vector<std::basic_string>.
+ */
+ typedef vector<string> StringVector;
+ /**
+ * @description Used throughout this application, a LinkVector is
+ * merely a shorthand notation for std::vector<Panlingua::Link>.
+ * It serves as the base 'collection' type for all Panlingual links.
+ */
+ typedef vector<Link*> LinkVector;
+ /**
+ * @description Used throughout this application, a NodeVector is
+ * merely a shortand notation for std::vector<Panlingua::Node>.
+ * It serves as the base 'collection' type for all Panlingua links.
+ */
+ typedef vector<Node*> NodeVector;
+ /**
+ * @description Used throughout this application, a NodeIndex is
+ * a means of indexing nodes according to a certain ID.
+ * It serves as the base 'index' type for all Panlingual nodes.
+ * @consider Transparently implementing a hash_table to increase speed. May have
+ * a few problems once it hits huge sets of data (700,000).
+ */
+ typedef map<int, Node*> NodeIndex;
+ /**
+ * @description Used throughout this application, a LinkIndex is a
+ * means of indexing links according to a certain ID.
+ * It serves as the base 'index' type for all Panlingual nodes.
+ * @consider See consider#1 for Panlingua::NodeIndex.
+ */
+ typedef map<string, Link*> LinkIndex;
+
+ void node_cleanup(void);
+
+ /**
+ * @description The base type for all nodes in Panlingua.
+ */
+ class Node {
+ private:
+ int id;
+
+ protected:
+ /**
+ * @description: Internal function
+ * Changes the ID of this Node. Note that only the ID stored with the node is changed,
+ * all parent indexes will not update to this change.
+ * @param int newID
+ */
+ void setID(const int);
+
+ public:
+ /**
+ * @description: Creates a new Node.
+ */
+ Node();
+ /**
+ * @description Destroys this node.
+ */
+ ~Node();
+ /**
+ * @description: Returns the ID associated with this node.
+ * @return int The ID associated with this node.
+ */
+ const int getID() const;
+ bool operator==(const Node&) const;
+ };
+
+ /**
+ * @description A word appearing in cohorent text; this is the "programmable" form
+ * of language. It's passed from and to code to be parsed as if it were
+ * an object.
+ */
+ class SyntacticNode : public Node {
+ friend void node_cleanup(void);
+
+ private:
+ static NodeIndex* _index;
+ static map<char, string> *_flgs;
+ string _flg;
+ string _sem;
+ string _txt;
+ bool _psu;
+
+ public:
+ /**
+ * @description: Creates a new SyntacticNode.
+ */
+ SyntacticNode();
+ /**
+ * @description: Destroys this SyntacticNode.
+ */
+ ~SyntacticNode();
+ /**
+ * @description: Gets the flags associated with this node.
+ * @return string A string (really should be a char[], but string's a container of it) of flags.
+ */
+ const string getFlags() const;
+ void setFlags(const string &);
+ /**
+ * @description: Gets the SemanticNode that's associated with this node.
+ * @return SemanticNode* A pointer to the SemanticNode.
+ */
+ SemanticNode* getMeaning() const;
+ /**
+ * @description: Gets the LexicalNode that's associated with this node.
+ * @return LexicalNode8 A pointer to the LexicalNode.
+ */
+ LexicalNode* getSymbol() const;
+ /**
+ * @description Determines if the specified flags are set in this SyntacticNode.
+ * @param string strFlags Flags to search for.
+ * @return boolean True if *all* flags have been found, false if *one* flag hasn't.
+ */
+ const bool hasFlag(const string &) const;
+ const bool hasFlag(const char &) const;
+ const char* hasTheFlag(const char &) const;
+ const string hasTheFlag(const string &)const;
+ /**
+ * @description Determines if the specified SyntacticNode is a psuedo word, or a word
+ * that isn't recognizable by the parser.
+ * @return boolean True if it's a psuedoword.
+ */
+ const bool isPsuedo() const;
+ /**
+ * @description Returns the flags in a human-friendly string.
+ * @return string The formatted flags.
+ */
+ const string getFormattedFlags() const;
+ /**
+ * @description: Obtains the text as if the word were to be parsed into its original sentence.
+ * @return string The original word.
+ */
+ const string getText() const;
+ /**
+ * @description Determines the word class.
+ * @return char The flag that represents its word class.
+ */
+ const char getType() const;
+ /**
+ * @description Determines the word type from a string.
+ * @param string The friendly name of the type.
+ * @return char The flag that represents its word class.
+ */
+ static const char getTypeFrom(const string &);
+ /**
+ * @description Get every possible word class loaded.
+ * @return a vector<char> with every word class.
+ */
+ static const vector<char> getAllTypes();
+ /**
+ * @description Generates a new SyntacticNode.
+ * @param string semid The SemanticNode's ID behind this.
+ * @param string flags The flags to determine the right LexicalNode.
+ * @param string text The original text.
+ * @return SyntacticNode* A pointer to the SyntacticNode.
+ */
+ static SyntacticNode* build(const int, const string, const string);
+ /**
+ * @description Generates a pseudo SyntacticNode.
+ * @param string text The text to be presented as a pseudoword.
+ * @return A pointer to the SyntacticNode.
+ */
+ static SyntacticNode* buildPsuedo(const string);
+ };
+
+ /**
+ * @description This type represents a 'meaning', or a node within the Panlingual ontology.
+ * @consider Should this be linked up to RDF?
+ */
+ class SemanticNode : public Node {
+ friend void node_cleanup(void);
+ private:
+ static NodeIndex* _index;
+ string __rdfUri;
+ void loadSemanticLinks();
+
+ public:
+ /**
+ * @description The directory at which the Panlingua's ontology is held.
+ */
+ static string BASEDIR;
+
+ /**
+ * @description Generates a new SemanticNode.
+ */
+ SemanticNode();
+ /**
+ * @description Destroys the node.
+ */
+ ~SemanticNode();
+ /**
+ * @description Obtains the meaning of the semantic node.
+ * @consider How does one get a meaning?!
+ */
+ void getMeaning() const;
+ static const bool exists(const int);
+ static SemanticNode* fromID(const int);
+ };
+
+ /**
+ * @description A symbol that represents a collection of sub-symbols that represents a collection of WORDs.
+ */
+ class LexicalNode : public Node {
+ friend void node_cleanup(void);
+ private:
+ static NodeIndex* _index;
+ string _strSymbol;
+ string _locale;
+ void _parse(const int);
+
+ public:
+ LexicalNode(const int, const string & = "");
+ ~LexicalNode();
+ static LexicalNode* fromID(const int);
+ static const bool exists(const int);
+ static const long toID(const string &);
+ static const int count();
+ const string getSymbol() const;
+ const string getLocale() const;
+ };
+
+ /**
+ * @description The base type of a linguistic link.
+ */
+ class Link {
+ protected:
+ Node* _nodeSrc;
+ Node* _nodeDest;
+ string _lnkType;
+
+ public:
+ Link();
+ Link(const Node*, const Node*);
+ ~Link();
+ Node* getSource() const;
+ Node* getDestination() const;
+ bool operator==(const Link&) const;
+ };
+
+ /**
+ * @description Links a dependent WORD to its regent WORD. Used for parsing.
+ */
+ class SyntacticLink : public Link {
+ friend void node_cleanup(void);
+ private:
+ NodeVector *_mods;
+
+ public:
+ SyntacticLink();
+ SyntacticLink(SyntacticNode * = NULL, SyntacticNode * = NULL, const string = "", const NodeVector * = NULL);
+ ~SyntacticLink();
+ SyntacticNode* getDependentWord() const;
+ SyntacticNode* getRegentWord() const;
+ };
+
+ /**
+ * @description Links a meaning to another meaning.
+ * Kick ISA Movement
+ * Father ISA Male_Human
+ */
+ class RadicalLink : public Link {
+ friend void node_cleanup(void);
+ private:
+ static LinkIndex* _index;
+ public:
+ RadicalLink();
+ RadicalLink(SemanticNode*, SemanticNode*, const string);
+ ~RadicalLink();
+ SemanticNode* getBaseMeaning() const;
+ SemanticNode* getSubMeaning() const;
+ static const int count();
+ static void build(SemanticNode*, SemanticNode*, const string);
+ };
+
+ /**
+ * @description Links words to their meaning.
+ */
+ class SemanticLink : public Link {
+ friend void node_cleanup(void);
+ public:
+ SemanticLink();
+ SemanticLink(SyntacticNode*, SemanticNode*, const string);
+ ~SemanticLink();
+ SyntacticNode* getWord() const;
+ SemanticNode* getMeaning() const;
+ const string getType() const;
+ };
+
+ /**
+ * @description Links a meaning with a symbol.
+ */
+ class LexicalLink : public Link {
+ friend void node_cleanup(void);
+ private:
+ static LinkIndex* _index;
+ public:
+ LexicalLink();
+ LexicalLink(SemanticNode*, LexicalNode*, const string);
+ ~LexicalLink();
+ SemanticNode* getMeaning() const;
+ LexicalNode* getSymbol() const;
+ static const int count();
+ static const bool exists(LexicalNode*);
+ static const bool hasFlagsFor(LexicalNode *, const string);
+ static const StringVector obtainFlagsFor(LexicalNode *, SemanticNode *);
+ static void build(SemanticNode*, LexicalNode*, const string);
+ /**
+ * Finds every semantic node attached to a lexical node.
+ * @param lnod The lexical node.
+ * @return Returns a SemanticNode if one was found, otherwise returns a NULL value.
+ * @note If the function returns NULL, that is, technically a *logical* error. There
+ * shouldn't *ever* be a word without a meaning. If possible, implement a means
+ * of creating a standard value for meanings (like a NULL pointer) and change
+ * the lexical node to that value.
+ * @note With larger lists; this can be a very CPU-intestive method, as it's winded
+ * down the entire list of links.
+ */
+ static NodeVector getMeaningOf(LexicalNode*);
+ static NodeVector getSymbolOf(SemanticNode*);
+ static SemanticNode* getExactMeaningOf(LexicalNode *, const string);
+ static LexicalNode* getExactSymbolOf(SemanticNode *, const string);
+ };
+
+ /**
+ * @description
+ */
+ class Interlinguish {
+ private:
+ NodeVector *_nodes;
+ map<char, string> _flgs;
+ map<string, Node*> _cmpn;
+
+ public:
+ Interlinguish();
+ Interlinguish(const NodeVector &);
+ ~Interlinguish();
+ void parse(Parser *);
+ SyntacticNode* at(const int) const;
+ };
+ }
+}
+#endif /* CORE_HPP */
+
=== added directory 'nbproject'
=== added file 'nbproject/Makefile-Debug.mk'
--- nbproject/Makefile-Debug.mk 1970-01-01 00:00:00 +0000
+++ nbproject/Makefile-Debug.mk 2011-03-26 23:34:24 +0000
@@ -0,0 +1,96 @@
+#
+# Generated Makefile - do not edit!
+#
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a -pre and a -post target defined where you can add customized code.
+#
+# This makefile implements configuration specific macros and targets.
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+GREP=grep
+NM=nm
+CCADMIN=CCadmin
+RANLIB=ranlib
+CC=gcc
+CCC=g++
+CXX=g++
+FC=
+AS=as
+
+# Macros
+CND_PLATFORM=GNU-Linux-x86
+CND_CONF=Debug
+CND_DISTDIR=dist
+
+# Include project Makefile
+include Makefile
+
+# Object Directory
+OBJECTDIR=build/${CND_CONF}/${CND_PLATFORM}
+
+# Object Files
+OBJECTFILES= \
+ ${OBJECTDIR}/config.o \
+ ${OBJECTDIR}/parser.o \
+ ${OBJECTDIR}/core.o
+
+
+# C Compiler Flags
+CFLAGS=
+
+# CC Compiler Flags
+CCFLAGS=`pkg-config --cflags --libs sigc++-2.0`
+CXXFLAGS=`pkg-config --cflags --libs sigc++-2.0`
+
+# Fortran Compiler Flags
+FFLAGS=
+
+# Assembler Flags
+ASFLAGS=
+
+# Link Libraries and Options
+LDLIBSOPTIONS=
+
+# Build Targets
+.build-conf: ${BUILD_SUBPROJECTS}
+ "${MAKE}" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/libwintermute-linguistics.a
+
+dist/Debug/GNU-Linux-x86/libwintermute-linguistics.a: ${OBJECTFILES}
+ ${MKDIR} -p dist/Debug/GNU-Linux-x86
+ ${RM} dist/Debug/GNU-Linux-x86/libwintermute-linguistics.a
+ ${AR} -rv ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libwintermute-linguistics.a ${OBJECTFILES}
+ $(RANLIB) dist/Debug/GNU-Linux-x86/libwintermute-linguistics.a
+
+${OBJECTDIR}/config.o: config.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -g -MMD -MP -MF $@.d -o ${OBJECTDIR}/config.o config.cpp
+
+${OBJECTDIR}/parser.o: parser.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -g -MMD -MP -MF $@.d -o ${OBJECTDIR}/parser.o parser.cpp
+
+${OBJECTDIR}/core.o: core.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -g -MMD -MP -MF $@.d -o ${OBJECTDIR}/core.o core.cpp
+
+# Subprojects
+.build-subprojects:
+
+# Clean Targets
+.clean-conf: ${CLEAN_SUBPROJECTS}
+ ${RM} -r build/Debug
+ ${RM} dist/Debug/GNU-Linux-x86/libwintermute-linguistics.a
+
+# Subprojects
+.clean-subprojects:
+
+# Enable dependency checking
+.dep.inc: .depcheck-impl
+
+include .dep.inc
=== added file 'nbproject/Makefile-Release.mk'
--- nbproject/Makefile-Release.mk 1970-01-01 00:00:00 +0000
+++ nbproject/Makefile-Release.mk 2011-03-26 23:34:24 +0000
@@ -0,0 +1,94 @@
+#
+# Generated Makefile - do not edit!
+#
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a -pre and a -post target defined where you can add customized code.
+#
+# This makefile implements configuration specific macros and targets.
+
+
+# Environment
+MKDIR=mkdir
+CP=cp
+GREP=grep
+NM=nm
+CCADMIN=CCadmin
+RANLIB=ranlib
+CC=gcc
+CCC=g++
+CXX=g++
+FC=
+AS=as
+
+# Macros
+CND_PLATFORM=GNU-Linux-x86
+CND_CONF=Release
+CND_DISTDIR=dist
+
+# Include project Makefile
+include Makefile
+
+# Object Directory
+OBJECTDIR=build/${CND_CONF}/${CND_PLATFORM}
+
+# Object Files
+OBJECTFILES= \
+ ${OBJECTDIR}/config.o \
+ ${OBJECTDIR}/parser.o \
+ ${OBJECTDIR}/core.o
+
+
+# C Compiler Flags
+CFLAGS=
+
+# CC Compiler Flags
+CCFLAGS=
+CXXFLAGS=
+
+# Fortran Compiler Flags
+FFLAGS=
+
+# Assembler Flags
+ASFLAGS=
+
+# Link Libraries and Options
+LDLIBSOPTIONS=
+
+# Build Targets
+.build-conf: ${BUILD_SUBPROJECTS}
+ "${MAKE}" -f nbproject/Makefile-Release.mk dist/Release/GNU-Linux-x86/libwintermute-linguistics.so
+
+dist/Release/GNU-Linux-x86/libwintermute-linguistics.so: ${OBJECTFILES}
+ ${MKDIR} -p dist/Release/GNU-Linux-x86
+ ${LINK.cc} -shared -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libwintermute-linguistics.so -fPIC ${OBJECTFILES} ${LDLIBSOPTIONS}
+
+${OBJECTDIR}/config.o: config.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -O2 -fPIC -MMD -MP -MF $@.d -o ${OBJECTDIR}/config.o config.cpp
+
+${OBJECTDIR}/parser.o: parser.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -O2 -fPIC -MMD -MP -MF $@.d -o ${OBJECTDIR}/parser.o parser.cpp
+
+${OBJECTDIR}/core.o: core.cpp
+ ${MKDIR} -p ${OBJECTDIR}
+ ${RM} $@.d
+ $(COMPILE.cc) -O2 -fPIC -MMD -MP -MF $@.d -o ${OBJECTDIR}/core.o core.cpp
+
+# Subprojects
+.build-subprojects:
+
+# Clean Targets
+.clean-conf: ${CLEAN_SUBPROJECTS}
+ ${RM} -r build/Release
+ ${RM} dist/Release/GNU-Linux-x86/libwintermute-linguistics.so
+
+# Subprojects
+.clean-subprojects:
+
+# Enable dependency checking
+.dep.inc: .depcheck-impl
+
+include .dep.inc
=== added file 'nbproject/Makefile-impl.mk'
--- nbproject/Makefile-impl.mk 1970-01-01 00:00:00 +0000
+++ nbproject/Makefile-impl.mk 2011-03-26 23:34:24 +0000
@@ -0,0 +1,133 @@
+#
+# Generated Makefile - do not edit!
+#
+# Edit the Makefile in the project folder instead (../Makefile). Each target
+# has a pre- and a post- target defined where you can add customization code.
+#
+# This makefile implements macros and targets common to all configurations.
+#
+# NOCDDL
+
+
+# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
+# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
+# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
+# and .clean-reqprojects-conf unless SUB has the value 'no'
+SUB_no=NO
+SUBPROJECTS=${SUB_${SUB}}
+BUILD_SUBPROJECTS_=.build-subprojects
+BUILD_SUBPROJECTS_NO=
+BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
+CLEAN_SUBPROJECTS_=.clean-subprojects
+CLEAN_SUBPROJECTS_NO=
+CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
+
+
+# Project Name
+PROJECTNAME=wintermute-linguistics
+
+# Active Configuration
+DEFAULTCONF=Debug
+CONF=${DEFAULTCONF}
+
+# All Configurations
+ALLCONFS=Debug Release
+
+
+# build
+.build-impl: .build-pre .validate-impl .depcheck-impl
+ @#echo "=> Running $@... Configuration=$(CONF)"
+ "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf
+
+
+# clean
+.clean-impl: .clean-pre .validate-impl .depcheck-impl
+ @#echo "=> Running $@... Configuration=$(CONF)"
+ "${MAKE}" -f nbproject/Makefile-${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf
+
+
+# clobber
+.clobber-impl: .clobber-pre .depcheck-impl
+ @#echo "=> Running $@..."
+ for CONF in ${ALLCONFS}; \
+ do \
+ "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .clean-conf; \
+ done
+
+# all
+.all-impl: .all-pre .depcheck-impl
+ @#echo "=> Running $@..."
+ for CONF in ${ALLCONFS}; \
+ do \
+ "${MAKE}" -f nbproject/Makefile-$${CONF}.mk QMAKE=${QMAKE} SUBPROJECTS=${SUBPROJECTS} .build-conf; \
+ done
+
+# build tests
+.build-tests-impl: .build-impl .build-tests-pre
+ @#echo "=> Running $@... Configuration=$(CONF)"
+ "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-tests-conf
+
+# run tests
+.test-impl: .build-tests-impl .test-pre
+ @#echo "=> Running $@... Configuration=$(CONF)"
+ "${MAKE}" -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .test-conf
+
+# dependency checking support
+.depcheck-impl:
+ @echo "# This code depends on make tool being used" >.dep.inc
+ @if [ -n "${MAKE_VERSION}" ]; then \
+ echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
+ echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
+ echo "include \$${DEPFILES}" >>.dep.inc; \
+ echo "endif" >>.dep.inc; \
+ else \
+ echo ".KEEP_STATE:" >>.dep.inc; \
+ echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
+ fi
+
+# configuration validation
+.validate-impl:
+ @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
+ then \
+ echo ""; \
+ echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \
+ echo "See 'make help' for details."; \
+ echo "Current directory: " `pwd`; \
+ echo ""; \
+ fi
+ @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
+ then \
+ exit 1; \
+ fi
+
+
+# help
+.help-impl: .help-pre
+ @echo "This makefile supports the following configurations:"
+ @echo " ${ALLCONFS}"
+ @echo ""
+ @echo "and the following targets:"
+ @echo " build (default target)"
+ @echo " clean"
+ @echo " clobber"
+ @echo " all"
+ @echo " help"
+ @echo ""
+ @echo "Makefile Usage:"
+ @echo " make [CONF=<CONFIGURATION>] [SUB=no] build"
+ @echo " make [CONF=<CONFIGURATION>] [SUB=no] clean"
+ @echo " make [SUB=no] clobber"
+ @echo " make [SUB=no] all"
+ @echo " make help"
+ @echo ""
+ @echo "Target 'build' will build a specific configuration and, unless 'SUB=no',"
+ @echo " also build subprojects."
+ @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no',"
+ @echo " also clean subprojects."
+ @echo "Target 'clobber' will remove all built files from all configurations and,"
+ @echo " unless 'SUB=no', also from subprojects."
+ @echo "Target 'all' will will build all configurations and, unless 'SUB=no',"
+ @echo " also build subprojects."
+ @echo "Target 'help' prints this message."
+ @echo ""
+
=== added file 'nbproject/Makefile-variables.mk'
--- nbproject/Makefile-variables.mk 1970-01-01 00:00:00 +0000
+++ nbproject/Makefile-variables.mk 2011-03-26 23:34:24 +0000
@@ -0,0 +1,24 @@
+#
+# Generated - do not edit!
+#
+# NOCDDL
+#
+CND_BASEDIR=`pwd`
+CND_BUILDDIR=build
+CND_DISTDIR=dist
+# Debug configuration
+CND_PLATFORM_Debug=GNU-Linux-x86
+CND_ARTIFACT_DIR_Debug=dist/Debug/GNU-Linux-x86
+CND_ARTIFACT_NAME_Debug=libwintermute-linguistics.a
+CND_ARTIFACT_PATH_Debug=dist/Debug/GNU-Linux-x86/libwintermute-linguistics.a
+CND_PACKAGE_DIR_Debug=dist/Debug/GNU-Linux-x86/package
+CND_PACKAGE_NAME_Debug=wintermute-linguistics.tar
+CND_PACKAGE_PATH_Debug=dist/Debug/GNU-Linux-x86/package/wintermute-linguistics.tar
+# Release configuration
+CND_PLATFORM_Release=GNU-Linux-x86
+CND_ARTIFACT_DIR_Release=dist/Release/GNU-Linux-x86
+CND_ARTIFACT_NAME_Release=libwintermute-linguistics.so
+CND_ARTIFACT_PATH_Release=dist/Release/GNU-Linux-x86/libwintermute-linguistics.so
+CND_PACKAGE_DIR_Release=dist/Release/GNU-Linux-x86/package
+CND_PACKAGE_NAME_Release=libwintermute-linguistics.so.tar
+CND_PACKAGE_PATH_Release=dist/Release/GNU-Linux-x86/package/libwintermute-linguistics.so.tar
=== added file 'nbproject/Package-Debug.bash'
--- nbproject/Package-Debug.bash 1970-01-01 00:00:00 +0000
+++ nbproject/Package-Debug.bash 2011-03-26 23:34:24 +0000
@@ -0,0 +1,74 @@
+#!/bin/bash -x
+
+#
+# Generated - do not edit!
+#
+
+# Macros
+TOP=`pwd`
+CND_PLATFORM=GNU-Linux-x86
+CND_CONF=Debug
+CND_DISTDIR=dist
+NBTMPDIR=build/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
+TMPDIRNAME=tmp-packaging
+OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libwintermute-linguistics.a
+OUTPUT_BASENAME=libwintermute-linguistics.a
+PACKAGE_TOP_DIR=wintermute-linguistics/
+
+# Functions
+function checkReturnCode
+{
+ rc=$?
+ if [ $rc != 0 ]
+ then
+ exit $rc
+ fi
+}
+function makeDirectory
+# $1 directory path
+# $2 permission (optional)
+{
+ mkdir -p "$1"
+ checkReturnCode
+ if [ "$2" != "" ]
+ then
+ chmod $2 "$1"
+ checkReturnCode
+ fi
+}
+function copyFileToTmpDir
+# $1 from-file path
+# $2 to-file path
+# $3 permission
+{
+ cp "$1" "$2"
+ checkReturnCode
+ if [ "$3" != "" ]
+ then
+ chmod $3 "$2"
+ checkReturnCode
+ fi
+}
+
+# Setup
+cd "${TOP}"
+mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package
+rm -rf ${NBTMPDIR}
+mkdir -p ${NBTMPDIR}
+
+# Copy files and create directories and links
+cd "${TOP}"
+makeDirectory "${NBTMPDIR}/wintermute-linguistics/lib"
+copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644
+
+
+# Generate tar file
+cd "${TOP}"
+rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/wintermute-linguistics.tar
+cd ${NBTMPDIR}
+tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/wintermute-linguistics.tar *
+checkReturnCode
+
+# Cleanup
+cd "${TOP}"
+rm -rf ${NBTMPDIR}
=== added file 'nbproject/Package-Release.bash'
--- nbproject/Package-Release.bash 1970-01-01 00:00:00 +0000
+++ nbproject/Package-Release.bash 2011-03-26 23:34:24 +0000
@@ -0,0 +1,74 @@
+#!/bin/bash -x
+
+#
+# Generated - do not edit!
+#
+
+# Macros
+TOP=`pwd`
+CND_PLATFORM=GNU-Linux-x86
+CND_CONF=Release
+CND_DISTDIR=dist
+NBTMPDIR=build/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
+TMPDIRNAME=tmp-packaging
+OUTPUT_PATH=${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libwintermute-linguistics.so
+OUTPUT_BASENAME=libwintermute-linguistics.so
+PACKAGE_TOP_DIR=libwintermute-linguistics.so/
+
+# Functions
+function checkReturnCode
+{
+ rc=$?
+ if [ $rc != 0 ]
+ then
+ exit $rc
+ fi
+}
+function makeDirectory
+# $1 directory path
+# $2 permission (optional)
+{
+ mkdir -p "$1"
+ checkReturnCode
+ if [ "$2" != "" ]
+ then
+ chmod $2 "$1"
+ checkReturnCode
+ fi
+}
+function copyFileToTmpDir
+# $1 from-file path
+# $2 to-file path
+# $3 permission
+{
+ cp "$1" "$2"
+ checkReturnCode
+ if [ "$3" != "" ]
+ then
+ chmod $3 "$2"
+ checkReturnCode
+ fi
+}
+
+# Setup
+cd "${TOP}"
+mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package
+rm -rf ${NBTMPDIR}
+mkdir -p ${NBTMPDIR}
+
+# Copy files and create directories and links
+cd "${TOP}"
+makeDirectory "${NBTMPDIR}/libwintermute-linguistics.so/lib"
+copyFileToTmpDir "${OUTPUT_PATH}" "${NBTMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644
+
+
+# Generate tar file
+cd "${TOP}"
+rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/libwintermute-linguistics.so.tar
+cd ${NBTMPDIR}
+tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/libwintermute-linguistics.so.tar *
+checkReturnCode
+
+# Cleanup
+cd "${TOP}"
+rm -rf ${NBTMPDIR}
=== added file 'nbproject/configurations.xml'
--- nbproject/configurations.xml 1970-01-01 00:00:00 +0000
+++ nbproject/configurations.xml 2011-03-26 23:34:24 +0000
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configurationDescriptor version="69">
+ <logicalFolder name="root" displayName="root" projectFiles="true">
+ <logicalFolder name="HeaderFiles"
+ displayName="Header Files"
+ projectFiles="true"
+ kind="SOURCE_LOGICAL_FOLDER">
+ <itemPath>config.hpp</itemPath>
+ <itemPath>core.hpp</itemPath>
+ <itemPath>parser.hpp</itemPath>
+ </logicalFolder>
+ <logicalFolder name="ResourceFiles"
+ displayName="Resource Files"
+ projectFiles="true"
+ kind="SOURCE_LOGICAL_FOLDER">
+ <itemPath>../HACKING</itemPath>
+ <itemPath>../INSTALL</itemPath>
+ <itemPath>../README</itemPath>
+ <itemPath>../TODO</itemPath>
+ </logicalFolder>
+ <logicalFolder name="SourceFiles"
+ displayName="Source Files"
+ projectFiles="true"
+ kind="SOURCE_LOGICAL_FOLDER">
+ <itemPath>config.cpp</itemPath>
+ <itemPath>core.cpp</itemPath>
+ <itemPath>parser.cpp</itemPath>
+ </logicalFolder>
+ <logicalFolder name="TestFiles"
+ displayName="Test Files"
+ projectFiles="false"
+ kind="TEST_LOGICAL_FOLDER">
+ </logicalFolder>
+ <logicalFolder name="ExternalFiles"
+ displayName="Important Files"
+ projectFiles="false"
+ kind="IMPORTANT_FILES_FOLDER">
+ <itemPath>Makefile</itemPath>
+ </logicalFolder>
+ </logicalFolder>
+ <projectmakefile>Makefile</projectmakefile>
+ <confs>
+ <conf name="Debug" type="3">
+ <toolsSet>
+ <developmentServer>localhost</developmentServer>
+ <compilerSet>GNU|GNU</compilerSet>
+ <platform>2</platform>
+ </toolsSet>
+ <compileType>
+ <ccTool>
+ <commandLine>`pkg-config --cflags --libs sigc++-2.0`</commandLine>
+ </ccTool>
+ <archiverTool>
+ </archiverTool>
+ </compileType>
+ </conf>
+ <conf name="Release" type="2">
+ <toolsSet>
+ <developmentServer>localhost</developmentServer>
+ <compilerSet>GNU|GNU</compilerSet>
+ <platform>2</platform>
+ </toolsSet>
+ <compileType>
+ <cTool>
+ <developmentMode>5</developmentMode>
+ </cTool>
+ <ccTool>
+ <developmentMode>5</developmentMode>
+ </ccTool>
+ <fortranCompilerTool>
+ <developmentMode>5</developmentMode>
+ </fortranCompilerTool>
+ <asmTool>
+ <developmentMode>5</developmentMode>
+ </asmTool>
+ </compileType>
+ </conf>
+ </confs>
+</configurationDescriptor>
=== added directory 'nbproject/private'
=== added file 'nbproject/private/configurations.xml'
--- nbproject/private/configurations.xml 1970-01-01 00:00:00 +0000
+++ nbproject/private/configurations.xml 2011-03-26 23:34:24 +0000
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configurationDescriptor version="69">
+ <projectmakefile>Makefile</projectmakefile>
+ <defaultConf>0</defaultConf>
+ <confs>
+ <conf name="Debug" type="3">
+ <gizmo_options version="3">
+ <configurationname>GizmoSimple</configurationname>
+ </gizmo_options>
+ <runprofile version="6">
+ <args></args>
+ <rundir></rundir>
+ <buildfirst>true</buildfirst>
+ <console-type>0</console-type>
+ <terminal-type>0</terminal-type>
+ <remove-instrumentation>0</remove-instrumentation>
+ <environment>
+ </environment>
+ </runprofile>
+ </conf>
+ <conf name="Release" type="2">
+ <gizmo_options version="3">
+ <configurationname>GizmoSimple</configurationname>
+ </gizmo_options>
+ <runprofile version="6">
+ <args></args>
+ <rundir></rundir>
+ <buildfirst>true</buildfirst>
+ <console-type>0</console-type>
+ <terminal-type>0</terminal-type>
+ <remove-instrumentation>0</remove-instrumentation>
+ <environment>
+ </environment>
+ </runprofile>
+ </conf>
+ </confs>
+</configurationDescriptor>
=== added file 'nbproject/private/private.properties'
=== added file 'nbproject/private/private.xml'
--- nbproject/private/private.xml 1970-01-01 00:00:00 +0000
+++ nbproject/private/private.xml 2011-03-26 23:34:24 +0000
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>
=== added file 'nbproject/project.properties'
=== added file 'nbproject/project.xml'
--- nbproject/project.xml 1970-01-01 00:00:00 +0000
+++ nbproject/project.xml 2011-03-26 23:34:24 +0000
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.cnd.makeproject</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/make-project/1">
+ <name>wintermute-linguistics</name>
+ <make-project-type>0</make-project-type>
+ <c-extensions/>
+ <cpp-extensions>cpp</cpp-extensions>
+ <header-extensions>hpp</header-extensions>
+ <sourceEncoding>UTF-8</sourceEncoding>
+ <make-dep-projects/>
+ <sourceRootList/>
+ <confList>
+ <confElem>Debug</confElem>
+ <confElem>Release</confElem>
+ </confList>
+ </data>
+ </configuration>
+</project>
=== added file 'parser.cpp'
--- parser.cpp 1970-01-01 00:00:00 +0000
+++ parser.cpp 2011-03-26 23:34:24 +0000
@@ -0,0 +1,292 @@
+/**
+ * File: parser.cpp
+ * Author: Jacky Alcine <jackyalcine@xxxxxxxxx>
+ * Created on January 26, 2011, 5:16 AM
+ *
+ * Copyright (c) SII 2010 - 2011
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * @consider: A storage template class for Nodes?
+
+ * @note Implement hashing and a cache
+ */
+#include "config.hpp"
+#include "parser.hpp"
+#include <sigc++/sigc++.h>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <cstring>
+#include <algorithm>
+
+using namespace Wintermute::Linguistics;
+using std::cout;
+using std::endl;
+using std::ifstream;
+using std::istringstream;
+using std::ios;
+using Wintermute::Linguistics::Configuration;
+
+Wordlist::Wordlist() {
+ this->_words = new StringVector;
+}
+
+Wordlist::Wordlist(const string &locale) {
+ this->_words = new StringVector;
+ load(locale);
+}
+
+const string Wordlist::at(const int &index) const {
+ return this->_words->at(index);
+}
+
+const int Wordlist::at(const string &word) const {
+ if (!has(word)) return -1;
+ for (int i = 0; i < size(); i++)
+ if (word == at(i)) return i;
+}
+
+const bool Wordlist::has(const string &word) const {
+ if (word.empty()) return false;
+ StringVector::iterator location;
+ location = std::find(this->_words->begin(), this->_words->end(), word);
+ return !(location == this->_words->end());
+}
+
+void Wordlist::load(const string &locale) {
+ string uri = Configuration::getWordlist(locale);
+ ifstream inWordlist(uri.c_str(), ios::in);
+
+ if (!inWordlist || filesize(uri) == 0 || inWordlist.is_open()) {
+ cout << "*** Wordlist '" << uri << "' doesn't exist." << endl;
+ return;
+ }
+
+ while (!inWordlist.eof()) {
+ string currentWord;
+ inWordlist >> currentWord;
+
+ if (!currentWord.empty()) {
+ /*if (currentWord.substr(0, 2) == "//")
+ continue; // just a comment.*/
+ this->_words->push_back(currentWord);
+ } else
+ break;
+ }
+
+ inWordlist.close();
+ this->_uri = uri;
+}
+
+const int Wordlist::size() const {
+ return this->_words->size();
+}
+
+void Wordlist::append(const string &word) {
+ this->_words->push_back(word);
+}
+
+void Wordlist::save() {
+ ofstream outList(_uri.c_str(), ios::trunc);
+ for (int i = 0; i < size(); i++)
+ outList << at(i) << endl;
+ outList.close();
+}
+
+Wordlist::~Wordlist() {
+}
+
+Parser::Parser() {
+ list = NULL;
+ _dels = new ParserDelegateList;
+}
+
+void Parser::loadList(const string &locale) {
+#ifdef DEBUG_OUTPUT
+ cout << "Loading locale " << locale << ".." << endl;
+#endif
+
+ // Find the wordlist on file.
+ if (list != NULL)
+ delete list;
+ Wordlist *list = new Wordlist(locale);
+ loadList(*list);
+}
+
+void Parser::loadList(Wordlist &preloadedList) {
+#ifdef DEBUG_OUTPUT
+ cout << "Using pre-loaded wordlist..." << endl;
+#endif
+ list = &preloadedList;
+ generateNodes();
+}
+
+Wordlist* Parser::getList() {
+ return this->list;
+}
+
+const int Parser::getLexicalCount() const {
+ return LexicalNode::count();
+}
+
+const long Parser::toID(const string &text) const {
+ return LexicalNode::toID(text);
+}
+
+void Parser::parseText(const string &text) {
+ /**
+ * @todo: Tokenize a string.
+ * @todo: Start the parsing loop.
+ */
+
+ // start @TODO1
+ char *str = const_cast<char*> (text.c_str());
+ char *token = strtok(str, " ");
+ StringVector tokens;
+
+ while (token != NULL) {
+ tokens.push_back(token);
+ cout << "'" << token << "': " << LexicalNode::toID(token) << endl;
+ token = strtok(NULL, " ");
+ }
+ // end @TODO1
+
+ cout << this->_dels->size() << " wordclass handlers loaded for " << tokens.size() << " words." << endl;
+
+ // start @TODO2
+ doParse(tokens);
+ // end @TODO2
+}
+
+void Parser::doParse(StringVector const &tokens) {
+ NodeVector theNodes;
+ int intPaths = 1;
+
+ // Remove the need to play with the tokens.
+ // In layman terms, translate from a lexicon to its internal form.
+ for (StringVector::const_iterator i = tokens.begin(); i != tokens.end(); i++) {
+ string currentWord = *i, theWord;
+
+ theWord.reserve(currentWord.size());
+
+ // @note: This part needs a bit of work, we'll need to flag certain words as so:
+ // at least for English..
+ // "word", (word), [word] = psuedo word
+ // word(.,!:?) = punctaction.
+ // **numerical value** = how should we save numbers?
+ for (int k = 0; k < currentWord.size(); k++) {
+ if (!isalpha(currentWord.at(k)))
+ continue;
+ else
+ theWord += tolower(currentWord.at(k));
+ }
+
+ SyntacticNode *synNode;
+ long theWordHash = LexicalNode::toID(theWord);
+ if (LexicalNode::exists(theWordHash)) {
+ LexicalNode *aWord = LexicalNode::fromID(theWordHash);
+ StringVector flags = LexicalLink::obtainFlagsFor(aWord, NULL);
+ NodeVector allMeanings = LexicalLink::getMeaningOf(aWord);
+ intPaths *= allMeanings.size();
+ if (allMeanings.size() != 0)
+ synNode = SyntacticNode::build(allMeanings.at(0)->getID(), flags.at(0), theWord);
+ } else
+ synNode = SyntacticNode::buildPsuedo(theWord);
+
+ if (synNode != NULL)
+ theNodes.push_back(synNode);
+ else
+ cout << "No meanings were found for '" << theWord << "'" << endl;
+ }
+
+ Interlinguish anArray = (Interlinguish) theNodes;
+#ifdef DEBUG_OUTPUT
+ cout << intPaths << " paths detected." << endl;
+#endif
+ anArray.parse(this);
+}
+
+void Parser::generateNodes() {
+ for (int i = 0; i < list->size(); i++) {
+ long lex = LexicalNode::toID(list->at(i));
+
+ if (!LexicalNode::exists(lex) && (LexicalNode::fromID(lex) == NULL))
+ cout << "Word #" << lex << " cannot be loaded.";
+ }
+}
+
+void Parser::createStore() {
+}
+
+const bool Parser::storeExists() {
+}
+
+SyntacticLink* Parser::parseWord(NodeVector::iterator &i, Interlinguish &wordlist) {
+ SyntacticNode *word = reinterpret_cast<SyntacticNode*> (*i);
+ ParserDelegateList::const_iterator itr = this->_dels->find(word->getType());
+ if (itr != this->_dels->end()) {
+ const ParserSignal *delegate = &itr->second;
+ return delegate->emit(i, wordlist);
+ }
+
+ return NULL;
+}
+
+ParserSignal* Parser::signalHandler(const char type) {
+ if (this->_dels->find(type) == this->_dels->end()) {
+ ParserSignal *sig = new ParserSignal;
+ this->_dels->insert(ParserDelegateList::value_type(type, *sig));
+ }
+ return &(this->_dels->find(type)->second);
+}
+
+Parser::~Parser() {
+}
+
+Interlinguish::Interlinguish() {
+ _nodes = NULL;
+}
+
+Interlinguish::Interlinguish(const NodeVector &nodes) {
+ _nodes = const_cast<NodeVector*> (&nodes);
+}
+
+SyntacticNode* Interlinguish::at(const int index) const {
+ if (index > -1 && index < this->_nodes->size())
+ return reinterpret_cast<SyntacticNode*> (this->_nodes->at(index));
+ else
+ return NULL;
+}
+
+void Interlinguish::parse(Parser *parser) {
+ if (_nodes == NULL)
+ return;
+
+ LinkVector links;
+ links.resize(0, NULL);
+
+ for (NodeVector::iterator i = _nodes->begin(); i != _nodes->end(); i++) {
+
+ SyntacticLink *aLink = parser->parseWord(i, *this);
+ if (aLink != NULL)
+ links.push_back(aLink);
+ }
+#ifdef DEBUG_OUTPUT
+ cout << links.size() << " syntactic links found." << endl;
+#endif
+}
+
+Interlinguish::~Interlinguish() {
+}
\ No newline at end of file
=== added file 'parser.hpp'
--- parser.hpp 1970-01-01 00:00:00 +0000
+++ parser.hpp 2011-03-26 23:34:24 +0000
@@ -0,0 +1,129 @@
+/**
+ * File: parser.hpp
+ * Author: Jacky Alcine <jackyalcine@xxxxxxxxx>
+ * Created on January 26, 2011, 8:42 PM
+ *
+ * Copyright (c) SII 2010 - 2011
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * @consider: A storage template class for Nodes?
+ * @description Header information for the Panlingua network.
+ * @note Implement hashing and a cache
+ */
+
+#include "core.hpp"
+#include <sigc++/sigc++.h>
+#include <string>
+#include <vector>
+#include <map>
+
+#ifndef PARSER_HPP
+#define PARSER_HPP
+
+namespace Wintermute {
+ namespace Linguistics {
+ typedef SyntacticLink* (ParserDelegate) (NodeVector::iterator &, Interlinguish &);
+ typedef sigc::signal<SyntacticLink*, NodeVector::iterator&, Interlinguish &> ParserSignal;
+ typedef map<char, ParserSignal> ParserDelegateList;
+ class Wordlist;
+ class Parser;
+
+ enum SUBJECTSTATES {
+ SUBJECTSTATE_DELAYED = 0,
+ SUBJECTSTATE_SIMPLE,
+ SUBJECTSTATE_COMPLETE,
+ SUBJECTSTATE_COMPOUND
+ };
+
+ enum PREDICATESTATES {
+ PREDICATESTATE_SIMPLE = 0,
+ PREDICATESTATE_COMPLETE,
+ PREDICATESTATE_COMPOUND
+ };
+
+ enum STATEMENTKINDS {
+ STATEMENTKIND_DECLARATIVE = 0,
+ STATEMENTKIND_INTERROGATIVE,
+ STATEMENTKIND_IMPERATIVE,
+ STATEMENTKIND_EXCLAMATORY,
+ STATEMENTKIND_CONDITIONAL
+ };
+
+ enum SENTENCETYPES {
+ SENTENCETYPE_SIMPLE = 0,
+ SENTENCETYPE_COMPOUND,
+ SENTENCETYPE_COMPLEX
+ };
+
+ class Parser {
+ friend class Interlinguish;
+ private:
+ Wordlist *list;
+ ParserDelegateList *_dels;
+ SyntacticLink* parseWord(NodeVector::iterator &, Interlinguish &);
+ void doParse(StringVector const &);
+ void generateNodes();
+
+ protected:
+ ParserSignal* signalHandler(const char);
+
+ public:
+ Parser();
+ ~Parser();
+ void loadList(const string &);
+ void loadList(Wordlist &);
+ void parseText(const string &);
+ Wordlist* getList();
+ const int getLexicalCount()const;
+ const long toID(const string &) const;
+ static void createStore();
+ const static bool storeExists();
+ };
+
+ class Wordlist {
+ private:
+ StringVector *_words;
+ string _uri;
+
+ public:
+ Wordlist();
+ Wordlist(const string &);
+ Wordlist(const Wordlist &);
+ ~Wordlist();
+ void load(const string & = "en");
+ void append(const string& = NULL);
+ void save();
+ const int size() const;
+ const string at(const int& = 0) const;
+ const int at(const string &) const;
+ const bool has(const string &) const;
+ string & operator[](int &);
+ const string & operator[](int &) const;
+ };
+
+ class Sentence {
+ public:
+ Sentence();
+ ~Sentence();
+ const NodeVector* getSubject(const SUBJECTSTATES & = SUBJECTSTATE_SIMPLE) const;
+ const NodeVector* getPredicate(const PREDICATESTATES & = PREDICATESTATE_SIMPLE) const;
+ const NodeVector* getDirectObjects();
+ const bool isSubjectDelayed() const;
+ const STATEMENTKINDS getKind() const;
+ const SENTENCETYPES getType() const;
+ };
+ }
+}
+#endif /* PARSER_HPP */
+
Follow ups