search.component.ts 1.75 KB
Newer Older
Administrator's avatar
Administrator committed
1
import { Component, OnInit } from '@angular/core';
Administrator's avatar
Administrator committed
2
import { HttpClient, HttpHeaders } from '@angular/common/http';
3
import { ParseXmlService } from '../services/parse-xml.service';
4
import { FormControl, FormGroup } from '@angular/forms';
Administrator's avatar
Administrator committed
5
6
7
8
9
10
11
12
13
14
15
16


@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.scss']
})



export class SearchComponent implements OnInit {

Administrator's avatar
Administrator committed
17

18
  public xmlItems: string[][] = []; 
Administrator's avatar
Administrator committed
19

20
21
22
23
  Form = new FormGroup({
    keyword: new FormControl()
});

Administrator's avatar
Administrator committed
24
  constructor(
25
26
    private http: HttpClient,
    private parserService: ParseXmlService
Administrator's avatar
Administrator committed
27
  ) { }
Administrator's avatar
Administrator committed
28
29
30
31

  ngOnInit(): void {
  }

Administrator's avatar
Administrator committed
32
33
34
35
  simpleSearch(){
     //effectuer une recherche plein text en SPARL sur la BDD Blazegraph
     //curl -X POST -H 'Accept: application/rdf+xml' -i 'http://10.6.10.9:8888/blazegraph/sparql' --data 'query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'

Administrator's avatar
Administrator committed
36
     let query: string;
37
38
39
40
41
42
43
//     query ='query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'
     


query= 
'query=PREFIX dcat: <http://www.w3.org/ns/dcat#>\n\
PREFIX dcterms: <http://purl.org/dc/terms/>\n\
44
SELECT  ?title ?description ?uri \n\
45
46
47
where {\n\
?dataset a dcat:Dataset ;\n\
dcterms:title ?title ;\n\
48
49
50
dcterms:description ?description; \n\
dcat:keyword ?uri ; \n\
FILTER (contains( ?description, "'+ this.Form.value.keyword +'") || contains( ?title, "'+ this.Form.value.keyword +'"))\n\
51
.\n\
52
53
54
}'


55
56
57
58
      this.parserService.getXmlResult("http://10.6.10.9:8888/blazegraph/sparql",query).subscribe(
        data=>{
          if (data){
            data.results.bindings.forEach(element => {
59
              this.xmlItems.push(element);
60
61
62
            });
          }
        })
Administrator's avatar
Administrator committed
63
      return null;
Administrator's avatar
Administrator committed
64
65
  }

66

Paulo's avatar
Paulo committed
67
68
69
  isXmlItemsEmpty(){
    return this.xmlItems.length === 0;
  } 
Administrator's avatar
Administrator committed
70
71

}