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.
275 lines
26 KiB
275 lines
26 KiB
4 years ago
|
"""
|
||
|
sphinx.search.pt
|
||
|
~~~~~~~~~~~~~~~~
|
||
|
|
||
|
Portuguese search language: includes the JS Portuguese 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
|
||
|
|
||
|
portuguese_stopwords = parse_stop_word('''
|
||
|
| source: http://snowball.tartarus.org/algorithms/portuguese/stop.txt
|
||
|
de | of, from
|
||
|
a | the; to, at; her
|
||
|
o | the; him
|
||
|
que | who, that
|
||
|
e | and
|
||
|
do | de + o
|
||
|
da | de + a
|
||
|
em | in
|
||
|
um | a
|
||
|
para | for
|
||
|
| é from SER
|
||
|
com | with
|
||
|
não | not, no
|
||
|
uma | a
|
||
|
os | the; them
|
||
|
no | em + o
|
||
|
se | himself etc
|
||
|
na | em + a
|
||
|
por | for
|
||
|
mais | more
|
||
|
as | the; them
|
||
|
dos | de + os
|
||
|
como | as, like
|
||
|
mas | but
|
||
|
| foi from SER
|
||
|
ao | a + o
|
||
|
ele | he
|
||
|
das | de + as
|
||
|
| tem from TER
|
||
|
à | a + a
|
||
|
seu | his
|
||
|
sua | her
|
||
|
ou | or
|
||
|
| ser from SER
|
||
|
quando | when
|
||
|
muito | much
|
||
|
| há from HAV
|
||
|
nos | em + os; us
|
||
|
já | already, now
|
||
|
| está from EST
|
||
|
eu | I
|
||
|
também | also
|
||
|
só | only, just
|
||
|
pelo | per + o
|
||
|
pela | per + a
|
||
|
até | up to
|
||
|
isso | that
|
||
|
ela | he
|
||
|
entre | between
|
||
|
| era from SER
|
||
|
depois | after
|
||
|
sem | without
|
||
|
mesmo | same
|
||
|
aos | a + os
|
||
|
| ter from TER
|
||
|
seus | his
|
||
|
quem | whom
|
||
|
nas | em + as
|
||
|
me | me
|
||
|
esse | that
|
||
|
eles | they
|
||
|
| estão from EST
|
||
|
você | you
|
||
|
| tinha from TER
|
||
|
| foram from SER
|
||
|
essa | that
|
||
|
num | em + um
|
||
|
nem | nor
|
||
|
suas | her
|
||
|
meu | my
|
||
|
às | a + as
|
||
|
minha | my
|
||
|
| têm from TER
|
||
|
numa | em + uma
|
||
|
pelos | per + os
|
||
|
elas | they
|
||
|
| havia from HAV
|
||
|
| seja from SER
|
||
|
qual | which
|
||
|
| será from SER
|
||
|
nós | we
|
||
|
| tenho from TER
|
||
|
lhe | to him, her
|
||
|
deles | of them
|
||
|
essas | those
|
||
|
esses | those
|
||
|
pelas | per + as
|
||
|
este | this
|
||
|
| fosse from SER
|
||
|
dele | of him
|
||
|
|
||
|
| other words. There are many contractions such as naquele = em+aquele,
|
||
|
| mo = me+o, but they are rare.
|
||
|
| Indefinite article plural forms are also rare.
|
||
|
|
||
|
tu | thou
|
||
|
te | thee
|
||
|
vocês | you (plural)
|
||
|
vos | you
|
||
|
lhes | to them
|
||
|
meus | my
|
||
|
minhas
|
||
|
teu | thy
|
||
|
tua
|
||
|
teus
|
||
|
tuas
|
||
|
nosso | our
|
||
|
nossa
|
||
|
nossos
|
||
|
nossas
|
||
|
|
||
|
dela | of her
|
||
|
delas | of them
|
||
|
|
||
|
esta | this
|
||
|
estes | these
|
||
|
estas | these
|
||
|
aquele | that
|
||
|
aquela | that
|
||
|
aqueles | those
|
||
|
aquelas | those
|
||
|
isto | this
|
||
|
aquilo | that
|
||
|
|
||
|
| forms of estar, to be (not including the infinitive):
|
||
|
estou
|
||
|
está
|
||
|
estamos
|
||
|
estão
|
||
|
estive
|
||
|
esteve
|
||
|
estivemos
|
||
|
estiveram
|
||
|
estava
|
||
|
estávamos
|
||
|
estavam
|
||
|
estivera
|
||
|
estivéramos
|
||
|
esteja
|
||
|
estejamos
|
||
|
estejam
|
||
|
estivesse
|
||
|
estivéssemos
|
||
|
estivessem
|
||
|
estiver
|
||
|
estivermos
|
||
|
estiverem
|
||
|
|
||
|
| forms of haver, to have (not including the infinitive):
|
||
|
hei
|
||
|
há
|
||
|
havemos
|
||
|
hão
|
||
|
houve
|
||
|
houvemos
|
||
|
houveram
|
||
|
houvera
|
||
|
houvéramos
|
||
|
haja
|
||
|
hajamos
|
||
|
hajam
|
||
|
houvesse
|
||
|
houvéssemos
|
||
|
houvessem
|
||
|
houver
|
||
|
houvermos
|
||
|
houverem
|
||
|
houverei
|
||
|
houverá
|
||
|
houveremos
|
||
|
houverão
|
||
|
houveria
|
||
|
houveríamos
|
||
|
houveriam
|
||
|
|
||
|
| forms of ser, to be (not including the infinitive):
|
||
|
sou
|
||
|
somos
|
||
|
são
|
||
|
era
|
||
|
éramos
|
||
|
eram
|
||
|
fui
|
||
|
foi
|
||
|
fomos
|
||
|
foram
|
||
|
fora
|
||
|
fôramos
|
||
|
seja
|
||
|
sejamos
|
||
|
sejam
|
||
|
fosse
|
||
|
fôssemos
|
||
|
fossem
|
||
|
for
|
||
|
formos
|
||
|
forem
|
||
|
serei
|
||
|
será
|
||
|
seremos
|
||
|
serão
|
||
|
seria
|
||
|
seríamos
|
||
|
seriam
|
||
|
|
||
|
| forms of ter, to have (not including the infinitive):
|
||
|
tenho
|
||
|
tem
|
||
|
temos
|
||
|
tém
|
||
|
tinha
|
||
|
tínhamos
|
||
|
tinham
|
||
|
tive
|
||
|
teve
|
||
|
tivemos
|
||
|
tiveram
|
||
|
tivera
|
||
|
tivéramos
|
||
|
tenha
|
||
|
tenhamos
|
||
|
tenham
|
||
|
tivesse
|
||
|
tivéssemos
|
||
|
tivessem
|
||
|
tiver
|
||
|
tivermos
|
||
|
tiverem
|
||
|
terei
|
||
|
terá
|
||
|
teremos
|
||
|
terão
|
||
|
teria
|
||
|
teríamos
|
||
|
teriam
|
||
|
''')
|
||
|
|
||
|
js_stemmer = """
|
||
|
|
||
|
var JSX={};(function(j){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 I(c,b){for(var a in b.prototype)if(b.prototype.hasOwnProperty(a))c.prototype[a]=b.prototype[a]}function h(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 J(a,b,c){return a[b]=a[b]/c|0}var p=parseInt;var z=parseFloat;function K(a){return a!==a}var x=isFinite;var w=encodeURIComponent;var u=decodeURIComponent;var t=encodeURI;var s=decodeURI;var A=Object.prototype.toString;var q=Object.prototype.hasOwnProperty;function k(){}j.require=function(b){var a=o[b];return a!==undefined?a:null};j.profilerIsRunning=function(){return k.getResults!=null};j.getProfileResults=function(){return(k.getResults||function(){return{}})()};j.postProfileResults=function(a,b){if(k.postResults==null)throw new Error('profiler has not been turned on');return k.postResults(a,b)};j.resetProfileResults=function(){if(k.resetResults==null)throw new Error('profiler has not been turned on');return k.resetResults()};j.DEBUG=false;function r(){};l([r],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 n(){};l([n],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.B=b;this.C=c};l([i],n);function v(a,b){a.E=b.E;a._=b._;a.A=b.A;a.D=b.D;a.B=b.B;a.C=b.C};function f(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 g(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 d(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 m(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 e(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 B(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.B)<0||c>(d=a.C)||d>(e=a.A)||e>a.E.length?false:true){B(a,a.B,a.C,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.B=d;this.C=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.B=g;this.C=h;this.J();a=this.E;this.G['.'+c]=a}d.push(a)}return d};i.prototype.stemWords=i.prototype.b;function b(){i.call(this);this.I_p2=0;this.I_p1=0;this.I_pV=0};l([b],i);b.prototype.M=function(a){this.I_p2=a.I_p2;this.I_p1=a.I_p1;this.I_pV=a.I_pV;v(this,a)};b.prototype.copy_from=b.prototype.M;b.prototype.V=function(){var a;var e;var d;b:while(true){e=this._;d
|
||
|
var Stemmer = JSX.require("src/portuguese-stemmer.jsx").PortugueseStemmer;
|
||
|
"""
|
||
|
|
||
|
|
||
|
class SearchPortuguese(SearchLanguage):
|
||
|
lang = 'pt'
|
||
|
language_name = 'Portuguese'
|
||
|
js_stemmer_rawcode = 'portuguese-stemmer.js'
|
||
|
js_stemmer_code = js_stemmer
|
||
|
stopwords = portuguese_stopwords
|
||
|
|
||
|
def init(self, options: Dict) -> None:
|
||
|
self.stemmer = snowballstemmer.stemmer('portuguese')
|
||
|
|
||
|
def stem(self, word: str) -> str:
|
||
|
return self.stemmer.stemWord(word.lower())
|