Search code examples
dotnetrdf

NTriplesParser extract textual value from string


I am using dotnetrdf and trying to parse some triples with NTriplesParser. I have my own handler RobHandler in which I process each triple in turn.

public class RobHandler : BaseRdfHandler
{
    protected override bool HandleTripleInternal(Triple t)
    {
        string predicateUrl = ((BaseUriNode)(t.Predicate)).Uri.AbsoluteUri;
        string value = t.Object.ToString();
    }
}

This works fine but I want to get the object minus the language. My objects look like "Lincoln"@en. I could obviously write some code to remove the @en bit, but I'd rather use some library code rather than my own that hard-coded strings like @en. To do this I think I need to create a LiteralNode but there doesn't seem to be a way to get from a string which is what I have (my variable value) to a LiteralNode.

How can I extract just the textual value from an object string?


Solution

  • Actually I think I have the answer myself:

      if (t.Object.NodeType == NodeType.Literal)
      {
          var node = (ILiteralNode)t.Object;
      }