public Provenance(SparqlResult result) { DateAcquired = result.Value("dateAcquired").ToString(); Location = result.Value("location").ToString(); OwnedBy = result.Value("ownerLabel").ToString(); DispayOrder = result.Value("dispayOrder").ToString(); }
private void tryAddPerson(SparqlResult i) { if (!People.ContainsKey(i.Value("person"))) { People.Add(i.Value("person"), i); } }
private string Get(string property) { if (info.Variables.Contains(property)) { if (property == "ram" || property == "storage") { return(info.Value(property).ToString() + " GB"); } if (property == "fcam" || property == "rcam") { return(info.Value(property).ToString() + " MP"); } if (property == "material" || property == "color" || property == "other") { string[] strs = info.Value(property).ToString().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); string res = ""; foreach (string str in strs) { res += (VIETNAMESE[str] + ", "); } res = res.Remove(res.Length - 2); return(res); } return(info.Value(property).ToString()); } return("Không"); }
private static bool CompareSolutions(SparqlResult x, SparqlResult y, Dictionary <string, string> bnodeMap) { var boundVarsX = x.Variables.Where(v => x.HasValue(v) && x.Value(v) != null); var boundVarsY = y.Variables.Where(v => y.HasValue(v) && y.Value(v) != null); if (!boundVarsX.Any() && !boundVarsY.Any()) { return(true); } if (x.Variables.Count().Equals(y.Variables.Count()) && x.Variables.All(xv => y.Variables.Contains(xv))) { foreach (var xv in x.Variables) { var xb = x[xv]; var yb = y[xv]; if (!CompareNodes(xb, yb, bnodeMap)) { return(false); } } return(true); } return(false); }
public Artwork(SparqlResult result) { Title = result.Value("label").ToString(); if (result.Variables.Contains("abstract")) { Abstract = result.Value("abstract").ToString(); } ImageUrl = result.Value("depiction").ToString(); if (result.Variables.Contains("museumlabel")) { Museum = result.Value("museumlabel").ToString(); } if (result.Variables.Contains("authorLabel")) { Author = result.Value("authorLabel").ToString(); } }
/// <summary> /// This function returns the redirection page to the pages which have ones /// </summary> /// <param name="uri">This function gets the abstract data of the resource with the URI sent using query</param> /// <returns>the redirection page if found else it returns the same URI</returns> private String useRedirection(String uri) { String query = "select * where {<" + uri + "><http://dbpedia.org/ontology/wikiPageRedirects> ?obj}"; SparqlResultSet results = Request.RequestWithHTTP(query); if (results.Count != 0) { SparqlResult result = results[0]; return(result.Value("obj").ToString()); } else { return(uri); } }
/// <summary> /// we get the values of each result from here /// </summary> /// <param name="sq">input sparqlResult</param> /// <returns>list of string of all the urls according to the query structure ex:?pf ?middle ?os ?ps </returns> private static List <string> valuesOfResults(SparqlResult sq) { //I need this one to know the variables names variableName = new List <string>(); //List<string> variableName = new List<string>(); variableName = sq.Variables.ToList(); List <string> output = new List <string>(); foreach (string var in variableName) { output.Add(sq.Value(var).ToString()); } return(output); }
/// <summary> /// This function gets the abstract data of the resource with the URI sent using query /// </summary> /// <param name="SubjectURI">The URI of the subject resource as String</param> /// <returns>Abstract data about the entity of the URI</returns> private String getAbstract(String SubjectURI) { String query = "select * where {<" + SubjectURI + "><http://dbpedia.org/ontology/abstract> ?obj}"; SparqlResultSet results = Request.RequestWithHTTP(query); if (results.Count != 0) { SparqlResult result = results[0]; return(((LiteralNode)result.Value("obj")).Value); } else { return(null); } }
/// <summary> /// This function gets latitude and longitude of the resource if found with the URI sent using query /// </summary> /// <param name="SubjectURI">The URI of the subject resource as String</param> /// <returns>Location object(latitude and longitude)</returns> private Location getLocation(String SubjectURI) { Location location = new Location(); String query = "select * where {<" + SubjectURI + "><http://www.w3.org/2003/01/geo/wgs84_pos#long> ?obj}"; SparqlResultSet resultsLong = Request.RequestWithHTTP(query); query = "select * where {<" + SubjectURI + "><http://www.w3.org/2003/01/geo/wgs84_pos#lat> ?obj}"; SparqlResultSet resultsLat = Request.RequestWithHTTP(query); if (resultsLat.Count != 0 && resultsLong.Count != 0) { SparqlResult resultLat = resultsLat[0]; SparqlResult resultLong = resultsLong[0]; location.Latitude = ((LiteralNode)resultLat.Value("obj")).Value; location.Longitude = ((LiteralNode)resultLong.Value("obj")).Value; } return(location); }
// TODO Should not be needed since we would rely on the underlying storage capabilities /** * Creates a new Values element. * @param model the Model to create the Values in * @param data the Table providing the actual data * @return a new Values */ public static IValues createValues(SpinProcessor model, SparqlResultSet data, bool untyped) { IResource blank = untyped ? model.CreateResource() : model.CreateResource(SP.ClassValues); IValues values = (IValues)blank.As(typeof(ValuesImpl)); List <IResource> vars = new List <IResource>(); foreach (String varName in data.Variables) { vars.Add(Resource.Get(RDFUtil.CreateLiteralNode(varName), model)); } IResource varList = model.CreateList(vars.GetEnumerator()); values.AddProperty(SP.PropertyVarNames, varList); IEnumerator <SparqlResult> bindings = data.Results.GetEnumerator(); if (bindings.MoveNext()) { List <IResource> lists = new List <IResource>(); while (bindings.MoveNext()) { List <IResource> nodes = new List <IResource>(); SparqlResult binding = bindings.Current; foreach (String varName in data.Variables) { INode value = binding.Value(varName); if (value == null) { nodes.Add(Resource.Get(SP.ClassPropertyUndef, model)); } else { nodes.Add(Resource.Get(value, model)); } } lists.Add(model.CreateList(nodes.GetEnumerator())); } values.AddProperty(SP.PropertyBindings, model.CreateList(lists.GetEnumerator())); } return(values); }
private static int scorecalc(string keyword, SparqlResult singleuri) { List <string> disambiguate_links = new List <string>(); string check_disambig; int score_redirect = 0; int score_resource = 0; SparqlResultSet result; score_resource = computeLevenshteinDistance(keyword, singleuri.Value("literal").ToString().Replace("@en", "")); if (singleuri.Value("redirects") != null) { if (disambiguate_links.Contains(singleuri.Value("redirects").ToString())) { return(1000); } check_disambig = "ASK where {<" + util.encodeURI(singleuri.Value("redirects").ToString()) + "> <http://dbpedia.org/ontology/wikiPageDisambiguates> ?disamb }"; result = Request.RequestWithHTTP(check_disambig); if (result.Result == true) { disambiguate_links.Add(singleuri.Value("redirects").ToString()); return(1000); } string redirect_query = "select * where{ <" + singleuri.Value("redirects").ToString() + "><http://www.w3.org/2000/01/rdf-schema#label> ?redirect_label}"; result = Request.RequestWithHTTP(redirect_query); if (result.Count != 0) { score_redirect = computeLevenshteinDistance(keyword, result[0].Value("redirect_label").ToString().Replace("@en", "")); return(score_redirect <= score_resource ? score_redirect : score_resource); } else { return(score_resource); } } return(score_resource); }
public Artist(SparqlResult result) { Name = result.Value("label").ToString(); Abstract = result.Value("abstract").ToString(); }
public void initForRdfTypeBrowing() { scroll = new ScrollViewer(); mainPanel = new StackPanel(); this.Children.Clear(); int i = 0; StackPanel lastType = null; while (i < resultSet.Count) { SparqlResult result = resultSet[i]; string type = result.Value("type").ToString(); StackPanel internalSt = new StackPanel(); internalSt.Orientation = Orientation.Vertical; internalSt.Margin = new Thickness(20); Label typePromptLabel = new Label(); typePromptLabel.Content = type + " : "; typePromptLabel.Padding = new Thickness(10); internalSt.Children.Add(typePromptLabel); while (i < resultSet.Count) { if (resultSet[i].Value("type").ToString().CompareTo(type) == 0) { if (i >= resultSet.Count) { break; } result = resultSet[i++]; foreach (string variableName in result.Variables.ToArray()) { if (variableName.CompareTo("type") == 0) { continue; } Label promptLabel = new Label(); promptLabel.Content = "-"; promptLabel.Padding = new Thickness(10); TextBlock dataBlock = new TextBlock { TextWrapping = TextWrapping.Wrap }; string data = result.Value(variableName).ToString(); if (data.StartsWith("http://")) { Run href = new Run(data); href.MouseDown += new MouseButtonEventHandler(Href_Click); href.MouseEnter += new MouseEventHandler(href_MouseEnter); dataBlock.Inlines.Add(href); } else { dataBlock.Text = data; } dataBlock.Padding = new Thickness(10); dataBlock.Foreground = Brushes.Blue; WrapPanel wp = new WrapPanel(); wp.Orientation = Orientation.Horizontal; wp.Children.Add(promptLabel); wp.Children.Add(dataBlock); internalSt.Children.Add(wp); } } else { mainPanel.Children.Add(internalSt); type = resultSet[i].Value("type").ToString(); break; } } if (i >= resultSet.Count) { lastType = internalSt; } } if (lastType != null) { mainPanel.Children.Add(lastType); } scroll.Content = mainPanel; this.Children.Add(scroll); }
private static int scorecalc(string keyword, SparqlResult singleuri) { List<string> disambiguate_links = new List<string>(); string check_disambig; int score_redirect = 0; int score_resource = 0; SparqlResultSet result; score_resource = computeLevenshteinDistance(keyword, singleuri.Value("literal").ToString().Replace("@en", "")); if (singleuri.Value("redirects") != null) { if (disambiguate_links.Contains(singleuri.Value("redirects").ToString())) return 1000; check_disambig = "ASK where {<" + util.encodeURI(singleuri.Value("redirects").ToString()) + "> <http://dbpedia.org/ontology/wikiPageDisambiguates> ?disamb }"; result = Request.RequestWithHTTP(check_disambig); if (result.Result == true) { disambiguate_links.Add(singleuri.Value("redirects").ToString()); return 1000; } string redirect_query = "select * where{ <" + singleuri.Value("redirects").ToString() + "><http://www.w3.org/2000/01/rdf-schema#label> ?redirect_label}"; result = Request.RequestWithHTTP(redirect_query); if (result.Count != 0) { score_redirect = computeLevenshteinDistance(keyword, result[0].Value("redirect_label").ToString().Replace("@en", "")); return (score_redirect <= score_resource ? score_redirect : score_resource); } else { return score_resource; } } return score_resource; }
private static List<string> valuesOfResults(SparqlResult sq) { List<string> variableName = new List<string>(); variableName = sq.Variables.ToList(); List<string> output = new List<string>(); foreach (string var in variableName) { output.Add(sq.Value(var).ToString()); } return output; }
private static bool CompareSolutions(SparqlResult x, SparqlResult y, Dictionary<string,string> bnodeMap) { var boundVarsX = x.Variables.Where(v=>x.HasValue(v) && x.Value(v)!=null); var boundVarsY = y.Variables.Where(v=>y.HasValue(v) && y.Value(v)!=null); if (!boundVarsX.Any() && !boundVarsY.Any()) return true; if (x.Variables.Count().Equals(y.Variables.Count()) && x.Variables.All(xv=>y.Variables.Contains(xv))) { foreach (var xv in x.Variables) { var xb = x[xv]; var yb = y[xv]; if (!CompareNodes(xb, yb, bnodeMap)) return false; } return true; } return false; }
protected override bool HandleResultInternal(SparqlResult result) { if (_firstResult) { _xmlWriter.WriteEndElement(); _xmlWriter.WriteStartElement("results"); _firstResult = false; } _xmlWriter.WriteStartElement("result"); foreach (var variable in result.Variables) { _xmlWriter.WriteStartElement("binding"); _xmlWriter.WriteAttributeString("name", variable); var node = result.Value(variable); switch (node.NodeType) { case NodeType.Blank: _xmlWriter.WriteStartElement("bnode"); _xmlWriter.WriteRaw(((IBlankNode)node).InternalID); _xmlWriter.WriteEndElement(); break; case NodeType.Uri: _xmlWriter.WriteStartElement("uri"); _xmlWriter.WriteRaw(WriterHelper.EncodeForXml(((IUriNode)node).Uri.AbsoluteUri)); _xmlWriter.WriteEndElement(); break; case NodeType.Literal: _xmlWriter.WriteStartElement("literal"); ILiteralNode literal = (ILiteralNode)node; if (!literal.Language.Equals(String.Empty)) { _xmlWriter.WriteStartAttribute("xml", "lang", XmlSpecsHelper.NamespaceXml); _xmlWriter.WriteRaw(literal.Language); _xmlWriter.WriteEndAttribute(); } else if (literal.DataType != null) { _xmlWriter.WriteStartAttribute("datatype"); _xmlWriter.WriteRaw(WriterHelper.EncodeForXml(literal.DataType.AbsoluteUri)); _xmlWriter.WriteEndAttribute(); } _xmlWriter.WriteRaw(WriterHelper.EncodeForXml(literal.Value)); _xmlWriter.WriteEndElement(); break; case NodeType.GraphLiteral: throw new RdfOutputException("Result Sets which contain Graph Literal Nodes cannot be serialized in the SPARQL Query Results XML Format"); case NodeType.Variable: break; default: throw new ArgumentOutOfRangeException(); } _xmlWriter.WriteEndElement(); } _xmlWriter.WriteEndElement(); return(true); }
private static int scorecalc(string keyword ,SparqlResult singleuri) { int score_redirect=0; int score_resource = 0; score_resource= computeLevenshteinDistance(keyword, singleuri.Value("literal").ToString()); if (singleuri.Value("redirects") != null) { string disamb_query = "select * where{ <" + singleuri.Value("redirects").ToString() + "><http://www.w3.org/2000/01/rdf-schema#label> ?redirect_label}"; SparqlResultSet result = remoteEndPoint.QueryWithResultSet(disamb_query); if (result.Count != 0) { score_redirect = computeLevenshteinDistance(keyword, result[0].Value("redirect_label").ToString()); return( score_redirect<score_resource? score_redirect: score_resource); } else { return score_resource; } } return score_resource; }
/// <summary> /// we get the values of each result from here /// </summary> /// <param name="sq">input sparqlResult</param> /// <returns>list of string of all the urls according to the query structure ex:?pf ?middle ?os ?ps </returns> private static List<string> valuesOfResults(SparqlResult sq) { //I need this one to know the variables names variableName = new List<string>(); //List<string> variableName = new List<string>(); variableName = sq.Variables.ToList(); List<string> output = new List<string>(); foreach (string var in variableName) { output.Add(sq.Value(var).ToString()); } return output; }
public void initForTripleBrowing() { scroll = new ScrollViewer(); mainPanel = new StackPanel(); this.Children.Clear(); for (int i = 0; i < resultSet.Count; i++) { SparqlResult result = resultSet[i]; Grid internalGrid = new Grid(); Rectangle rec = new Rectangle(); StackPanel internalStackPanel = new StackPanel(); Label titleLabel = new Label(); titleLabel.Background = Brushes.LightBlue; titleLabel.HorizontalContentAlignment = HorizontalAlignment.Center; titleLabel.VerticalContentAlignment = VerticalAlignment.Center; titleLabel.HorizontalAlignment = HorizontalAlignment.Stretch; titleLabel.Content = i + 1; internalStackPanel.Children.Add(titleLabel); rec.Stroke = Brushes.Aqua; rec.StrokeThickness = 2; rec.VerticalAlignment = VerticalAlignment.Stretch; rec.HorizontalAlignment = HorizontalAlignment.Stretch; internalGrid.Children.Add(rec); internalGrid.Children.Add(internalStackPanel); foreach (string variableName in result.Variables.ToArray()) { Label promptLabel = new Label(); promptLabel.Content = variableName + " : "; promptLabel.Padding = new Thickness(10); string data = result.Value(variableName).ToString(); Run href = new Run(data); href.MouseDown += new MouseButtonEventHandler(Href_Click); href.MouseEnter += new MouseEventHandler(href_MouseEnter); TextBlock dataBlock = new TextBlock { TextWrapping = TextWrapping.Wrap }; string dataa = result.Value(variableName).ToString(); if (dataa.StartsWith("http://")) { Run hreff = new Run(dataa); hreff.MouseDown += new MouseButtonEventHandler(Href_Click); hreff.MouseEnter += new MouseEventHandler(href_MouseEnter); dataBlock.Inlines.Add(hreff); } else { dataBlock.Text = dataa; } dataBlock.Padding = new Thickness(10); dataBlock.Foreground = Brushes.Blue; WrapPanel internalWrap = new WrapPanel(); internalWrap.Orientation = Orientation.Horizontal; internalWrap.Children.Add(promptLabel); internalWrap.Children.Add(dataBlock); internalStackPanel.Children.Add(internalWrap); } internalGrid.Margin = new Thickness(10); mainPanel.Children.Add(internalGrid); } scroll.Content = mainPanel; this.Children.Add(scroll); }