freme-project / e-Entity

Apache License 2.0
1 stars 1 forks source link

Parameters from URL query processed by E-Entity #30

Closed x-fran closed 8 years ago

x-fran commented 8 years ago

I'm playing with this piece of code in zend framework 2.

        $request = new Request();
        $request->getHeaders()->addHeaders(array(
            'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
        ));
        $request->setUri("http://api-dev.freme-project.eu/current/e-entity/dbpedia-spotlight/documents");
        $request->setQuery(new Parameters([
            'informat' => 'text',
            'outformat' => 'json-ld', // will be fixed
            'language' => 'en',
            'confidence' => 0.3
        ]));
        $request->setMethod(Request::METHOD_POST);
        $request->setPost(new Parameters([
            "Welcome to Berlin"
        ]));
        $client = new Client();
        $response = $client->dispatch($request);
        $data = json_decode($response->getContent(), true);
        return $data;

And I have this back:


  '@graph' => 
    array (size=44)
      0 => 
        array (size=10)
          '@id' => string 'http://freme-project.eu/char=0,78' (length=33)
          '@type' => 
            array (size=3)
              ...
          'anchorOf' => string 'informat=text&outformat=json-ld&language=en&confidence=0.3&0=Welcome+to+Berlin' (length=78)
          'beginIndex' => string '0' (length=1)
          'endIndex' => string '78' (length=2)
          'firstWord' => string 'http://freme-project.eu/char=0,8' (length=32)
          'isString' => string 'informat=text&outformat=json-ld&language=en&confidence=0.3&0=Welcome+to+Berlin' (length=78)
          'lastWord' => string 'http://freme-project.eu/char=72,78' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'word' => 
            array (size=21)
              ...
      1 => 
        array (size=8)
          '@id' => string 'http://freme-project.eu/char=0,8' (length=32)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'informat' (length=8)
          'beginIndex' => string '0' (length=1)
          'endIndex' => string '8' (length=1)
          'nextWord' => string 'http://freme-project.eu/char=8,9' (length=32)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      2 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=13,14' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '&' (length=1)
          'beginIndex' => string '13' (length=2)
          'endIndex' => string '14' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=14,23' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=9,13' (length=33)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      3 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=14,23' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'outformat' (length=9)
          'beginIndex' => string '14' (length=2)
          'endIndex' => string '23' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=23,24' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=13,14' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      4 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=23,24' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '=' (length=1)
          'beginIndex' => string '23' (length=2)
          'endIndex' => string '24' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=24,31' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=14,23' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      5 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=24,31' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'json-ld' (length=7)
          'beginIndex' => string '24' (length=2)
          'endIndex' => string '31' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=31,32' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=23,24' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      6 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=31,32' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '&' (length=1)
          'beginIndex' => string '31' (length=2)
          'endIndex' => string '32' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=32,40' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=24,31' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      7 => 
        array (size=10)
          '@id' => string 'http://freme-project.eu/char=32,40' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'language' (length=8)
          'beginIndex' => string '32' (length=2)
          'endIndex' => string '40' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=40,41' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=31,32' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
          'taIdentRef' => string 'http://dbpedia.org/resource/Language' (length=36)
      8 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=40,41' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '=' (length=1)
          'beginIndex' => string '40' (length=2)
          'endIndex' => string '41' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=41,43' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=32,40' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      9 => 
        array (size=10)
          '@id' => string 'http://freme-project.eu/char=41,43' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'en' (length=2)
          'beginIndex' => string '41' (length=2)
          'endIndex' => string '43' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=43,44' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=40,41' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
          'taIdentRef' => string 'http://dbpedia.org/resource/English_language' (length=44)
      10 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=43,44' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '&' (length=1)
          'beginIndex' => string '43' (length=2)
          'endIndex' => string '44' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=44,54' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=41,43' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      11 => 
        array (size=10)
          '@id' => string 'http://freme-project.eu/char=44,54' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'confidence' (length=10)
          'beginIndex' => string '44' (length=2)
          'endIndex' => string '54' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=54,55' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=43,44' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
          'taIdentRef' => 
            array (size=2)
              ...
      12 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=54,55' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '=' (length=1)
          'beginIndex' => string '54' (length=2)
          'endIndex' => string '55' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=55,58' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=44,54' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      13 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=55,58' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '0.3' (length=3)
          'beginIndex' => string '55' (length=2)
          'endIndex' => string '58' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=58,59' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=54,55' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      14 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=58,59' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '&' (length=1)
          'beginIndex' => string '58' (length=2)
          'endIndex' => string '59' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=59,60' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=55,58' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      15 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=59,60' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '0' (length=1)
          'beginIndex' => string '59' (length=2)
          'endIndex' => string '60' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=60,61' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=58,59' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      16 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=60,61' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '=' (length=1)
          'beginIndex' => string '60' (length=2)
          'endIndex' => string '61' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=61,68' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=59,60' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      17 => 
        array (size=10)
          '@id' => string 'http://freme-project.eu/char=61,68' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'Welcome' (length=7)
          'beginIndex' => string '61' (length=2)
          'endIndex' => string '68' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=68,69' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=60,61' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
          'taIdentRef' => string 'http://dbpedia.org/resource/Welcome_(2007_film)' (length=47)
      18 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=68,69' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '+' (length=1)
          'beginIndex' => string '68' (length=2)
          'endIndex' => string '69' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=69,71' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=61,68' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      19 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=69,71' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'to' (length=2)
          'beginIndex' => string '69' (length=2)
          'endIndex' => string '71' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=71,72' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=68,69' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      20 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=71,72' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '+' (length=1)
          'beginIndex' => string '71' (length=2)
          'endIndex' => string '72' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=72,78' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=69,71' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      21 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=72,78' (length=34)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'Berlin' (length=6)
          'beginIndex' => string '72' (length=2)
          'endIndex' => string '78' (length=2)
          'previousWord' => string 'http://freme-project.eu/char=71,72' (length=34)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
          'taIdentRef' => string 'http://dbpedia.org/resource/Berlin' (length=34)
      22 => 
        array (size=9)
          '@id' => string 'http://freme-project.eu/char=8,9' (length=32)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string '=' (length=1)
          'beginIndex' => string '8' (length=1)
          'endIndex' => string '9' (length=1)
          'nextWord' => string 'http://freme-project.eu/char=9,13' (length=33)
          'previousWord' => string 'http://freme-project.eu/char=0,8' (length=32)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
      23 => 
        array (size=10)
          '@id' => string 'http://freme-project.eu/char=9,13' (length=33)
          '@type' => 
            array (size=2)
              ...
          'anchorOf' => string 'text' (length=4)
          'beginIndex' => string '9' (length=1)
          'endIndex' => string '13' (length=2)
          'nextWord' => string 'http://freme-project.eu/char=13,14' (length=34)
          'previousWord' => string 'http://freme-project.eu/char=8,9' (length=32)
          'referenceContext' => string 'http://freme-project.eu/char=0,78' (length=33)
          'sentence' => string 'http://freme-project.eu/char=0,78' (length=33)
          'taIdentRef' => 
            array (size=2)

...
...

I'm doing something wrong?

m1ci commented 8 years ago

Hi Francisc, The results are wrong, actually all the params are considered as content since you send the data as application/x-www-form-urlencoded.

I am not familiar with the performing HTTP requests with the Zend framework but here are some tips that might solve you problem:

If you are familiar with cURL, here is one line command which do the same thing

BTW, its not good practice to write your own parser for RDF (serialized as turtle, json-ld, rdf/xml, etc.). I recommend you use well-established RDF parsers for PHP. Here are some RDF libraries you can use in PHP: http://www.easyrdf.org/ http://wifo5-03.informatik.uni-mannheim.de/bizer/rdfapi/ http://graphite.ecs.soton.ac.uk/

Hope it helps!

x-fran commented 8 years ago

Sorry, I was a little bit busy. I will take a look and see what is happening. I'm sure all this info it will help. Thank you.

x-fran commented 8 years ago

I performed the changes. Is working as expected.

m1ci commented 8 years ago

Great! let us know if you need any help, ... any feedback is also more than welcome!