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.
215 lines
14 KiB
215 lines
14 KiB
4 years ago
|
"""
|
||
|
sphinx.search.no
|
||
|
~~~~~~~~~~~~~~~~
|
||
|
|
||
|
Norwegian search language: includes the JS Norwegian 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
|
||
|
|
||
|
norwegian_stopwords = parse_stop_word('''
|
||
|
| source: http://snowball.tartarus.org/algorithms/norwegian/stop.txt
|
||
|
og | and
|
||
|
i | in
|
||
|
jeg | I
|
||
|
det | it/this/that
|
||
|
at | to (w. inf.)
|
||
|
en | a/an
|
||
|
et | a/an
|
||
|
den | it/this/that
|
||
|
til | to
|
||
|
er | is/am/are
|
||
|
som | who/that
|
||
|
på | on
|
||
|
de | they / you(formal)
|
||
|
med | with
|
||
|
han | he
|
||
|
av | of
|
||
|
ikke | not
|
||
|
ikkje | not *
|
||
|
der | there
|
||
|
så | so
|
||
|
var | was/were
|
||
|
meg | me
|
||
|
seg | you
|
||
|
men | but
|
||
|
ett | one
|
||
|
har | have
|
||
|
om | about
|
||
|
vi | we
|
||
|
min | my
|
||
|
mitt | my
|
||
|
ha | have
|
||
|
hadde | had
|
||
|
hun | she
|
||
|
nå | now
|
||
|
over | over
|
||
|
da | when/as
|
||
|
ved | by/know
|
||
|
fra | from
|
||
|
du | you
|
||
|
ut | out
|
||
|
sin | your
|
||
|
dem | them
|
||
|
oss | us
|
||
|
opp | up
|
||
|
man | you/one
|
||
|
kan | can
|
||
|
hans | his
|
||
|
hvor | where
|
||
|
eller | or
|
||
|
hva | what
|
||
|
skal | shall/must
|
||
|
selv | self (reflective)
|
||
|
sjøl | self (reflective)
|
||
|
her | here
|
||
|
alle | all
|
||
|
vil | will
|
||
|
bli | become
|
||
|
ble | became
|
||
|
blei | became *
|
||
|
blitt | have become
|
||
|
kunne | could
|
||
|
inn | in
|
||
|
når | when
|
||
|
være | be
|
||
|
kom | come
|
||
|
noen | some
|
||
|
noe | some
|
||
|
ville | would
|
||
|
dere | you
|
||
|
som | who/which/that
|
||
|
deres | their/theirs
|
||
|
kun | only/just
|
||
|
ja | yes
|
||
|
etter | after
|
||
|
ned | down
|
||
|
skulle | should
|
||
|
denne | this
|
||
|
for | for/because
|
||
|
deg | you
|
||
|
si | hers/his
|
||
|
sine | hers/his
|
||
|
sitt | hers/his
|
||
|
mot | against
|
||
|
å | to
|
||
|
meget | much
|
||
|
hvorfor | why
|
||
|
dette | this
|
||
|
disse | these/those
|
||
|
uten | without
|
||
|
hvordan | how
|
||
|
ingen | none
|
||
|
din | your
|
||
|
ditt | your
|
||
|
blir | become
|
||
|
samme | same
|
||
|
hvilken | which
|
||
|
hvilke | which (plural)
|
||
|
sånn | such a
|
||
|
inni | inside/within
|
||
|
mellom | between
|
||
|
vår | our
|
||
|
hver | each
|
||
|
hvem | who
|
||
|
vors | us/ours
|
||
|
hvis | whose
|
||
|
både | both
|
||
|
bare | only/just
|
||
|
enn | than
|
||
|
fordi | as/because
|
||
|
før | before
|
||
|
mange | many
|
||
|
også | also
|
||
|
slik | just
|
||
|
vært | been
|
||
|
være | to be
|
||
|
båe | both *
|
||
|
begge | both
|
||
|
siden | since
|
||
|
dykk | your *
|
||
|
dykkar | yours *
|
||
|
dei | they *
|
||
|
deira | them *
|
||
|
deires | theirs *
|
||
|
deim | them *
|
||
|
di | your (fem.) *
|
||
|
då | as/when *
|
||
|
eg | I *
|
||
|
ein | a/an *
|
||
|
eit | a/an *
|
||
|
eitt | a/an *
|
||
|
elles | or *
|
||
|
honom | he *
|
||
|
hjå | at *
|
||
|
ho | she *
|
||
|
hoe | she *
|
||
|
henne | her
|
||
|
hennar | her/hers
|
||
|
hennes | hers
|
||
|
hoss | how *
|
||
|
hossen | how *
|
||
|
ikkje | not *
|
||
|
ingi | noone *
|
||
|
inkje | noone *
|
||
|
korleis | how *
|
||
|
korso | how *
|
||
|
kva | what/which *
|
||
|
kvar | where *
|
||
|
kvarhelst | where *
|
||
|
kven | who/whom *
|
||
|
kvi | why *
|
||
|
kvifor | why *
|
||
|
me | we *
|
||
|
medan | while *
|
||
|
mi | my *
|
||
|
mine | my *
|
||
|
mykje | much *
|
||
|
no | now *
|
||
|
nokon | some (masc./neut.) *
|
||
|
noka | some (fem.) *
|
||
|
nokor | some *
|
||
|
noko | some *
|
||
|
nokre | some *
|
||
|
si | his/hers *
|
||
|
sia | since *
|
||
|
sidan | since *
|
||
|
so | so *
|
||
|
somt | some *
|
||
|
somme | some *
|
||
|
um | about*
|
||
|
upp | up *
|
||
|
vere | be *
|
||
|
vore | was *
|
||
|
verte | become *
|
||
|
vort | become *
|
||
|
varte | became *
|
||
|
vart | became *
|
||
|
''')
|
||
|
|
||
|
js_stemmer = """
|
||
|
var JSX={};(function(g){function i(b,e){var a=function(){};a.prototype=e.prototype;var c=new a;for(var d in b){b[d].prototype=c}}function G(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 H(a,b,c){return a[b]=a[b]/c|0}var B=parseInt;var q=parseFloat;function I(a){return a!==a}var y=isFinite;var x=encodeURIComponent;var w=decodeURIComponent;var u=encodeURI;var t=decodeURI;var s=Object.prototype.toString;var r=Object.prototype.hasOwnProperty;function h(){}g.require=function(b){var a=m[b];return a!==undefined?a:null};g.profilerIsRunning=function(){return h.getResults!=null};g.getProfileResults=function(){return(h.getResults||function(){return{}})()};g.postProfileResults=function(a,b){if(h.postResults==null)throw new Error('profiler has not been turned on');return h.postResults(a,b)};g.resetProfileResults=function(){if(h.resetResults==null)throw new Error('profiler has not been turned on');return h.resetResults()};g.DEBUG=false;function A(){};i([A],Error);function b(a,b,c){this.G=a.length;this.R=a;this.U=b;this.J=c;this.I=null;this.V=null};i([b],Object);function j(){};i([j],Object);function d(){var a;var b;var c;this.F={};a=this.C='';b=this._=0;c=this.A=a.length;this.B=0;this.D=b;this.E=c};i([d],j);function v(a,b){a.C=b.C;a._=b._;a.A=b.A;a.B=b.B;a.D=b.D;a.E=b.E};function l(b,d,c,e){var a;if(b._>=b.A){return false}a=b.C.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 k(b,d,c,e){var a;if(b._<=b.B){return false}a=b.C.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 p(a,d,c,e){var b;if(a._>=a.A){return false}b=a.C.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,d,c,e){var b;if(a._<=a.B){return false}b=a.C.charCodeAt(a._-1);if(b>e||b<c){a._--;return true}b-=c;if((d[b>>>3]&1<<(b&7))===0){a._--;return true}return false};function n(a,b,d){var c;if(a._-a.B<b){return false}if(a.C.slice((c=a._)-b,c)!==d){return false}a._-=b;return true};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.B;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.G-1-c;j>=0;j--){if(e-c===n){h=-1;break}h=d.C.charCodeAt(e-1-c)-a.R.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.G){d._=e-a.G|0;if(a.I==null){return a.J}o=a.I(d);d._=e-a.G|0;if(o){return a.J}}b=a.U;if(b<0){return 0}}return-1};function C(a,b,d,e){var c;c=e.length-(d-b);a.C=a.C.slice(0,b)+e+a.C.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.D)<0||c>(d=a.E)||d>(e=a.A)||e>a.C.length?false:true){C(a,a.D,a.E,f);b=true}return b};d.prototype.H=function(){return false};d.prototype.S=function(b){var a;var c;var d;var e;a=this.F['.'+b];if(a==null){c=this.C=b;d=this._=0;e=this.A=c.length;this.B=0;this.D=d;this.E=e;this.H();a=this.C;this.F['.'+b]=a}return a};d.prototype.stemWord=d.prototype.S;d.prototype.T=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.F['.'+c];if(a==null){f=this.C=c;g=this._=0;h=this.A=f.length;this.B=0;this.D=g;this.E=h;this.H();a=this.C;this.F['.'+c]=a}d.push(a)}return d};d.prototype.stemWords=d.prototype.T;function a(){d.call(this);this.I_x=0;this.I_p1=0};i([a],d);a.prototype.K=function(a){this.I_x=a.I_x;this.I_p1=a.I_p1;v(this,a)};a.prototype.copy_from=a.prototype.K;a.prototype.P=function(){var g;var d;var b;var e;var c;var f;var i;var j;var k;var h;this.I_p1=j=this.A;g=i=this._;b=i+3|0;if(0>b||b>j){return false}h=this._=b;this.I_x=h;this._=g;a:while(true){d=this._;e=true;b:while(e===true){e=false;if(!l(this,a.g_v,97,248)){break b}thi
|
||
|
var Stemmer = JSX.require("src/norwegian-stemmer.jsx").NorwegianStemmer;
|
||
|
"""
|
||
|
|
||
|
|
||
|
class SearchNorwegian(SearchLanguage):
|
||
|
lang = 'no'
|
||
|
language_name = 'Norwegian'
|
||
|
js_stemmer_rawcode = 'norwegian-stemmer.js'
|
||
|
js_stemmer_code = js_stemmer
|
||
|
stopwords = norwegian_stopwords
|
||
|
|
||
|
def init(self, options: Dict) -> None:
|
||
|
self.stemmer = snowballstemmer.stemmer('norwegian')
|
||
|
|
||
|
def stem(self, word: str) -> str:
|
||
|
return self.stemmer.stemWord(word.lower())
|