Exemplo n.º 1
0
        /// <summary>
        /// Gets all phone models and their names
        /// </summary>
        /// <returns>Dictionary with key is model and value is name</returns>
        public static Dictionary <string, string> GetAllModels()
        {
            SparqlResultSet models = SPARQL.DoQuery(@"
                PREFIX ont: <http://www.co-ode.org/ontologies/ont.owl#>
                SELECT ?model ?name WHERE 
                { 
                    ?s a ont:PhoneModel. BIND (STRAFTER(STR(?s), STR(ont:)) AS ?model).
                    ?s ont:hasName ?name.                    
                }");

            Dictionary <string, string> D = new Dictionary <string, string>();

            foreach (SparqlResult model in models)
            {
                D.Add(model.Value("model").ToString(), model.Value("name").ToString());
            }
            return(D);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a phone model with all properties gotten by querying the model key
        /// </summary>
        public PhoneModel(string modelKey)
        {
            SparqlResultSet results = SPARQL.DoQuery(@"
                PREFIX ont: <http://www.co-ode.org/ontologies/ont.owl#>
                SELECT * WHERE 
                { 
                    ?s a ont:PhoneModel. BIND (STRAFTER(STR(?s), STR(ont:)) AS ?model).
                    ?s ont:hasName ?name.
                    ?s ont:hasPrice ?t1. BIND (STR(?t1) AS ?price).
                    ?s ont:hasBatteryCapacity ?t2. BIND (STR(?t2) AS ?battery).
                    ?s ont:hasScreenSize ?t3. BIND (STR(?t3) AS ?screensize).
                    ?s ont:hasHeightOfRes ?t4. BIND (STR(?t4) AS ?hres).
                    ?s ont:hasWidthOfRes ?t5. BIND (STR(?t5) AS ?wres).
                    ?s ont:hasColor ?color.
                    ?s ont:hasMaterial ?material.
                    ?s ont:hasLink ?link.
                    OPTIONAL { 
                        ?s ont:hasOS ?os.
                        ?os ont:hasName ?osName.
                        ?os ont:hasVersion ?t6. BIND (STR(?t6) AS ?osVersion). }
                    OPTIONAL { 
                        ?s ont:hasCPU ?cpu.
                        ?cpu ont:hasName ?cpuName.
                        ?cpu ont:hasBitArchitecture ?t7. BIND (STR(?t7) AS ?bit).
                        ?cpu ont:hasCores ?t8. BIND (STR(?t8) AS ?core). }
                    OPTIONAL { 
                        ?s ont:hasRAMCapacity ?t9. BIND (STR(?t9) AS ?ram). }
                    OPTIONAL {
                        ?s ont:hasInternalStorageCapacity ?t10. BIND (STR(?t10) AS ?storage). }
                    OPTIONAL {
                        ?s ont:hasFrontMegapixel ?t11. BIND (STR(?t11) AS ?fcam). }
                    OPTIONAL {
                        ?s ont:hasRearMegapixel ?t12. BIND (STR(?t12) AS ?rcam). }
                    OPTIONAL {
                        ?s ont:hasOtherFeatures ?other. }
                    FILTER (?model = '" + modelKey + @"').
                }
                LIMIT 1");

            if (results.Count != 0)
            {
                info = results[0];
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Searchs phone models by their properties
        /// </summary>
        /// <param name="filterOptions">phone properties to filter</param>
        /// <returns>Dictionary with key is model and value is name</returns>
        public static Dictionary <string, string> SearchProperties(FilterOptions filterOptions)
        {
            string pattern = filterOptions.GetQueryPattern();

            SparqlResultSet models = SPARQL.DoQuery(@"
                PREFIX ont: <http://www.co-ode.org/ontologies/ont.owl#>
                PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
                SELECT ?model ?name WHERE 
                { 
                    ?s a ont:PhoneModel. BIND (STRAFTER(STR(?s), STR(ont:)) AS ?model).
                    ?s ont:hasName ?name.
                    " + pattern + @"
                }");

            Dictionary <string, string> D = new Dictionary <string, string>();

            foreach (SparqlResult model in models)
            {
                D.Add(model.Value("model").ToString(), model.Value("name").ToString());
            }
            return(D);
        }
Exemplo n.º 4
0
        static void ScoreMatchingFacts(Dictionary <string, int> models)
        {
            foreach (Fact f in Known)
            {
                string prefix = "";
                if (f.Name == "Manufacturer" || f.Name == "OS" || f.Name == "CPU")
                {
                    prefix = "ont:";
                }

                string patterns = "";
                if (f.Name == "CPUCores")
                {
                    patterns = @"
                    ?s ont:hasCPU ?prop.
                    ?prop ont:hasCores ?subprop.
                    FILTER (?subprop " + f.Operator + " " + f.Value + ").";
                }
                else if (f.Name == "OSName")
                {
                    patterns = @"
                    ?s ont:hasOS ?prop.
                    ?prop ont:hasName ?subprop.
                    FILTER (?subprop " + f.Operator + " " + f.Value + ").";
                }
                else if (f.Name == "Color")
                {
                    patterns = @"
                    ?s ont:hasColor ?prop.
                    FILTER regex(?prop, " + f.Value + ").";
                }
                else if (f.Name == "Material")
                {
                    patterns = @"
                    ?s ont:hasMaterial ?prop.
                    FILTER regex(?prop, " + f.Value + ").";
                }
                else if (f.Name == "OS")
                {
                    switch (f.Value)
                    {
                    case "Android": patterns += ("?s ont:hasOS ?os. FILTER ( ?os > ont:" + f.Value + " && ?os < ont:B"); break;

                    case "iOS": patterns += ("?s ont:hasOS ?os. FILTER ( ?os > ont:" + f.Value + " && ?os < ont:j"); break;

                    case "Windows":
                        patterns += ("?s ont:hasOS ?os. FILTER ( ?os > ont:" + f.Value + " && ?os < ont:X"); break;
                    }
                    patterns += ").";
                }
                else
                {
                    patterns = @"
                    ?s ont:has" + f.Name + @" ?prop.
                    FILTER (?prop " + f.Operator + " " + prefix + f.Value + ").";
                }

                SparqlResultSet results = SPARQL.DoQuery(@"
                PREFIX ont: <http://www.co-ode.org/ontologies/ont.owl#>
                SELECT ?model WHERE 
                { 
                    ?s a ont:PhoneModel. BIND (STRAFTER(STR(?s), STR(ont:)) AS ?model).
                    " + patterns + @"
                }");

                foreach (var result in results)
                {
                    string modelKey = result.Value("model").ToString();
                    if (models.ContainsKey(modelKey))
                    {
                        models[modelKey] += FactScore[f];
                        if (!ModelFacts.ContainsKey(modelKey))
                        {
                            ModelFacts[modelKey] = new List <Fact>();
                        }
                        else
                        {
                            ModelFacts[modelKey].Add(f);
                        }
                    }
                }
            }
        }