You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
329 lines
28 KiB
329 lines
28 KiB
4 years ago
|
"""
|
||
|
sphinx.search.it
|
||
|
~~~~~~~~~~~~~~~~
|
||
|
|
||
|
Italian search language: includes the JS Italian stemmer.
|
||
|
|
||
|
:copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
|
||
|
:license: BSD, see LICENSE for details.
|
||
|
"""
|
||
|
|
||
|
from typing import Dict
|
||
|
|
||
|
import snowballstemmer
|
||
|
|
||
|
from sphinx.search import SearchLanguage, parse_stop_word
|
||
|
|
||
|
italian_stopwords = parse_stop_word('''
|
||
|
| source: http://snowball.tartarus.org/algorithms/italian/stop.txt
|
||
|
ad | a (to) before vowel
|
||
|
al | a + il
|
||
|
allo | a + lo
|
||
|
ai | a + i
|
||
|
agli | a + gli
|
||
|
all | a + l'
|
||
|
agl | a + gl'
|
||
|
alla | a + la
|
||
|
alle | a + le
|
||
|
con | with
|
||
|
col | con + il
|
||
|
coi | con + i (forms collo, cogli etc are now very rare)
|
||
|
da | from
|
||
|
dal | da + il
|
||
|
dallo | da + lo
|
||
|
dai | da + i
|
||
|
dagli | da + gli
|
||
|
dall | da + l'
|
||
|
dagl | da + gll'
|
||
|
dalla | da + la
|
||
|
dalle | da + le
|
||
|
di | of
|
||
|
del | di + il
|
||
|
dello | di + lo
|
||
|
dei | di + i
|
||
|
degli | di + gli
|
||
|
dell | di + l'
|
||
|
degl | di + gl'
|
||
|
della | di + la
|
||
|
delle | di + le
|
||
|
in | in
|
||
|
nel | in + el
|
||
|
nello | in + lo
|
||
|
nei | in + i
|
||
|
negli | in + gli
|
||
|
nell | in + l'
|
||
|
negl | in + gl'
|
||
|
nella | in + la
|
||
|
nelle | in + le
|
||
|
su | on
|
||
|
sul | su + il
|
||
|
sullo | su + lo
|
||
|
sui | su + i
|
||
|
sugli | su + gli
|
||
|
sull | su + l'
|
||
|
sugl | su + gl'
|
||
|
sulla | su + la
|
||
|
sulle | su + le
|
||
|
per | through, by
|
||
|
tra | among
|
||
|
contro | against
|
||
|
io | I
|
||
|
tu | thou
|
||
|
lui | he
|
||
|
lei | she
|
||
|
noi | we
|
||
|
voi | you
|
||
|
loro | they
|
||
|
mio | my
|
||
|
mia |
|
||
|
miei |
|
||
|
mie |
|
||
|
tuo |
|
||
|
tua |
|
||
|
tuoi | thy
|
||
|
tue |
|
||
|
suo |
|
||
|
sua |
|
||
|
suoi | his, her
|
||
|
sue |
|
||
|
nostro | our
|
||
|
nostra |
|
||
|
nostri |
|
||
|
nostre |
|
||
|
vostro | your
|
||
|
vostra |
|
||
|
vostri |
|
||
|
vostre |
|
||
|
mi | me
|
||
|
ti | thee
|
||
|
ci | us, there
|
||
|
vi | you, there
|
||
|
lo | him, the
|
||
|
la | her, the
|
||
|
li | them
|
||
|
le | them, the
|
||
|
gli | to him, the
|
||
|
ne | from there etc
|
||
|
il | the
|
||
|
un | a
|
||
|
uno | a
|
||
|
una | a
|
||
|
ma | but
|
||
|
ed | and
|
||
|
se | if
|
||
|
perché | why, because
|
||
|
anche | also
|
||
|
come | how
|
||
|
dov | where (as dov')
|
||
|
dove | where
|
||
|
che | who, that
|
||
|
chi | who
|
||
|
cui | whom
|
||
|
non | not
|
||
|
più | more
|
||
|
quale | who, that
|
||
|
quanto | how much
|
||
|
quanti |
|
||
|
quanta |
|
||
|
quante |
|
||
|
quello | that
|
||
|
quelli |
|
||
|
quella |
|
||
|
quelle |
|
||
|
questo | this
|
||
|
questi |
|
||
|
questa |
|
||
|
queste |
|
||
|
si | yes
|
||
|
tutto | all
|
||
|
tutti | all
|
||
|
|
||
|
| single letter forms:
|
||
|
|
||
|
a | at
|
||
|
c | as c' for ce or ci
|
||
|
e | and
|
||
|
i | the
|
||
|
l | as l'
|
||
|
o | or
|
||
|
|
||
|
| forms of avere, to have (not including the infinitive):
|
||
|
|
||
|
ho
|
||
|
hai
|
||
|
ha
|
||
|
abbiamo
|
||
|
avete
|
||
|
hanno
|
||
|
abbia
|
||
|
abbiate
|
||
|
abbiano
|
||
|
avrò
|
||
|
avrai
|
||
|
avrà
|
||
|
avremo
|
||
|
avrete
|
||
|
avranno
|
||
|
avrei
|
||
|
avresti
|
||
|
avrebbe
|
||
|
avremmo
|
||
|
avreste
|
||
|
avrebbero
|
||
|
avevo
|
||
|
avevi
|
||
|
aveva
|
||
|
avevamo
|
||
|
avevate
|
||
|
avevano
|
||
|
ebbi
|
||
|
avesti
|
||
|
ebbe
|
||
|
avemmo
|
||
|
aveste
|
||
|
ebbero
|
||
|
avessi
|
||
|
avesse
|
||
|
avessimo
|
||
|
avessero
|
||
|
avendo
|
||
|
avuto
|
||
|
avuta
|
||
|
avuti
|
||
|
avute
|
||
|
|
||
|
| forms of essere, to be (not including the infinitive):
|
||
|
sono
|
||
|
sei
|
||
|
è
|
||
|
siamo
|
||
|
siete
|
||
|
sia
|
||
|
siate
|
||
|
siano
|
||
|
sarò
|
||
|
sarai
|
||
|
sarà
|
||
|
saremo
|
||
|
sarete
|
||
|
saranno
|
||
|
sarei
|
||
|
saresti
|
||
|
sarebbe
|
||
|
saremmo
|
||
|
sareste
|
||
|
sarebbero
|
||
|
ero
|
||
|
eri
|
||
|
era
|
||
|
eravamo
|
||
|
eravate
|
||
|
erano
|
||
|
fui
|
||
|
fosti
|
||
|
fu
|
||
|
fummo
|
||
|
foste
|
||
|
furono
|
||
|
fossi
|
||
|
fosse
|
||
|
fossimo
|
||
|
fossero
|
||
|
essendo
|
||
|
|
||
|
| forms of fare, to do (not including the infinitive, fa, fat-):
|
||
|
faccio
|
||
|
fai
|
||
|
facciamo
|
||
|
fanno
|
||
|
faccia
|
||
|
facciate
|
||
|
facciano
|
||
|
farò
|
||
|
farai
|
||
|
farà
|
||
|
faremo
|
||
|
farete
|
||
|
faranno
|
||
|
farei
|
||
|
faresti
|
||
|
farebbe
|
||
|
faremmo
|
||
|
fareste
|
||
|
farebbero
|
||
|
facevo
|
||
|
facevi
|
||
|
faceva
|
||
|
facevamo
|
||
|
facevate
|
||
|
facevano
|
||
|
feci
|
||
|
facesti
|
||
|
fece
|
||
|
facemmo
|
||
|
faceste
|
||
|
fecero
|
||
|
facessi
|
||
|
facesse
|
||
|
facessimo
|
||
|
facessero
|
||
|
facendo
|
||
|
|
||
|
| forms of stare, to be (not including the infinitive):
|
||
|
sto
|
||
|
stai
|
||
|
sta
|
||
|
stiamo
|
||
|
stanno
|
||
|
stia
|
||
|
stiate
|
||
|
stiano
|
||
|
starò
|
||
|
starai
|
||
|
starà
|
||
|
staremo
|
||
|
starete
|
||
|
staranno
|
||
|
starei
|
||
|
staresti
|
||
|
starebbe
|
||
|
staremmo
|
||
|
stareste
|
||
|
starebbero
|
||
|
stavo
|
||
|
stavi
|
||
|
stava
|
||
|
stavamo
|
||
|
stavate
|
||
|
stavano
|
||
|
stetti
|
||
|
stesti
|
||
|
stette
|
||
|
stemmo
|
||
|
steste
|
||
|
stettero
|
||
|
stessi
|
||
|
stesse
|
||
|
stessimo
|
||
|
stessero
|
||
|
''')
|
||
|
|
||
|
js_stemmer = """
|
||
|
var JSX={};(function(k){function l(b,e){var a=function(){};a.prototype=e.prototype;var c=new a;for(var d in b){b[d].prototype=c}}function K(c,b){for(var a in b.prototype)if(b.prototype.hasOwnProperty(a))c.prototype[a]=b.prototype[a]}function e(a,b,d){function c(a,b,c){delete a[b];a[b]=c;return c}Object.defineProperty(a,b,{get:function(){return c(a,b,d())},set:function(d){c(a,b,d)},enumerable:true,configurable:true})}function L(a,b,c){return a[b]=a[b]/c|0}var r=parseInt;var B=parseFloat;function M(a){return a!==a}var z=isFinite;var y=encodeURIComponent;var x=decodeURIComponent;var w=encodeURI;var u=decodeURI;var t=Object.prototype.toString;var C=Object.prototype.hasOwnProperty;function j(){}k.require=function(b){var a=q[b];return a!==undefined?a:null};k.profilerIsRunning=function(){return j.getResults!=null};k.getProfileResults=function(){return(j.getResults||function(){return{}})()};k.postProfileResults=function(a,b){if(j.postResults==null)throw new Error('profiler has not been turned on');return j.postResults(a,b)};k.resetProfileResults=function(){if(j.resetResults==null)throw new Error('profiler has not been turned on');return j.resetResults()};k.DEBUG=false;function s(){};l([s],Error);function a(a,b,c){this.F=a.length;this.K=a;this.L=b;this.I=c;this.H=null;this.P=null};l([a],Object);function p(){};l([p],Object);function i(){var a;var b;var c;this.G={};a=this.E='';b=this._=0;c=this.A=a.length;this.D=0;this.C=b;this.B=c};l([i],p);function v(a,b){a.E=b.E;a._=b._;a.A=b.A;a.D=b.D;a.C=b.C;a.B=b.B};function d(b,d,c,e){var a;if(b._>=b.A){return false}a=b.E.charCodeAt(b._);if(a>e||a<c){return false}a-=c;if((d[a>>>3]&1<<(a&7))===0){return false}b._++;return true};function m(b,d,c,e){var a;if(b._<=b.D){return false}a=b.E.charCodeAt(b._-1);if(a>e||a<c){return false}a-=c;if((d[a>>>3]&1<<(a&7))===0){return false}b._--;return true};function h(a,d,c,e){var b;if(a._>=a.A){return false}b=a.E.charCodeAt(a._);if(b>e||b<c){a._++;return true}b-=c;if((d[b>>>3]&1<<(b&7))===0){a._++;return true}return false};function o(a,b,d){var c;if(a.A-a._<b){return false}if(a.E.slice(c=a._,c+b)!==d){return false}a._+=b;return true};function g(a,b,d){var c;if(a._-a.D<b){return false}if(a.E.slice((c=a._)-b,c)!==d){return false}a._-=b;return true};function n(f,m,p){var b;var d;var e;var n;var g;var k;var l;var i;var h;var c;var a;var j;var o;b=0;d=p;e=f._;n=f.A;g=0;k=0;l=false;while(true){i=b+(d-b>>>1);h=0;c=g<k?g:k;a=m[i];for(j=c;j<a.F;j++){if(e+c===n){h=-1;break}h=f.E.charCodeAt(e+c)-a.K.charCodeAt(j);if(h!==0){break}c++}if(h<0){d=i;k=c}else{b=i;g=c}if(d-b<=1){if(b>0){break}if(d===b){break}if(l){break}l=true}}while(true){a=m[b];if(g>=a.F){f._=e+a.F|0;if(a.H==null){return a.I}o=a.H(a.P);f._=e+a.F|0;if(o){return a.I}}b=a.L;if(b<0){return 0}}return-1};function f(d,m,p){var b;var g;var e;var n;var f;var k;var l;var i;var h;var c;var a;var j;var o;b=0;g=p;e=d._;n=d.D;f=0;k=0;l=false;while(true){i=b+(g-b>>1);h=0;c=f<k?f:k;a=m[i];for(j=a.F-1-c;j>=0;j--){if(e-c===n){h=-1;break}h=d.E.charCodeAt(e-1-c)-a.K.charCodeAt(j);if(h!==0){break}c++}if(h<0){g=i;k=c}else{b=i;f=c}if(g-b<=1){if(b>0){break}if(g===b){break}if(l){break}l=true}}while(true){a=m[b];if(f>=a.F){d._=e-a.F|0;if(a.H==null){return a.I}o=a.H(d);d._=e-a.F|0;if(o){return a.I}}b=a.L;if(b<0){return 0}}return-1};function D(a,b,d,e){var c;c=e.length-(d-b);a.E=a.E.slice(0,b)+e+a.E.slice(d);a.A+=c|0;if(a._>=d){a._+=c|0}else if(a._>b){a._=b}return c|0};function c(a,f){var b;var c;var d;var e;b=false;if((c=a.C)<0||c>(d=a.B)||d>(e=a.A)||e>a.E.length?false:true){D(a,a.C,a.B,f);b=true}return b};i.prototype.J=function(){return false};i.prototype.a=function(b){var a;var c;var d;var e;a=this.G['.'+b];if(a==null){c=this.E=b;d=this._=0;e=this.A=c.length;this.D=0;this.C=d;this.B=e;this.J();a=this.E;this.G['.'+b]=a}return a};i.prototype.stemWord=i.prototype.a;i.prototype.b=function(e){var d;var b;var c;var a;var f;var g;var h;d=[];for(b=0;b<e.length;b++){c=e[b];a=this.G['.'+c];if(a==null){f=this.E=c;g=this._=0;h=this.A=f.length;this.D=0;this.C=g;this.B=h;this.J();a=this.E;this.G['.'+c]=a}d.push(a)}return d};i.prototype.stemWor
|
||
|
var Stemmer = JSX.require("src/italian-stemmer.jsx").ItalianStemmer;
|
||
|
"""
|
||
|
|
||
|
|
||
|
class SearchItalian(SearchLanguage):
|
||
|
lang = 'it'
|
||
|
language_name = 'Italian'
|
||
|
js_stemmer_rawcode = 'italian-stemmer.js'
|
||
|
js_stemmer_code = js_stemmer
|
||
|
stopwords = italian_stopwords
|
||
|
|
||
|
def init(self, options: Dict) -> None:
|
||
|
self.stemmer = snowballstemmer.stemmer('italian')
|
||
|
|
||
|
def stem(self, word: str) -> str:
|
||
|
return self.stemmer.stemWord(word.lower())
|