Commit fdb91000 authored by Thibault Ehrhart's avatar Thibault Ehrhart

Add basic support for schemas filtering

parent 138beb67
......@@ -40,7 +40,7 @@ export class HomeDetailsComponent implements OnInit {
this.selectedItem.sources = [];
if (sources) {
sources.source_sentences.forEach((sentence: any) => {
this.selectedItem.sources.push(sentence.text);
this.selectedItem.sources.push(sentence);
});
}
}, (error: any) => {
......
......@@ -30,6 +30,7 @@ export class HomeComponent implements OnInit {
subjectCodes: NgOption[] = [];
locations: NgOption[] = [];
schemas: NgOption[] = [];
annotations: any = [{
id: 'http://adel.eurecom.fr/Stanford/Location',
label: 'Location',
......@@ -54,6 +55,24 @@ export class HomeComponent implements OnInit {
selected: null,
options: [],
typeahead: new Subject<string>()
}, {
id: 'http://adel.eurecom.fr/Stanford/Thing',
label: 'Thing',
selected: null,
options: [],
typeahead: new Subject<string>()
}, {
id: 'http://adel.eurecom.fr/Stanford/Event',
label: 'Event',
selected: null,
options: [],
typeahead: new Subject<string>()
}, {
id: 'http://adel.eurecom.fr/Stanford/Product',
label: 'Product',
selected: null,
options: [],
typeahead: new Subject<string>()
}];
constructor(
......@@ -77,7 +96,8 @@ export class HomeComponent implements OnInit {
location: new FormControl(),
date: new FormControl(),
who: new FormControl(),
keywords: new FormControl()
keywords: new FormControl(),
schema: new FormControl()
});
this.formGroupSearch.valueChanges.debounceTime(500).subscribe(form => {
......@@ -86,6 +106,7 @@ export class HomeComponent implements OnInit {
this.search.searchParams.subjects = form.selectedSubjectCodes;
this.search.searchParams.location = form.location ? form.location.trim() : null;
this.search.searchParams.keywords = form.keywords ? form.keywords.trim() : null;
this.search.searchParams.schema = form.schema ? form.schema : null;
this.search.searchParams.annotations = [];
this.annotations.forEach((annotation: any) => {
......@@ -114,10 +135,19 @@ export class HomeComponent implements OnInit {
});
});
// Define schemas
this.schemas = [{
id: 'aviation-accident',
label: 'Aviation accident'
}];
// Load news from URL ID
this.sub = this.route.params.subscribe(params => {
let id = params['id'];
if (id) {
// Remove the previous item
this.selectedItem = null;
// Load the new item
this.newsService.getNewsByUri('http://asrael.eurecom.fr/news/' + id).subscribe((data: any) => {
this.selectItem(data.results.bindings[0]);
......
......@@ -18,6 +18,7 @@ export interface NewsContext {
location?: string;
keywords?: string;
annotations?: Array<any>;
schema?: string;
}
@Injectable()
......@@ -31,8 +32,9 @@ export class NewsService {
let query = `
${this.getPrefixes()}
SELECT DISTINCT ?anchorOf ?classRef ?identRef
FROM <http://asrael.eurecom.fr/agencefrancepresse/news>
WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?s a nif:Phrase . }
?s a nif:Phrase .
?s nif:referenceContext ?refContext .
?s nif:anchorOf ?anchorOf .
?s itsrdf:taClassRef ?classRef .
......@@ -56,8 +58,9 @@ export class NewsService {
return Observable.fromPromise(client.query(`
${this.getPrefixes()}
SELECT DISTINCT ?country
FROM <http://asrael.eurecom.fr/agencefrancepresse/news>
WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?s a rnews:NewsItem . }
?s a rnews:NewsItem .
?s schema:contentLocation ?location .
?location schema:address ?address .
?address schema:addressCountry ?country .
......@@ -66,6 +69,7 @@ export class NewsService {
ORDER BY ASC(?country)
`));
}
getSubjectCodes(): Observable<any> {
let client = new Client(environment.virtuosoAddress);
client.setOptions('application/json');
......@@ -99,6 +103,7 @@ export class NewsService {
PREFIX asrael: <http://asrael.eurecom.fr/asrael#>
PREFIX nif: <http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#>
PREFIX itsrdf: <http://www.w3.org/2005/11/its/rdf#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
`;
}
......@@ -144,7 +149,7 @@ export class NewsService {
OPTIONAL {
?s asrael:context ?context .
{
SELECT ?refContext ?annotations WHERE {
SELECT ?refContext (GROUP_CONCAT(DISTINCT ?annotations; separator="|") AS ?annotations) WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?sp a nif:Phrase . }
?sp nif:referenceContext ?refContext .
?sp nif:anchorOf ?anchorOf .
......@@ -212,7 +217,7 @@ export class NewsService {
context.subjects = [context.subjects];
}
if (Array.isArray(context.subjects) && context.subjects.length > 0) {
subjectsFilter = 'VALUES ?subject { ' + context.subjects.map(uri => '<' + uri + '>').join(' ') + ' }';
subjectsFilter = '?s dc:subject ?subject . VALUES ?subject { ' + context.subjects.map(uri => '<' + uri + '>').join(' ') + ' }';
}
// Genres filter
......@@ -221,7 +226,7 @@ export class NewsService {
context.genres = [context.genres];
}
if (Array.isArray(context.genres) && context.genres.length > 0) {
genresFilter = 'FILTER (?genre NOT IN(' + context.genres.map(uri => '<' + uri + '>').join(',') + '))';
genresFilter = 'OPTIONAL { ?s rnews:genre ?genre . } FILTER (?genre NOT IN(' + context.genres.map(uri => '<' + uri + '>').join(',') + '))';
}
// Date filter
......@@ -267,36 +272,22 @@ export class NewsService {
// Generate query
let query = `
${this.getPrefixes()}
SELECT DISTINCT ?s ?dateCreated ?dateModified ?datePublished ?description ?genre ?subject ?headline ?identifier ?language ?slug ?country ?locality
SELECT DISTINCT *
FROM <http://asrael.eurecom.fr/agencefrancepresse/news>
WHERE {
GRAPH <http://asrael.eurecom.fr/agencefrancepresse/news> { ?s a rnews:NewsItem . }
?s a rnews:NewsItem .
OPTIONAL { ?s rnews:dateCreated ?dateCreated . }
OPTIONAL { ?s rnews:dateModified ?dateModified . }
OPTIONAL { ?s rnews:datePublished ?datePublished . }
OPTIONAL {
?s rnews:description ?description .
${keywordsFilter}
FILTER (LANG(?description) = "" || LANG(?description = "en"))
}
OPTIONAL { ?s rnews:genre ?genre . }
OPTIONAL { ?s dc:subject ?subject . }
OPTIONAL { ?s rnews:description ?description . }
OPTIONAL { ?s rnews:headline ?headline . }
OPTIONAL { ?s rnews:identifier ?identifier . }
OPTIONAL { ?s rnews:inLanguage ?language . }
OPTIONAL { ?s rnews:slug ?slug . }
OPTIONAL {
?s schema:contentLocation ?location .
OPTIONAL {
?location schema:address ?address .
OPTIONAL { ?address schema:addressCountry ?country . }
OPTIONAL { ?address schema:addressLocality ?locality }
}
}
OPTIONAL { ?s schema:contentLocation/schema:address/schema:addressCountry ?country . }
OPTIONAL { ?s schema:contentLocation/schema:address/schema:addressLocality ?locality . }
FILTER (BOUND(?headline) || STRLEN(?headline) > 0)
${keywordsFilter}
${subjectsFilter}
${genresFilter}
${dateFilter}
${locationFilter}
${schemaFilter}
${annotationsFilter}
}
ORDER BY DESC(?dateCreated)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment