本文整理汇总了C#中SparqlResultSet.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# SparqlResultSet.ToList方法的具体用法?C# SparqlResultSet.ToList怎么用?C# SparqlResultSet.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparqlResultSet
的用法示例。
在下文中一共展示了SparqlResultSet.ToList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getLiterals
/// <summary>
/// get predicates is a method in lexicon class that get all LexiconLiterals objects that match some words in the Question
/// </summary>
/// <param name="question">question to get matched predicates of it </param>
/// <param name="topN">the number of top matching results to be returned, default = 10</param>
/// <param name="Limit">the limit of the number of returned results in the query, default = 20</param>
/// <returns>list of top matching LexiconLiterals with it's type of owner and predicate </returns>
public List<LexiconLiteral> getLiterals(string question, int topN = 10, int Limit = 20)
{
DateTime dt = DateTime.Now; // capturing time for testing
List<LexiconLiteral> __literalList = new List<LexiconLiteral>();
//getting all permutation of words formed from the question string
List<string> permutationList = getPermutations(question);
//removing permutations that most propbably wont return results and will take time in querying
permutationList = trimPermutations(permutationList);
// iterating over each permutation of Question left and Query them from virtuoso and return predicate list and add them
foreach (string questionleft in permutationList)
{
// Query 1 is suitable for Keywords like : United states which match the most popular resource
string Query1 = "SELECT distinct ?subject ?literal ?typeOfOwner " +
"where { " +
" ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?literal . " +
" optional { ?subject <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?typeOfOwner ." +
" ?literal bif:contains '\"" + questionleft + "\"' OPTION (score ?sc) . " +
"FILTER (" +
"!(?typeOfOwner = <http://www.w3.org/2002/07/owl#Thing> " +
"|| ?typeOfOwner = <http://www.w3.org/2004/02/skos/core#Concept> " +
"|| ?typeOfOwner = <http://www.w3.org/2002/07/owl#ObjectProperty> " +
"|| ?typeOfOwner = <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> " +
"|| ?typeOfOwner = <http://www.w3.org/2002/07/owl#DatatypeProperty>) " +
")" +
"} limit " + Limit;
// Query2 is suitable for Keywords like : USA , which match the redirections
string Query2 = "SELECT distinct ?subject ?literal ?typeOfOwner " +
"WHERE { " +
" ?subject2 <http://www.w3.org/2000/01/rdf-schema#label> ?literal . " +
" ?subject2 <http://dbpedia.org/ontology/wikiPageRedirects> ?subject ." +
" ?subject <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?typeOfOwner ." +
" ?literal bif:contains '\"" + questionleft + "\"' OPTION (score ?sc) ." +
"FILTER (" +
"!(?typeOfOwner = <http://www.w3.org/2002/07/owl#Thing> " +
"|| ?typeOfOwner = <http://www.w3.org/2004/02/skos/core#Concept> " +
"|| ?typeOfOwner = <http://www.w3.org/2002/07/owl#ObjectProperty> " +
"|| ?typeOfOwner = <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> " +
"|| ?typeOfOwner = <http://www.w3.org/2002/07/owl#DatatypeProperty>) " +
")" +
"} limit " + Limit;
SparqlRemoteEndpoint remoteEndPoint = new SparqlRemoteEndpoint(new Uri("http://localhost:8890/sparql"));
SparqlResultSet resultSet1 = new SparqlResultSet();
SparqlResultSet resultSet2 = new SparqlResultSet();
List<SparqlResult> resultSet = new List<SparqlResult>();
try
{
//executing the Query and finding results
resultSet1 = remoteEndPoint.QueryWithResultSet(Query1);
}
// skipping results that raised timeout exceptions
catch
{
util.log("skipped Query1 : " + questionleft + " ---- due to time out ");
}
try
{
resultSet2 = remoteEndPoint.QueryWithResultSet(Query2);
}
// skipping results that raised timeout exceptions
catch
{
util.log("skipped Query2: " + questionleft + " ---- due to time out ");
}
resultSet = (resultSet1.Count != 0) ? resultSet1.ToList<SparqlResult>() : resultSet;
resultSet = (resultSet2.Count != 0) ? resultSet.Concat<SparqlResult>(resultSet2.ToList<SparqlResult>()).ToList() : resultSet;
//iterating over matched Literals in the resultset
foreach (SparqlResult result in resultSet)
{
INode resourceURI = result.Value("subject");
INode literalLabel = result.Value("literal");
INode literalTypeOfOwner = result.Value("typeOfOwner");
// check that the predicate doesn't exists in the predicateslist before
bool exists = false; // URI + Label only Exists
bool totallyExists = false; // URI + Label + TypeofOwner exists in the literal list
foreach (LexiconLiteral x in __literalList)
{
if (x.URI == resourceURI.ToString() && x.label == literalLabel.ToString())
{
exists = true;
if (x.typeOfOwner.Contains(literalTypeOfOwner.ToString()))
{
totallyExists = true;
break;
}
//.........这里部分代码省略.........