Browse Source

added locations and countries queries

tags/v2.0
Robin Thoni 7 years ago
parent
commit
cb481f25f2
1 changed files with 44 additions and 10 deletions
  1. 44
    10
      backend/WebSem/WebApiWebSem/DataAccess/DbPediaDataAccess.cs

+ 44
- 10
backend/WebSem/WebApiWebSem/DataAccess/DbPediaDataAccess.cs View File

88
                 }
88
                 }
89
                 else
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
             return dbo;
102
             return dbo;
102
         public LuResult<LuPaginatedDbo<ArticlesDbo>> GetMultiple(LuPaginatedRequestDbo request)
105
         public LuResult<LuPaginatedDbo<ArticlesDbo>> GetMultiple(LuPaginatedRequestDbo request)
103
         {
106
         {
104
             var type = ArticlesDataAccess.GetFilterType(request.Filter);
107
             var type = ArticlesDataAccess.GetFilterType(request.Filter);
105
-            string query = null;
106
             string querySelect = null;
108
             string querySelect = null;
107
             string queryWhereId = null;
109
             string queryWhereId = null;
108
             string queryWhereVars = null;
110
             string queryWhereVars = null;
122
                 queryWhereId = @"?id rdf:type dbo:Person ;
124
                 queryWhereId = @"?id rdf:type dbo:Person ;
123
 ?type dbr:World_War_II .";
125
 ?type dbr:World_War_II .";
124
                 queryWhereVars = @"
126
                 queryWhereVars = @"
127
+?id dbp:name ?name .
125
 OPTIONAL { ?id dbo:abstract ?abstract FILTER(lang(?abstract) = 'en') }
128
 OPTIONAL { ?id dbo:abstract ?abstract FILTER(lang(?abstract) = 'en') }
126
 OPTIONAL { ?id foaf:depiction ?pictureUrl }
129
 OPTIONAL { ?id foaf:depiction ?pictureUrl }
127
 OPTIONAL { ?id dbpedia-owl:depictionDescription ?pictureDesc }
130
 OPTIONAL { ?id dbpedia-owl:depictionDescription ?pictureDesc }
128
-OPTIONAL { ?id dbp:name ?name . FILTER (lang(?name) = 'en') }
129
 OPTIONAL { ?id dbp:birthDate ?birthDate }
131
 OPTIONAL { ?id dbp:birthDate ?birthDate }
130
 OPTIONAL { ?id dbp:deathDate ?deathDate }
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
             var filter = $"FILTER regex(?search, '{request.Filter.Query}', 'i')";
166
             var filter = $"FILTER regex(?search, '{request.Filter.Query}', 'i')";
135
 
167
 
136
             var count = Query(string.Format(@"{0}
168
             var count = Query(string.Format(@"{0}
137
 SELECT (COUNT(?id) AS ?count) WHERE {{
169
 SELECT (COUNT(?id) AS ?count) WHERE {{
138
-{1}
170
+SELECT DISTINCT {1} WHERE {{
139
 {2}
171
 {2}
140
 {3}
172
 {3}
173
+{4}
174
+}}
141
 }}
175
 }}
142
-", Prefixes, queryWhereId, queryWhereVars, filter));
176
+", Prefixes, querySelect, queryWhereId, queryWhereVars, filter));
143
             if (!count)
177
             if (!count)
144
             {
178
             {
145
                 return count.To<LuPaginatedDbo<ArticlesDbo>>();
179
                 return count.To<LuPaginatedDbo<ArticlesDbo>>();

Loading…
Cancel
Save