public static WordNode Parse(string source) {
if(source == null) {
throw new ArgumentNullException("source");
}
string trimmedSource = source.Trim();
var m = Regex.Match(trimmedSource, @"^(\w*)\((\w*)\)$"); //matches <text>(<tag>)
if(!m.Success) {
throw new FormatException("Provided string is not a valid WordNode string representation.");
}
string text = m.Groups[1].Value;
PartOfSpeechTag tag;
if(!Enum.TryParse<PartOfSpeechTag>(m.Groups[2].Value, out tag)) {
throw new FormatException("Invalid part-of-speech tag in string.");
}
return new WordNode(text, tag);
}