private void FindCategoryButton_Click(object sender, RoutedEventArgs e) { string productName = ProductNameTextBox.Text; string query = "SELECT ?categoryName WHERE { <http://www.myproducts.com/" + productName + "> <http://www.myproducts.com/InCategoryOf> ?cat . ?cat <http://www.myproducts.com/CategoryCodeOf> ?categoryName }"; SparqlResultSet results = (SparqlResultSet)myGraph.ExecuteQuery(query); DataTable dt = new DataTable(); dt.Columns.Add("CategoryName"); foreach (var arr in results.ToArray()) { dt.Rows.Add(arr.ToString().Substring(16)); } dataGrid1.ItemsSource = dt.DefaultView; }
private void FindRelativesButton_Click(object sender, RoutedEventArgs e) { string productName = ProductNameTextBox.Text; string query = "SELECT ?RelativeProducts WHERE { <http://www.myproducts.com/" + productName + "> <http://www.myproducts.com/InCategoryOf> ?CategoryId . ?RelativeProducts <http://www.myproducts.com/InCategoryOf> ?CategoryId FILTER (?RelativeProducts!=<http://www.myproducts.com/" + productName + ">)} ORDER BY ?RelativeProducts"; SparqlResultSet results = (SparqlResultSet)myGraph.ExecuteQuery(query); DataTable dt = new DataTable(); dt.Columns.Add("RelativeProducts"); foreach (var arr in results.ToArray()) { dt.Rows.Add(arr.ToString().Substring(46)); } dataGrid1.ItemsSource = dt.DefaultView; /*foreach (var res in results) * { * MessageBox.Show(res.ToString()); * }*/ }