Ver código fonte

added locations and countries queries

tags/v2.0
Robin Thoni 7 anos atrás
pai
commit
cb481f25f2

+ 44
- 10
backend/WebSem/WebApiWebSem/DataAccess/DbPediaDataAccess.cs Ver arquivo

@@ -88,12 +88,15 @@ PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
88 88
                 }
89 89
                 else
90 90
                 {
91
-                    dbo.Fields.Add(new ArticlesFieldsDbo
91
+                    if (data != null)
92 92
                     {
93
-                        Property = variable,
94
-                        Type = "text/plain",
95
-                        Value = data
96
-                    });
93
+                        dbo.Fields.Add(new ArticlesFieldsDbo
94
+                        {
95
+                            Property = variable,
96
+                            Type = "text/plain",
97
+                            Value = data
98
+                        });
99
+                    }
97 100
                 }
98 101
             }
99 102
             return dbo;
@@ -102,7 +105,6 @@ PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
102 105
         public LuResult<LuPaginatedDbo<ArticlesDbo>> GetMultiple(LuPaginatedRequestDbo request)
103 106
         {
104 107
             var type = ArticlesDataAccess.GetFilterType(request.Filter);
105
-            string query = null;
106 108
             string querySelect = null;
107 109
             string queryWhereId = null;
108 110
             string queryWhereVars = null;
@@ -122,24 +124,56 @@ BIND ((?abstract) AS ?search)";
122 124
                 queryWhereId = @"?id rdf:type dbo:Person ;
123 125
 ?type dbr:World_War_II .";
124 126
                 queryWhereVars = @"
127
+?id dbp:name ?name .
125 128
 OPTIONAL { ?id dbo:abstract ?abstract FILTER(lang(?abstract) = 'en') }
126 129
 OPTIONAL { ?id foaf:depiction ?pictureUrl }
127 130
 OPTIONAL { ?id dbpedia-owl:depictionDescription ?pictureDesc }
128
-OPTIONAL { ?id dbp:name ?name . FILTER (lang(?name) = 'en') }
129 131
 OPTIONAL { ?id dbp:birthDate ?birthDate }
130 132
 OPTIONAL { ?id dbp:deathDate ?deathDate }
131
-BIND (CONCAT(?abstract, ' ', ?id) AS ?search)";
133
+FILTER (lang(?name) = 'en')
134
+BIND (CONCAT(?name) AS ?search)";
135
+            }
136
+            else if (type == "locations")
137
+            {
138
+                querySelect = "?id ?name ?abstract ?pictureUrl ?pictureDesc (str(MIN(?date) as ?date) as ?date) (group_concat(distinct ?combatant;separator=', ') as ?combatant) (group_concat(distinct ?commanderName;separator=', ') as ?commander)";
139
+                queryWhereId = @"?ww foaf:isPrimaryTopicOf wikipedia-en:World_War_II ;
140
+dbo:place ?id.";
141
+                queryWhereVars = @"
142
+?id foaf:name ?name .
143
+OPTIONAL { ?id dbo:abstract ?abstract FILTER(lang(?abstract) = 'en') }
144
+OPTIONAL { ?id foaf:depiction ?pictureUrl }
145
+OPTIONAL { ?id dbpedia-owl:depictionDescription ?pictureDesc }
146
+OPTIONAL { ?id dbo:date ?date }
147
+OPTIONAL { ?id dbp:combatant ?combatant }
148
+OPTIONAL { ?id dbp:commander ?commanderName }
149
+FILTER (lang(?name) = 'en')
150
+BIND (CONCAT(?name) AS ?search)";
151
+            }
152
+            else if (type == "countries")
153
+            {
154
+                querySelect = "?id (MIN(?name) as ?name) ?abstract ?pictureUrl ?pictureDesc ";
155
+                queryWhereId = @"?id a <http://dbpedia.org/ontology/Country> ;
156
+?type dbr:World_War_II .";
157
+                queryWhereVars = @"
158
+?id foaf:name ?name .
159
+OPTIONAL { ?id dbo:abstract ?abstract FILTER(lang(?abstract) = 'en') }
160
+OPTIONAL { ?id foaf:depiction ?pictureUrl }
161
+OPTIONAL { ?id dbpedia-owl:depictionDescription ?pictureDesc }
162
+FILTER (lang(?name) = 'en')
163
+BIND (CONCAT(?name) AS ?search)";
132 164
             }
133 165
 
134 166
             var filter = $"FILTER regex(?search, '{request.Filter.Query}', 'i')";
135 167
 
136 168
             var count = Query(string.Format(@"{0}
137 169
 SELECT (COUNT(?id) AS ?count) WHERE {{
138
-{1}
170
+SELECT DISTINCT {1} WHERE {{
139 171
 {2}
140 172
 {3}
173
+{4}
174
+}}
141 175
 }}
142
-", Prefixes, queryWhereId, queryWhereVars, filter));
176
+", Prefixes, querySelect, queryWhereId, queryWhereVars, filter));
143 177
             if (!count)
144 178
             {
145 179
                 return count.To<LuPaginatedDbo<ArticlesDbo>>();

Carregando…
Cancelar
Salvar