<commit_before>using System;
using System.Xml;
using System.Collections;

namespace Uiml.Peers
{
	/// <summary>
	/// Summary description for Vocabulary.
	/// </summary>
	public class Vocabulary
	{
		// a Hashtable of (name, DClass) key-value pairs
		protected Hashtable m_dictDCls;
		// a Hashtable of (name, DComponent) key-value pairs
		protected Hashtable m_dictDCmp;
		protected string m_identifier;
		protected XmlDocument m_doc;
		protected string m_vocName;

		public Vocabulary()
		{
			m_dictDCls = new Hashtable();
			m_dictDCmp = new Hashtable();
		}

		public Vocabulary(string vocName)
		{
			m_dictDCls = new Hashtable();
			m_dictDCmp = new Hashtable();
			m_vocName = vocName;
			
			Load(vocName);
		}

		protected void Load(string vocName)
		{
			//first try to load the string "as is". If this does not work
			//try to load the online vocabulary provided this exists
			m_doc = new XmlDocument();
			XmlTextReader xr = null;
			try
			{
				xr = new XmlTextReader(vocName);
				m_doc.Load(xr);
				Parse();
			}
			catch(XmlException xe)
			{
				Console.WriteLine("Could not load {0} because of: ", vocName);
				Console.WriteLine(xe);
				Console.WriteLine("Trying other possible vocabulary locations...");
				try
				{
					xr = new XmlTextReader(VOCABULARY_BASE + vocName + VOCABULARY_EXT);
					m_doc.Load(xr);
					Parse();
				}
				catch(Exception e)
				{
					xr = new XmlTextReader(VOCABULARY_BASE2 + vocName + VOCABULARY_EXT);
					m_doc.Load(xr);
					Parse();				
				}
			}
			catch(Exception e)
			{						
				Console.WriteLine(e);
			}				
		}

		public void MergeLogic(Logic l)
		{
			XmlNode logicNode = m_doc.ImportNode(l.Tag, true);

			XmlNode n = MoveToUimlElement(m_doc);
						
			if(n != null)
			{
				n.AppendChild(logicNode);			
				ParseLogic(logicNode);
			}
			else
				throw new Exception("UIML file not in correct format. Could not find uiml element.");
		}

		protected void Parse(XmlNode n)
		{
			IEnumerator enumNodes = n.ChildNodes.GetEnumerator();

			while(enumNodes.MoveNext())
			{
				XmlNode c = (XmlNode) enumNodes.Current;
				switch(c.Name)
				{
					case Presentation.IAM:
						ParsePresentation(c);
						break;
					case Logic.IAM:
						ParseLogic(c);
						break;
				}
			}
		}

		protected void Parse()
		{
			XmlNode n = MoveToUimlElement(m_doc);
			
			if(n != null)
				Parse(n);
			else
				throw new Exception("Vocabulary not in correct format. Could not find uiml element.");
		}

		protected XmlNode MoveToUimlElement(XmlNode n)
		{
			n = n.FirstChild;

			while(n != null && n.Name != "uiml")			
			{
				n = n.NextSibling;
			}
			
			return n;
		}

		protected void ParsePresentation(XmlNode n)
		{
			XmlNode b = n.Attributes.GetNamedItem(Presentation.BASE);
			
			try
			{
				m_identifier = b.Value;
			}
			catch(NullReferenceException nre)
			{
				Console.WriteLine("The presentation has no base attribute, please check your UIML file!");
				Console.WriteLine(nre.StackTrace);
			}			

			IEnumerator enumChildren = n.ChildNodes.GetEnumerator();
			
			while(enumChildren.MoveNext())
			{
				XmlNode c = (XmlNode) enumChildren.Current;
				switch(c.Name)
				{
					case DClass.IAM:
						ParseDClass(c);
						break;
				}
			}
		}

		protected void ParseLogic(XmlNode n)
		{
			IEnumerator enumChildren = n.ChildNodes.GetEnumerator();
			
			while(enumChildren.MoveNext())
			{
				XmlNode c = (XmlNode) enumChildren.Current;
				switch(c.Name)
				{
					case DComponent.IAM:
						ParseDComponent(c);<commit_msg>Fixed notification of a NullReferenceException.<commit_after>using System;
using System.Xml;
using System.Collections;

namespace Uiml.Peers
{
	/// <summary>
	/// Summary description for Vocabulary.
	/// </summary>
	public class Vocabulary
	{
		// a Hashtable of (name, DClass) key-value pairs
		protected Hashtable m_dictDCls;
		// a Hashtable of (name, DComponent) key-value pairs
		protected Hashtable m_dictDCmp;
		protected string m_identifier;
		protected XmlDocument m_doc;
		protected string m_vocName;

		public Vocabulary()
		{
			m_dictDCls = new Hashtable();
			m_dictDCmp = new Hashtable();
		}

		public Vocabulary(string vocName)
		{
			m_dictDCls = new Hashtable();
			m_dictDCmp = new Hashtable();
			m_vocName = vocName;
			
			Load(vocName);
		}

		protected void Load(string vocName)
		{
			//first try to load the string "as is". If this does not work
			//try to load the online vocabulary provided this exists
			m_doc = new XmlDocument();
			XmlTextReader xr = null;
			try
			{
				xr = new XmlTextReader(vocName);
				m_doc.Load(xr);
				Parse();
			}
			catch(XmlException xe)
			{
				Console.WriteLine("Could not load {0} because of: ", vocName);
				Console.WriteLine(xe);
				Console.WriteLine("Trying other possible vocabulary locations...");
				try
				{
					xr = new XmlTextReader(VOCABULARY_BASE + vocName + VOCABULARY_EXT);
					m_doc.Load(xr);
					Parse();
				}
				catch(Exception e)
				{
					xr = new XmlTextReader(VOCABULARY_BASE2 + vocName + VOCABULARY_EXT);
					m_doc.Load(xr);
					Parse();				
				}
			}
			catch(Exception e)
			{						
				Console.WriteLine(e);
			}				
		}

		public void MergeLogic(Logic l)
		{
			XmlNode logicNode = m_doc.ImportNode(l.Tag, true);

			XmlNode n = MoveToUimlElement(m_doc);
						
			if(n != null)
			{
				n.AppendChild(logicNode);			
				ParseLogic(logicNode);
			}
			else
				throw new Exception("UIML file not in correct format. Could not find uiml element.");
		}

		protected void Parse(XmlNode n)
		{
			IEnumerator enumNodes = n.ChildNodes.GetEnumerator();

			while(enumNodes.MoveNext())
			{
				XmlNode c = (XmlNode) enumNodes.Current;
				switch(c.Name)
				{
					case Presentation.IAM:
						ParsePresentation(c);
						break;
					case Logic.IAM:
						ParseLogic(c);
						break;
				}
			}
		}

		protected void Parse()
		{
			XmlNode n = MoveToUimlElement(m_doc);
			
			if(n != null)
				Parse(n);
			else
				throw new Exception("Vocabulary not in correct format. Could not find uiml element.");
		}

		protected XmlNode MoveToUimlElement(XmlNode n)
		{
			n = n.FirstChild;

			while(n != null && n.Name != "uiml")			
			{
				n = n.NextSibling;
			}
			
			return n;
		}

		protected void ParsePresentation(XmlNode n)
		{
			XmlNode b = n.Attributes.GetNamedItem(Presentation.BASE);
			
			try
			{
				m_identifier = b.Value;
			}
			catch(NullReferenceException nre)
			{
				Console.WriteLine("The presentation has no base attribute, please check your UIML file!");
				Console.WriteLine(nre);
			}			

			IEnumerator enumChildren = n.ChildNodes.GetEnumerator();
			
			while(enumChildren.MoveNext())
			{
				XmlNode c = (XmlNode) enumChildren.Current;
				switch(c.Name)
				{
					case DClass.IAM:
						ParseDClass(c);
						break;
				}
			}
		}

		protected void ParseLogic(XmlNode n)
		{
			IEnumerator enumChildren = n.ChildNodes.GetEnumerator();
			
			while(enumChildren.MoveNext())
			{
				XmlNode c = (XmlNode) enumChildren.Current;
				switch(c.Name)
				{
					case DComponent.IAM:
						ParseDComponent(c);
{'fraction_non_alphanumeric': 0.10778612962700326, 'fraction_numerical': 0.0005672954190894909, 'mean_word_length': 2.7057277982133474, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3480566', 'n_tokens_mistral': 3165, 'n_tokens_neox': 2424, 'n_words': 559}