private Collection<BaprLocation> Convert(ICollection<ILocation> locations)
 {
     Collection<BaprLocation> baprLocations = new Collection<BaprLocation>();
     foreach (var location in locations)
     {
         BaprLocation baprLocation = new BaprLocation()
         {
             name = location.name,
             latitude = location.latitude,
             longitude = location.longitude,
             IsVisited = location.IsVisited,
             IsFavorite = location.IsFavorite
         };
         baprLocation.attributes = new Collection<BaprLocationAttribute>();
         foreach (var attr in location.attributes)
         {
             baprLocation.attributes.Add(new BaprLocationAttribute()
             {
                 Name = attr.Name,
                 Value = attr.Value,
                 Type = attr.Type
             });
         }
         baprLocations.Add(baprLocation);
     }
     return baprLocations;
 }
        private Collection<BaprLocation> ExtractResults(Graph graph, List<string> inferredResults)
        {
            Collection<BaprLocation> results = new Collection<BaprLocation>();
            List<object[]> itemsArray = new List<object[]>();
            foreach (DataRow row in graph.ToDataTable().Rows)
            {
                itemsArray.Add(row.ItemArray);
            }
            foreach (var group in itemsArray.GroupBy(x => x[0]))
            {
                if (!inferredResults.Contains(group.Key.ToString()))
                    continue;

                BaprLocation location = new BaprLocation();
                location.attributes = new Collection<BaprLocationAttribute>();
                foreach (object[] attribute in group)
                {
                    string attrValue = attribute[2].ToString();
                    if (attribute[1].ToString().Contains("label"))
                        location.name = GetAttributeName(attrValue);
                    else if (attribute[1].ToString().Contains("lat"))
                        location.latitude = GetCoordinate(attrValue);
                    else if (attribute[1].ToString().Contains("long"))
                        location.longitude = GetCoordinate(attrValue);
                    else
                    {
                        BaprLocationAttribute attr = new BaprLocationAttribute();
                        attr.Name = GetLastSubstring(attribute[1].ToString());
                        attr.Value = SplitValue(attribute[1].ToString(), attribute[2].ToString());
                        attr.Type = "string";
                        location.attributes.Add(attr);
                    }
                }
                results.Add(location);
            }

            return results;
        }
Exemple #3
0
        public static Collection<BaprLocation> ConvertFromSparqlSetToBaprLocations(SparqlResultSet entities)
        {
            var finalResult = new Collection<BaprLocation>();
            foreach (VDS.RDF.Query.SparqlResult result in entities)
            {
                var baprLocation = new BaprLocation
                {
                    attributes = new Collection<BaprLocationAttribute>()
                };
                var properties = result.ToString().Split(',');
                foreach (var property in properties)
                {
                    var list = property.Split('=');
                    var attr = list[0].Replace("?", "");
                    var @value = list.Length > 1 ?  list[1] : string.Empty;
                    var index = @value.IndexOf('^');
                    if (index > -1)
                    {
                        @value = @value.Remove(index);
                    }

                    if (attr.Trim() == "head_chef" || attr.Trim().Contains("type") || attr.Trim() == "health_care")
                    {
                        string decodedUrlValue = HttpUtility.UrlDecode(@value);
                        var headChef = decodedUrlValue.Substring(decodedUrlValue.LastIndexOf('/') + 1);
                        @value = headChef;
                    }
                    if (attr.Trim() == "lat")
                    {
                        baprLocation.latitude = Convert.ToDouble(@value);
                    }
                    else if (attr.Trim() == "long")
                    {
                        baprLocation.longitude = Convert.ToDouble(@value);
                    }
                    else if (attr.Trim() == "name")
                    {
                        var indexForName = @value.IndexOf('@');
                        if (indexForName > -1)
                        {
                            @value = @value.Remove(indexForName);
                        }
                        baprLocation.name = @value;
                    }

                    else if (!string.IsNullOrWhiteSpace(@value))
                    {
                        @value = @value.Trim();
                        var indexForName = @value.IndexOf('@');
                        if (indexForName == @value.Length - 3 && indexForName > -1)
                        {
                            @value = @value.Remove(indexForName);
                        }
                        baprLocation.attributes.Add(new BaprLocationAttribute
                        {
                            Name = attr,
                            Value = attr.Trim() == "wheelchair" ? "True" : @value,
                            Type = attr.Trim() == "wheelchair" ? "bool" : "string"
                        });

                    }
                }
                finalResult.Add(baprLocation);
            }
            return finalResult;
        }