Con este método, usando la librería dotnetrdf en una aplicación web, podemos mostrar los valores asociados a las variables de una consulta SPARQL sin que se muestre el texto que identifica al tipo de dato o al idioma, etc.
private string GetINodeText(INode n)
{
String output = "";
if (n != null)
{
switch (n.NodeType)
{
case NodeType.Literal:
//For literals you only want the lexical value only so need to cast to
//literal and access the Value property
output = ((ILiteralNode)n).Value;
break;
default:
//For any other node we just want the string form so
//ToString() is sufficient
output = n.ToString();
break;
}
}
return output;
}
El parámetro que se pasa es el que se obtiene haciendo esto:
SparqlResultSet results = LoadFromEndPoint2("dbpedia.org/sparql", "dbpedia.org", query);
if (results != null)
{
foreach (SparqlResult result in results)
{
string text = GetINodeText(result.Value("varname"));
}
}
El método LoadFromEndPoint2 básicamente es esto:
private SparqlResultSet LoadFromEndPoint2(string ipaddress, string graph, string query)
{
try
{
SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://" + ipaddress), "http://" + graph);
endpoint.Timeout = 0;
SparqlResultSet results = endpoint.QueryWithResultSet(query);
return results;
}catch(Exception ex)
{
}
}
No hay comentarios:
Publicar un comentario