PayloadCheckerSpanFilter : Différence entre versions

De JDONREF Wiki
(Checkers)
 
(6 révisions intermédiaires par le même utilisateur non affichées)
Ligne 123 : Ligne 123 :
 
|-
 
|-
 
| Limit
 
| Limit
| Validate the "limit" first documents.
+
| No more available (>=0.4). Validate the "limit" first documents.
 
| { "type":"Limit", "limit" : 100 }
 
| { "type":"Limit", "limit" : 100 }
 
|-
 
|-
Ligne 131 : Ligne 131 :
 
|}
 
|}
   
  +
=====How it works=====
   
=====Principe de fonctionnement=====
 
  +
Elasticsearch is a flat inverted index document, it does not natively make a difference between one term or another. As an example, it uses frequencies to seek for terms in a corpus.
   
ElasticSearch étant un moteur d'indexation à plat, il ne fait pas nativement de distinction entre les termes qu'il indexe. ElasticSearch s'appuie par exemple sur la fréquence des termes dans l'ensemble du corpus.
 
  +
However, in a simple sentence, like an adress, terms might be very differents. Frequency might not be usable in such cases.
   
Toutefois, dans une adresse, les éléments qui la compose peuvent avoir une importance très différente dans l'adresse. Notamment, ce n'est pas toujours leur fréquence qui guide leur importance.
 
  +
For example for the request :
 
Par exemple concernant la requête :
 
 
57 BD DE L HOPITAL 75 PARIS
 
57 BD DE L HOPITAL 75 PARIS
   
A la saisie de cette adresse, on ne s'attendrait pas à retrouver des résultats tels que :
 
  +
We are not intend to get such results :
75 BD DE L HOPITAL 75013 PARIS (le numéro de voie 75)
+
75 BD DE L HOPITAL 75013 PARIS (75 as the number of the adress)
75 rue de paris 57 L HOPITAL (la ville l'hopital en moselle, la voie n'existe pas il s'agit d'un exemple)
+
75 rue de paris 57 L HOPITAL (the town L HOPITAL in Moselle, it do not exists in real life, it's an example)
   
L'exactitude du numéro d'adresse a ici une importance qui dépasse sa fréquence élevée d'apparition dans le corpus.
 
  +
The exactitude of the number of the adresse is here more important than its frequency in the corpus.
   
Pour mettre en avant les résultats les plus pertinents, ElasticSearch s'appuie sur le moteur lucene qui attribue une note à chaque résultat. JDONREFv4 surcharge ce système de notation et attribue une nouvelle note à chaque résultat. Pour tout dire, le plugin ne met pas en avant les bons résultats, il dégrade les mauvais.
 
  +
To get the most pertinent results, ElasticSearch uses lucene engine to get a score for each results. PayloadCheckerSpanQuery overload that scorer with a new score for each results. Actually, it descores bad results.
   
=====Notation=====
+
=====Performance consideration=====
   
Le système de notation mis en oeuvre par JDONREFv4 a plusieurs objectifs :
 
  +
Notice check for span may result slower than a simple match query !
#mettre en avant les résultats les plus pertinents
 
  +
Although the result will match your working rules, the query will scan over ever document matching your query terms.
#disposer d'une notation absolue, permettant à une IA d'effectuer un choix objectif parmi les propositions de résultats (voir le mode bulk plus loin)
 
  +
Here is two tips to gain performances :
  +
#terms are internally set in order of term frequencies. That mean if your request is 'RUE EIFFEL', the internal request will be 'EIFFEL RUE'. The number of document checked for 'RUE' term will be down to 'EIFFEL' count. Of course, GroupedPayload and OneBeforeAnother checkers support this.
  +
#you can reduce fonctionnality when terms are too frequent. That mean a request for 'RUE' whom results are about 600 000 documents in FRANCE, will bypass payload checker to give a null response. With more terms (like RUE EIFFEL), the checker will be on again. The query got a "limit" parameter to set the number of documents not to reach. This parameter is usefull when you request over multiple indexes with differents level of details.
   
L'algorithme de notation reprend celui de JDONREFv2 et JDONREFv3, adapté à une recherche par index inversé.
 
  +
=====Scoring (soon)=====
   
Plutôt que d'affecter un poids à chaque élément de l'adresse, il s'appuie simplement sur une version légèrement adapté de la classe DefaultSimilarity d'ElasticSearch.
 
  +
Scoring System of PayloadCheckerSpanQuery got two objectives :
Il est (sera) possible de choisir les éléments qui participent à cette notation.
 
  +
#give the most representative results
  +
#get an absolute notation , than mean an AI would pick the good choice between the results (see bulk mode)
   
Le mode bulk permet de disposer d'un notation absolue, c'est à dire dont la note maximale est 200. Le plafond est déterminé par la note maximale qu'il est possible d'avoir pour chaque document. Le score est ensuite rapporté sur 200 par une simple règle de trois, par simple commodité (sinon tous les scores seraient inférieurs ou égaux à 1).
 
  +
The scoring concept follows the SpanScorer and the BooleanScorer, and is inspired by scoring in JDONREFv2 and JDONREFv3 (adapted to inversed index).
A noter que ce mode bulk nécessite un peu plus de calcul que la note traditionnelle, c'est pourquoi il s'agit d'une option.
 
  +
It was necessary to change the DefaultSimilarity class.
Le mode bulk n'est pas nécessaire lorsqu'un être humain peut choisir l'adresse parmi plusieurs propositions. Par contre, le fait de disposer d'une note plafonnée (sur 200) va permettre à une IA de choisir lui-même la proposition en lui fixant un seuil (par exemple, l'adresse est choisie si sa note est supérieure à 180).
 
   
Pour le moment, les éléments pris en compte sont présentés dans le tableau ci-dessous.
 
{| border="1"
 
| '''éléments'''
 
| '''remarque'''
 
|-
 
| ligne 1
 
|
 
|-
 
| ligne 4
 
| Elle peut ou pas contenir le numéro d'adresse. La présence du numéro conditionne un malus.
 
|-
 
| codes
 
| Il est construit à partir des champs code postal / code insee / code departement / code arrondissement. Contrairement aux autres champs, il suffit d'avoir l'un d'entre eux présent pour obtenir la note maximale.
 
|-
 
| commune
 
|
 
|-
 
| ligne 7
 
|
 
|-
 
| code_pays
 
| Le code pays n'est actuellement pas pris en compte, mais aura probablement le même poids que la ligne7.
 
|}
 
   
Plusieurs malus sont ensuite appliqués à la somme totale :
 
  +
The bulk mode is a mode where score get a ceiling. The ceiling for a result is the maximum score it is possible to get with it. So the bulk mode is simply the score divided by the maximum score. Then it's applying a rule of three to the ceiling for commodity (something like 100% or 20/20).
#si l'ordre des termes appartenant à un élément ne sont pas consécutifs. Sa valeur est de 0.5 pour chaque terme discordant. C'est très pénalisant.
 
  +
#s'il s'agit d'une adresse, et que l'adresse n'est pas présente (ou erronée), la note est 0. Les résultats disposant d'un numéro d'adresse erroné ne sont donc pas retournés (le nombre de faux positif est trop important).
 
  +
The bulk mode is less performant than traditionnal way, so it is not recommended for autocomplete, and it is made like an option mode.
#si le document ne dispose pas de numéro d'adresse, mais qu'un numéro est présent devant la voie, un malus de 0.5 est appliqué (cela complète en quelque sorte le malus sur l'ordre des termes)
 
  +
It is not necessary when a human being can choose between results. But an IA can choose automatically a result when the score is for example over 19/20.
#s'il s'agit d'un POI ou d'une Zone, la ligne1 ou la ligne4 doit être présente, sinon la note est 0.
 
  +
#s'il s'agit d'une voie ou d'une adresse, la ligne4 et codes ou commune doit être présent, sinon la note est 0.
 
  +
=====Customise Scoring=====
#s'il s'agit d'une commune, le champ codes ou commune doit être présent, sinon la note est 0.
 
  +
#s'il s'agit d'un département, le champ codes doit être présent, sinon la note est 0.
 
  +
(soon)
#s'il s'agit d'un pays, le champ ligne7 doit être présent, sinon la note est 0.
 
   
 
===== See also =====
 
===== See also =====

Version actuelle en date du 3 mai 2015 à 08:33

Check results for grammar rules according to payloads values.

Sample

For example, the document :

 { "fullName": "BOULEVARD|1 DE|1 PARIS|1 07|2 L|3 HOPITAL|3" }

with the following mapping :

 "fullName" : {"type": "string", "term_vector" : "with_positions_offsets_payloads", "index_analyzer":"myAnalyzer"}

and settings like :

 {
   "index" : {
      "analysis" : {
          "analyzer": {
              "myAnalyzer" : {
                  "type" : "custom",
                  "tokenizer" : "whitespace",
                  "filter" : ["delimited_payload_filter", "lowercase", "tokencount_payload_filter"]
              }
          },
          "filter" : {
              "delimited_payload_filter" : {
                "type": "delimited_payload_filter",
                "delimiter" : "|",
                "encoding" : "int"
              },
              "tokencount_payload_filter" : {
                "type": "tokencountpayloads",
                "factor": 1000
              }
      }
 } 

will match the query :

 {
   "span_payloadchecker" : {
       "clauses": [
         { "span_multipayloadterm" : { "fullName": "BOULEVARD" } },
         { "span_multipayloadterm" : { "fullName": "PARIS" } },
         { "span_multipayloadterm" : { "fullName": "HOPITAL" } }
       ],
       "checker": { "type":"Grouped" }
   }
 }

but not match the following :

 {
   "span_payloadchecker" : {
       "clauses": [
         { "span_multipayloadterm" : { "fullName": "BOULEVARD" } },
         { "span_multipayloadterm" : { "fullName": "HOPITAL" } }
         { "span_multipayloadterm" : { "fullName": "PARIS" } },
       ],
       "checker": { "type":"Grouped" }
   }
 }

because eventhough they got the same payload BOULEVARD and PARIS are not grouped together in the second request.


Checkers

Notice the following checkers :

checker type description sample
And All the given checkers from data array must validate to validate the document { "type":"And", "checkers" : [ ... ] }
Or One of the given checkers from data array must validate to validate the document { "type":"Or", "checkers" : [ ... ] }
Xor Only one of the given checkers from data array must validate to validate the document { "type":"Xor", "checkers" : [ ... ] }
Not The given checker 'data' must not validate to validate the document { "type":"Not", "checker" : { ... } }
All All the tokens with the given payload (bytes[] or int) must match to validate the document. You will need tokencountpayloads token filter for that. { "type":"All", "payload" : "AAAD8Q==" }
One One token with the given payload (bytes[] or int) must match to validate the document { "type":"One", "payload" : "AAAD8Q==" }
Field Field value (default to _type) must match to validate the document { "type":"Field", "field" : "type_de_voie", "value" : "BOULEVARD" }
Grouped Groups of tokens by payloads must not interlace to validate the document { "type":"Grouped" }
BeforeAnother Check whether tokens with a given payload are just before another group of payloads { "type":"BeforeAnother", "payloadbefore" : "AAAD8Q==", "another" : "AAAD8Q==" }
If If the condition match, the then clause must match to validate the document. Otherwise it matches. Be aware of performances. { "type":"If", "condition" : {...}, "then" : {...} }
IfElse If the condition match, the then clause must match to validate the document. If the condition does not match, the else clause must match to validate the document. Be aware of performances (see Switch) { "type":"IfElse", "condition" : {...}, "then" : {...}, "else" : {...} }
Switch If a switch condition clause match, the switch clause must match to validate the document. Default not customizable set to true (Null). { "type":"Switch", "field" : "_type", "clauses" : { "adresse": { ... }, "commune": { ... } } }
Limit No more available (>=0.4). Validate the "limit" first documents. { "type":"Limit", "limit" : 100 }
Null Validate all documents { "type":"Null" }
How it works

Elasticsearch is a flat inverted index document, it does not natively make a difference between one term or another. As an example, it uses frequencies to seek for terms in a corpus.

However, in a simple sentence, like an adress, terms might be very differents. Frequency might not be usable in such cases.

For example for the request :

 57 BD DE L HOPITAL 75 PARIS

We are not intend to get such results :

 75 BD DE L HOPITAL 75013 PARIS (75 as the number of the adress)
 75 rue de paris 57 L HOPITAL (the town L HOPITAL in Moselle, it do not exists in real life, it's an example)

The exactitude of the number of the adresse is here more important than its frequency in the corpus.

To get the most pertinent results, ElasticSearch uses lucene engine to get a score for each results. PayloadCheckerSpanQuery overload that scorer with a new score for each results. Actually, it descores bad results.

Performance consideration

Notice check for span may result slower than a simple match query ! Although the result will match your working rules, the query will scan over ever document matching your query terms. Here is two tips to gain performances :

  1. terms are internally set in order of term frequencies. That mean if your request is 'RUE EIFFEL', the internal request will be 'EIFFEL RUE'. The number of document checked for 'RUE' term will be down to 'EIFFEL' count. Of course, GroupedPayload and OneBeforeAnother checkers support this.
  2. you can reduce fonctionnality when terms are too frequent. That mean a request for 'RUE' whom results are about 600 000 documents in FRANCE, will bypass payload checker to give a null response. With more terms (like RUE EIFFEL), the checker will be on again. The query got a "limit" parameter to set the number of documents not to reach. This parameter is usefull when you request over multiple indexes with differents level of details.
Scoring (soon)

Scoring System of PayloadCheckerSpanQuery got two objectives :

  1. give the most representative results
  2. get an absolute notation , than mean an AI would pick the good choice between the results (see bulk mode)

The scoring concept follows the SpanScorer and the BooleanScorer, and is inspired by scoring in JDONREFv2 and JDONREFv3 (adapted to inversed index). It was necessary to change the DefaultSimilarity class.


The bulk mode is a mode where score get a ceiling. The ceiling for a result is the maximum score it is possible to get with it. So the bulk mode is simply the score divided by the maximum score. Then it's applying a rule of three to the ceiling for commodity (something like 100% or 20/20).

The bulk mode is less performant than traditionnal way, so it is not recommended for autocomplete, and it is made like an option mode. It is not necessary when a human being can choose between results. But an IA can choose automatically a result when the score is for example over 19/20.

Customise Scoring

(soon)

See also

EdgeNGramWithPayloadsFilter

TokenCountPayloadFilter