Click here to Skip to main content
15,892,059 members
Articles / Desktop Programming / Win32

True Natural Language Understanding through a Conceptual Language Understanding Engine

Rate me:
Please Sign up or sign in to vote.
4.97/5 (55 votes)
11 Jan 201029 min read 68K   3.1K   118  
An article introducing an Artificial Intelligence technique that understands and manipulates concepts from text.
/*
The usage of this source code file, including but not limited to the reading, the compilation and 
redistribution, is subject to the license agreement detailed in the license.txt and license.pdf files
which accompany this source code. By proceeding to use this file you are acknowledging that you have
read either license.txt or license.pdf, and that you agree to be bound by the terms and conditions of
the license. If license.txt and license.pdf are not available, you are not licensed this file and you 
must delete it permanently; or contact the author at proy@conceptualspeech.com to obtain a copy of 
the license before proceeding to use this file.

Copyright Philippe Roy 2010 - proy@conceptualspeech.com.
*/

#ifndef __POSNODE_H__
#define __POSNODE_H__

#include "shared_auto_ptr.h"
#include "JSObjectSupport.h"

#include <string>
#include <vector>
#include "POSEntry.h"
#include "Predicate.h"

using std::string;
using std::vector;

class POSNode: public JSObjectSupport<POSNode>
{
	public:
		enum ESortType
		{
			eNoSort = 0,
			eSortLargestToSmallestNode = 1,
			eSortSmallestToLargestNode = 2
		};
		enum EDirection
		{
			eSibling = 0,
			eSiblingLeft = 1,
			eSiblingRight = 2,
			eFirstSibling = 3,
			eLastSibling = 4,
			eNextSibling = 5,
			ePreviousSibling = 6,
			eAncestre = 7,
			eParent = 8,
			eTopParent = 9,
			eChild = 10,
			eFirstChild = 11,
			eLastChild = 12,
			eDescendant = 13,
			ePreviousWord = 14,
			eNextWord = 15,
			eFirstWord = 16,
			eLastWord = 17
		};
		static shared_auto_ptr<POSNode> Construct(string dNodeDesc, vector<shared_auto_ptr<POSNode>> *allPOSNodes = NULL, 
			unsigned int dStartPosition = 0, unsigned int dEndPosition = 0, unsigned int dBridgePosition = 0, string data = "");
		static void ConstructSequence(string dSequence, vector<shared_auto_ptr<POSNode>> *allPOSNodes);
		POSNode();
		POSNode(POSEntry dPOS, 
			string dSpelling = "", 
			unsigned int dStartPosition = 0, 
			unsigned int dEndPosition = 0, 
			unsigned int dBridgePosition = 0,
			string data = "");
		virtual ~POSNode();
		string GetNodeDesc();
		void SetParent(shared_auto_ptr<POSNode> dParent);
		unsigned int GetStartPosition();
		unsigned int GetEndPosition();
		unsigned int GetBridgePosition();
		virtual void ClearAnalyzed(bool includingSelf);
		void SetBridgePosition(unsigned int dPosition);
		POSEntry GetPOSEntry() { return m_POS; }
		virtual int CompareSpellings(POSNode &dNode);
		virtual int Compare(POSNode &dNode);
		virtual string GetSpelling(int debugLevel = 0);
		virtual string GetID();
		virtual string GetData();
		virtual void SetData(string data);
		virtual shared_auto_ptr<POSNode> Navigate(EDirection direction, POSNode *constraint = NULL);
		virtual void ManageTransientParents(Persistent<Context> context, bool recursive = false);
		virtual void UpdateFromChildValues();
		static bool CompareNodes(shared_auto_ptr<POSNode> elem1, shared_auto_ptr<POSNode> elem2);
		virtual void SetSortRequirement(ESortType dRequirement);
		virtual void SetConstructionLine(string dLine);
		virtual string GetConstructionLine();
		virtual vector<shared_auto_ptr<CPredicate>> BuildPredicates(string wpstr = "");
		virtual void AddInitializer(string dPredicateString) throw();
		virtual void SetWordIndex(unsigned int dIndex) throw();
		virtual unsigned int GetWordIndex() const throw();
		virtual void UpdateNodesCount() throw();
		virtual string Inspect(int indentCount) throw();
		int ChildNodeCount();
		virtual shared_auto_ptr<POSNode> GetChild(int index);
		virtual shared_auto_ptr<POSNode> GetParent();
		virtual void SetSpelling(string dSpelling);
		virtual void SetStartPosition(unsigned int dPosition);
		virtual void SetEndPosition(unsigned int dPosition);
		virtual void UpdateDebugStrings();
		virtual void SetTransientParent(shared_auto_ptr<POSNode> dTransientParent);
		virtual bool HasConceptualDefinition();
		virtual void OutputTransformLineInfo();
	protected:
		virtual bool ValidatePredicates();
		virtual void AddPredicate(shared_auto_ptr<CPredicate> dPredicate, bool bringUp);
		virtual bool IsLeaf();
		virtual void FlagPacketAnalyzed();
		virtual bool Analyzed();
		static int m_maxSpellingLength;
		Persistent<Context> m_context;
		POSEntry m_POS;
		string m_spelling;
		string m_constructionLine;
		string m_data;
		POSNode* m_transientParent;
		vector<shared_auto_ptr<POSNode>> m_children;
		unsigned int m_startPosition;
		unsigned int m_endPosition;
		unsigned int m_bridgePosition;
		unsigned int m_wordIndex;
		unsigned int m_totalNodesUnder;
		ESortType m_sortRequirement;
		vector<shared_auto_ptr<CPredicate>> m_initializers;
		vector<shared_auto_ptr<CPredicate>> m_predicates;
		int m_inCurInitializer;
		bool m_analyzed;
		bool m_hasConceptualDefinition;
		EPredicateCalculusCycle m_curCycle;
		string m_debugString;
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Canada Canada
Philippe Roy was a key contributor throughout his 20+ years career with many high-profile companies such as Nuance Communications, IBM (ViaVoice and ProductManager), VoiceBox Technologies, just to name a few. He is creative and proficient in OO coding and design, knowledgeable about the intellectual-property world (he owns many patents), tri-lingual, and passionate about being part of a team that creates great solutions.

Oh yes, I almost forgot to mention, he has a special thing for speech recognition and natural language processing... The magic of first seeing a computer transform something as chaotic as sound and natural language into intelligible and useful output has never left him.

Comments and Discussions