|
From: Rob V. <rv...@do...> - 2015-06-22 15:14:41
|
Michael
No such method exists in the library because a nodes value is a possibly
complex and compound value.
Really it depends what you want to do, if you need to specifically act upon
the value somehow then generally speaking you do something like the
following:
switch (subject.NodeType)
{
case NodeType.Uri:
Uri u = ((IUriNode)subject).Uri;
// Act on the URI
break;
case NodeType.Literal:
String value = ((ILiteralNode)subject).Value;
// Act on the value
break;
// And so on
}
If you just need a textual value for display you can just call ToString() or
if you want a slightly more standard textual representation you can use a
INodeFormatter instead e.g.
NTriplesNodeFormatter formatter = new NTriplesNodeFormatter();
String text = formatter.Format(subject);
Hope this helps,
Rob
PS This is a subscription based list, your email was moderated through and
your email CC'd on this reply this time. Please subscribe at
https://lists.sourceforge.net/lists/listinfo/dotnetrdf-support if you want
to ask further questions
From: "Yuqian (Michael) Lu" <yl...@au...>
Reply-To: dotNetRDF User Help and Support
<dot...@li...>
Date: Wednesday, 17 June 2015 03:01
To: <dot...@li...>
Subject: [dotNetRDF-Support] dotNetRDF how to get the value from a INode
> Hi dotNetRDF Team,
>
> I am using dotNetRDF library to process my ontology in RDF/XML format.
>
> Following the tutorials on your website, I can easily get a triple from my
> graph and further get the INode I am interested in. Then I would like to
> retrieve the actual value from the resultant INode no matter it is actually a
> UriNode or a LiteralNode. So I was wondering if there is some method in
> dotNetRDF that I can use to extract the value from INode?
>
> Below is the code:
> IUriNode rdfType = g.CreateUriNode("rdf:type");
> IUriNode projectType = g.CreateUriNode("ms:Project");
> IEnumerable<Triple> ts = g.GetTriplesWithPredicateObject(rdfType,
> projectType);
> foreach (var triple in ts)
> {
> //UriNode is in the format of [PrefixNamespaceURI]value.
> //LiteralNode is in the format of
> value^^[URIoftheBuiltinDataType]
> INode subject = triple.Subject;
> //Here I need some method to extract the value only
> ……………………………………
> }
>
> It would be much appreciated if you could provide some information on this.
>
> I am looking forward to hearing from you.
>
> Best regards,
>
> Michael
>
> ------------------------------------------------------------------------------
> _______________________________________________ dotNetRDF-Support mailing list
> dot...@li...
> https://lists.sourceforge.net/lists/listinfo/dotnetrdf-support
|