本文整理汇总了C#中VDS.RDF.Parsing.SparqlQueryParser类的典型用法代码示例。如果您正苦于以下问题:C# SparqlQueryParser类的具体用法?C# SparqlQueryParser怎么用?C# SparqlQueryParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparqlQueryParser类属于VDS.RDF.Parsing命名空间,在下文中一共展示了SparqlQueryParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SparqlBindLazy
public void SparqlBindLazy()
{
String query = "PREFIX fn: <" + XPathFunctionFactory.XPathFunctionsNamespace + "> SELECT ?triple WHERE { ?s ?p ?o . BIND(fn:concat(STR(?s), ' ', STR(?p), ' ', STR(?o)) AS ?triple) } LIMIT 1";
TripleStore store = new TripleStore();
Graph g = new Graph();
FileLoader.Load(g, "InferenceTest.ttl");
store.Add(g);
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString(query);
Console.WriteLine(q.ToAlgebra().ToString());
Assert.IsTrue(q.ToAlgebra().ToString().Contains("LazyBgp"), "Should have been optimised to use a Lazy BGP");
Console.WriteLine();
Object results = q.Evaluate(store);
if (results is SparqlResultSet)
{
SparqlResultSet rset = (SparqlResultSet)results;
foreach (SparqlResult r in rset)
{
Console.WriteLine(r.ToString());
}
Assert.IsTrue(rset.Count == 1, "Expected exactly 1 results");
Assert.IsTrue(rset.All(r => r.HasValue("triple")), "All Results should have had a value for ?triple");
}
else
{
Assert.Fail("Expected a SPARQL Result Set");
}
}
示例2: BindRdfDataObjects
public IEnumerable<IDataObject> BindRdfDataObjects(XDocument rdfXmlDocument,
IList<OrderingDirection> orderingDirections)
{
var g = new Graph();
#if PORTABLE || WINDOWS_PHONE
var parser = new RdfXmlParser(RdfXmlParserMode.Streaming);
// This is pretty nasty, having to deserialize only to go through parsing again
parser.Load(g, new System.IO.StringReader(rdfXmlDocument.ToString()));
#else
var parser = new RdfXmlParser(RdfXmlParserMode.DOM);
parser.Load(g, rdfXmlDocument.AsXmlDocument());
#endif
var p = new VDS.RDF.Query.LeviathanQueryProcessor(new InMemoryDataset(g));
var queryString = MakeOrderedResourceQuery(orderingDirections);
var sparqlParser = new SparqlQueryParser();
var query = sparqlParser.ParseFromString(queryString);
var queryResultSet = p.ProcessQuery(query) as VDS.RDF.Query.SparqlResultSet;
foreach (var row in queryResultSet.Results)
{
INode uriNode;
if (row.TryGetBoundValue("x", out uriNode) && uriNode is IUriNode)
{
yield return BindRdfDataObject(uriNode as IUriNode, g);
}
}
}
示例3: TestParser
public void TestParser()
{
const string exp = "select ?t where { ?t a ?tt }";
var parser = new SparqlQueryParser();
var query = parser.ParseFromString(exp);
Assert.IsNotNull(query);
}
示例4: SparqlDefaultGraphExists3
public void SparqlDefaultGraphExists3()
{
SqlDataset dataset = new SqlDataset(new MicrosoftSqlStoreManager("localhost", "unit_test", "example", "password"));
//Create Default Graph only if required
if (!dataset.HasGraph(null))
{
Graph g = new Graph();
g.Assert(g.CreateUriNode(new Uri("http://example.org/subject")), g.CreateUriNode(new Uri("http://example.org/predicate")), g.CreateUriNode(new Uri("http://example.org/object")));
dataset.AddGraph(g);
dataset.Flush();
}
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString("ASK WHERE { GRAPH ?g { ?s ?p ?o }}");
LeviathanQueryProcessor lvn = new LeviathanQueryProcessor(dataset);
Object results = lvn.ProcessQuery(q);
if (results is SparqlResultSet)
{
Assert.IsTrue(((SparqlResultSet)results).Result);
}
else
{
Assert.Fail("ASK Query did not return a SPARQL Result Set as expected");
}
dataset.Flush();
}
示例5: SparqlFunctionsIsNumeric
public void SparqlFunctionsIsNumeric()
{
Graph g = new Graph();
IUriNode subj = g.CreateUriNode(new Uri("http://example.org/subject"));
IUriNode pred = g.CreateUriNode(new Uri("http://example.org/predicate"));
g.Assert(subj, pred, (12).ToLiteral(g));
g.Assert(subj, pred, g.CreateLiteralNode("12"));
g.Assert(subj, pred, g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeNonNegativeInteger)));
g.Assert(subj, pred, g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeNonPositiveInteger)));
g.Assert(subj, pred, g.CreateLiteralNode("1200", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)));
g.Assert(subj, pred, ((byte)50).ToLiteral(g));
g.Assert(subj, pred, g.CreateLiteralNode("-50", new Uri(XmlSpecsHelper.XmlSchemaDataTypeByte)));
g.Assert(subj, pred, g.CreateLiteralNode("-50", new Uri(XmlSpecsHelper.XmlSchemaDataTypeUnsignedByte)));
g.Assert(subj, pred, g.CreateUriNode(new Uri("http://example.org")));
TripleStore store = new TripleStore();
store.Add(g);
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString("SELECT ?obj (IsNumeric(?obj) AS ?IsNumeric) WHERE { ?s ?p ?obj }");
Object results = store.ExecuteQuery(q);
Assert.IsTrue(results is SparqlResultSet, "Result should be a SPARQL Result Set");
TestTools.ShowResults(results);
}
示例6: fclsInspect
public fclsInspect(SparqlQuery query, long parseTime, String origQuery)
{
InitializeComponent();
this.lblParseTime.Text = "Took " + parseTime + "ms to parse";
this.txtQuery.Text = this._formatter.Format(query);
this.txtAlgebra.Text = query.ToAlgebra().ToString();
//Compute the actual syntax compatability
SparqlQueryParser parser = new SparqlQueryParser();
parser.SyntaxMode = SparqlQuerySyntax.Sparql_1_0;
try
{
SparqlQuery q = parser.ParseFromString(origQuery);
this.lblSyntaxCompatability.Text += " SPARQL 1.0 (Standard)";
}
catch
{
try
{
parser.SyntaxMode = SparqlQuerySyntax.Sparql_1_1;
SparqlQuery q = parser.ParseFromString(origQuery);
this.lblSyntaxCompatability.Text += " SPARQL 1.1 (Current Working Draft Standard)";
}
catch
{
parser.SyntaxMode = SparqlQuerySyntax.Extended;
SparqlQuery q = parser.ParseFromString(origQuery);
this.lblSyntaxCompatability.Text += " SPARQL 1.1 (Implementation specific extensions)";
}
}
}
示例7: ExecuteQuery
public SparqlResult ExecuteQuery(SparqlQueryContext queryContext, IList<string> datasetGraphUris)
{
var parser = new SparqlQueryParser();
var query = parser.ParseFromString(queryContext.SparqlQuery);
var sparqlResults = _queryProcessor.ProcessQuery(query);
return new SparqlResult(sparqlResults, queryContext);
}
示例8: SparqlGroupByAssignmentExpression
public void SparqlGroupByAssignmentExpression()
{
String query = "SELECT ?s ?sum WHERE { ?s ?p ?o } GROUP BY ?s (1 + 2 AS ?sum)";
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString(query);
SparqlFormatter formatter = new SparqlFormatter();
Console.WriteLine(formatter.Format(q));
Console.WriteLine();
QueryableGraph g = new QueryableGraph();
FileLoader.Load(g, "InferenceTest.ttl");
Object results = g.ExecuteQuery(q);
if (results is SparqlResultSet)
{
SparqlResultSet rset = (SparqlResultSet)results;
TestTools.ShowResults(rset);
Assert.IsTrue(rset.All(r => r.HasValue("s") && r.HasValue("sum")), "All Results should have a ?s and a ?sum variable");
}
else
{
Assert.Fail("Didn't get a Result Set as expected");
}
}
示例9: SparqlAlgebraReverseSimple
public void SparqlAlgebraReverseSimple()
{
List<String> tests = new List<string>()
{
"SELECT * WHERE { ?s ?p ?o }",
"SELECT ?s WHERE { ?s ?p ?o }",
"SELECT ?p ?o WHERE { ?s ?p ?o }",
"PREFIX fn: <" + XPathFunctionFactory.XPathFunctionsNamespace + "> SELECT (fn:concat(?s, ?p) AS ?string) WHERE {?s ?p ?o}",
"SELECT * WHERE {?s ?p ?o . ?o ?x ?y }",
"SELECT * WHERE {?s ?p ?o . OPTIONAL {?o ?x ?y} }",
"SELECT * WHERE {?s ?p ?o . OPTIONAL {?o ?x ?y . FILTER(BOUND(?s)) } }"
};
SparqlQueryParser parser = new SparqlQueryParser();
foreach (String test in tests)
{
Console.WriteLine("Test Input:");
Console.WriteLine(test);
Console.WriteLine();
Console.WriteLine("Parsed Query:");
SparqlQuery q = parser.ParseFromString(test);
Console.WriteLine(q.ToString());
Console.WriteLine();
Console.WriteLine("Algebra:");
Console.WriteLine(q.ToAlgebra().ToString());
Console.WriteLine();
Console.WriteLine("Algebra Reverse Transformed to Query:");
Console.WriteLine(q.ToAlgebra().ToQuery().ToString());
Console.WriteLine();
Console.WriteLine();
}
}
示例10: SparqlBind
public void SparqlBind()
{
String query = "PREFIX fn: <" + XPathFunctionFactory.XPathFunctionsNamespace + "> SELECT ?triple WHERE { ?s ?p ?o . BIND(fn:concat(STR(?s), ' ', STR(?p), ' ', STR(?o)) AS ?triple) }";
TripleStore store = new TripleStore();
Graph g = new Graph();
FileLoader.Load(g, "InferenceTest.ttl");
store.Add(g);
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString(query);
Object results = q.Evaluate(store);
if (results is SparqlResultSet)
{
SparqlResultSet rset = (SparqlResultSet)results;
foreach (SparqlResult r in rset)
{
Console.WriteLine(r.ToString());
}
Assert.IsTrue(rset.Count > 0, "Expected 1 or more results");
}
else
{
Assert.Fail("Expected a SPARQL Result Set");
}
}
示例11: Execute
static object Execute(TripleStore store, string sparql)
{
InMemoryDataset ds = new InMemoryDataset(store);
ISparqlQueryProcessor processor = new LeviathanQueryProcessor(ds);
SparqlQueryParser sparqlparser = new SparqlQueryParser();
SparqlQuery query = sparqlparser.ParseFromString(sparql);
return processor.ProcessQuery(query);
}
示例12: BaseSparqlView
/// <summary>
/// Creates a new SPARQL View
/// </summary>
/// <param name="sparqlQuery">SPARQL Query</param>
/// <param name="store">Triple Store to query</param>
public BaseSparqlView(String sparqlQuery, ITripleStore store)
{
SparqlQueryParser parser = new SparqlQueryParser();
this._q = parser.ParseFromString(sparqlQuery);
this._store = store;
this._async = new UpdateViewDelegate(this.UpdateViewInternal);
this.Initialise();
}
示例13: Setup
public void Setup()
{
this._parser = new SparqlQueryParser();
TripleStore store = new TripleStore();
Graph g = new Graph();
FileLoader.Load(g, "describe-algos.ttl");
store.Add(g);
this._data = new InMemoryDataset(store);
}
示例14: ParseSparql
public static SparqlQuery ParseSparql(string exp)
{
var parser = new SparqlQueryParser(SparqlQuerySyntax.Extended);
var expressionFactories = parser.ExpressionFactories.ToList();
expressionFactories.Add(new BrightstarFunctionFactory());
parser.ExpressionFactories = expressionFactories;
var query = parser.ParseFromString(exp);
return query;
}
示例15: SparqlResultSetToDataTable2
public void SparqlResultSetToDataTable2()
{
String query = "PREFIX ex: <http://example.org/vehicles/> SELECT * WHERE {?s a ex:Car . OPTIONAL { ?s ex:Speed ?speed }}";
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery q = parser.ParseFromString(query);
Graph g = new Graph();
FileLoader.Load(g, "InferenceTest.ttl");
Object results = g.ExecuteQuery(q);
if (results is SparqlResultSet)
{
SparqlResultSet rset = (SparqlResultSet)results;
DataTable table = new DataTable();
foreach (String var in rset.Variables)
{
table.Columns.Add(new DataColumn(var, typeof(INode)));
}
foreach (SparqlResult r in rset)
{
DataRow row = table.NewRow();
foreach (String var in rset.Variables)
{
if (r.HasValue(var))
{
row[var] = r[var];
}
else
{
row[var] = null;
}
}
table.Rows.Add(row);
}
Assert.AreEqual(rset.Variables.Count(), table.Columns.Count, "Number of Columns should be equal");
Assert.AreEqual(rset.Count, table.Rows.Count, "Number of Rows should be equal");
foreach (DataRow row in table.Rows)
{
foreach (DataColumn col in table.Columns)
{
Object temp = row[col];
Console.Write(col.ColumnName + " = " + ((temp != null) ? temp.ToString() : String.Empty) + " , ");
}
Console.WriteLine();
}
}
else
{
Assert.Fail("Query should have returned a Result Set");
}
}