mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.8.4.1
This commit is contained in:
31
400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm.java
Normal file
31
400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_abrv_wm {
|
||||
public Xow_abrv_wm(byte[] raw, byte[] lang_domain, Xol_lang_itm lang_actl, int domain_type) {
|
||||
this.raw = raw;
|
||||
this.lang_domain = lang_domain;
|
||||
this.lang_actl = lang_actl;
|
||||
this.domain_type = domain_type;
|
||||
}
|
||||
public byte[] Raw() {return raw;} private final byte[] raw;
|
||||
public byte[] Lang_domain() {return lang_domain;} private final byte[] lang_domain;
|
||||
public Xol_lang_itm Lang_actl() {return lang_actl;} private final Xol_lang_itm lang_actl;
|
||||
public int Domain_type() {return domain_type;} private final int domain_type;
|
||||
}
|
||||
178
400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_.java
Normal file
178
400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_.java
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_abrv_wm_ {
|
||||
public static Xow_abrv_wm Parse_to_abrv_or_null(byte[] src) { // EX: parse "enwiki" to abrv_itm
|
||||
if (src == null) return null;
|
||||
int src_len = src.length; if (src_len == 0) return null; // empty bry
|
||||
Object o = bry_trie.Match_bgn(src, src_len - 1, -1); if (o == null) return null;
|
||||
Xow_abrv_wm rv = Xow_abrv_wm_override.To_abrv_itm_or_null(src); if (rv != null) return rv;
|
||||
int domain_type = ((Int_obj_ref)o).Val();
|
||||
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(src, 0, bry_trie.Match_pos() + 1);
|
||||
return new Xow_abrv_wm(src, lang_itm.Key(), lang_itm, domain_type);
|
||||
}
|
||||
public static Xow_domain_itm Parse_to_domain_itm(byte[] src) { // EX: parse "enwiki" to "en.wikipedia.org" itm
|
||||
if (Bry_.Has(src, Byte_ascii.Underline)) // convert "_" to "-"; note that wmf_keys have a strict format of langtype; EX: "zh_yuewiki"; DATE:2014-10-06
|
||||
src = Bry_.Replace_create(src, Byte_ascii.Underline, Byte_ascii.Dash);
|
||||
return Xow_domain_itm_.parse(Xow_abrv_wm_.Parse_to_domain_bry(src));
|
||||
}
|
||||
public static byte[] Parse_to_domain_bry(byte[] src) { // EX: parse "enwiki" to en.wikipedia.org
|
||||
if (src == null) return null;
|
||||
int src_len = src.length; if (src_len == 0) return null; // empty bry
|
||||
Object o = bry_trie.Match_bgn(src, src_len - 1, - 1); if (o == null) return null;
|
||||
int domain_type = -1;
|
||||
byte[] lang = null;
|
||||
Xow_abrv_wm rv = Xow_abrv_wm_override.To_abrv_itm_or_null(src);
|
||||
if (rv != null) {
|
||||
lang = rv.Lang_domain();
|
||||
domain_type = rv.Domain_type();
|
||||
}
|
||||
else {
|
||||
domain_type = ((Int_obj_ref)o).Val();
|
||||
}
|
||||
switch (domain_type) {
|
||||
case Xow_domain_type_.Int__wmfblog: return Xow_domain_itm_.Bry__wmforg;
|
||||
case Xow_domain_type_.Int__wikidata: return Xow_domain_itm_.Bry__wikidata;
|
||||
case Xow_domain_type_.Int__mediawiki: return Xow_domain_itm_.Bry__mediawiki;
|
||||
case Xow_domain_type_.Int__commons: return Xow_domain_itm_.Bry__commons;
|
||||
case Xow_domain_type_.Int__species: return Xow_domain_itm_.Bry__species;
|
||||
case Xow_domain_type_.Int__meta: return Xow_domain_itm_.Bry__meta;
|
||||
case Xow_domain_type_.Int__incubator: return Xow_domain_itm_.Bry__incubator;
|
||||
case Xow_domain_type_.Int__wikipedia:
|
||||
case Xow_domain_type_.Int__wiktionary:
|
||||
case Xow_domain_type_.Int__wikisource:
|
||||
case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity:
|
||||
case Xow_domain_type_.Int__wikiquote:
|
||||
case Xow_domain_type_.Int__wikinews:
|
||||
case Xow_domain_type_.Int__wikivoyage:
|
||||
case Xow_domain_type_.Int__wikimedia:
|
||||
if (lang == null) {
|
||||
lang = Bry_.Mid(src, 0, bry_trie.Match_pos() + 1); // en
|
||||
if (Bry_.Has(lang, Byte_ascii.Underline)) // convert "_" to "-"; note that wmf_keys have a strict format of langtype; EX: "zh_yuewiki"; DATE:2014-10-06
|
||||
lang = Bry_.Replace_create(lang, Byte_ascii.Underline, Byte_ascii.Dash);
|
||||
}
|
||||
return Bry_.Add
|
||||
( lang
|
||||
, Byte_ascii.Dot_bry // .
|
||||
, Xow_domain_type_.Get_type_as_bry(domain_type) // wikipedia
|
||||
, Byte_ascii.Dot_bry // .
|
||||
, Xow_domain_itm_.Seg__org // org
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void To_abrv(Bry_bfr bfr, byte[] lang_key, Int_obj_ref domain_type) {
|
||||
byte[] suffix_bry = (byte[])int_hash.Get_by(domain_type); if (suffix_bry == null) return;
|
||||
switch (domain_type.Val()) {
|
||||
case Xow_domain_type_.Int__commons:
|
||||
case Xow_domain_type_.Int__species:
|
||||
case Xow_domain_type_.Int__meta:
|
||||
case Xow_domain_type_.Int__incubator:
|
||||
case Xow_domain_type_.Int__wikidata:
|
||||
case Xow_domain_type_.Int__mediawiki:
|
||||
case Xow_domain_type_.Int__wmfblog: bfr.Add(suffix_bry); break;
|
||||
case Xow_domain_type_.Int__other: break;
|
||||
default: bfr.Add(lang_key).Add(suffix_bry); break;
|
||||
}
|
||||
}
|
||||
public static byte[] To_abrv(Xow_domain_itm domain_itm) {
|
||||
int tid = domain_itm.Domain_type_id();
|
||||
byte[] suffix = (byte[])int_hash.Get_by(Int_obj_ref.new_(tid)); if (suffix == null) return null;
|
||||
switch (tid) {
|
||||
case Xow_domain_type_.Int__commons:
|
||||
case Xow_domain_type_.Int__species:
|
||||
case Xow_domain_type_.Int__meta:
|
||||
case Xow_domain_type_.Int__incubator:
|
||||
case Xow_domain_type_.Int__wikidata:
|
||||
case Xow_domain_type_.Int__mediawiki:
|
||||
case Xow_domain_type_.Int__wmfblog: return suffix;
|
||||
case Xow_domain_type_.Int__wikipedia:
|
||||
case Xow_domain_type_.Int__wiktionary:
|
||||
case Xow_domain_type_.Int__wikisource:
|
||||
case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity:
|
||||
case Xow_domain_type_.Int__wikiquote:
|
||||
case Xow_domain_type_.Int__wikinews:
|
||||
case Xow_domain_type_.Int__wikivoyage:
|
||||
case Xow_domain_type_.Int__wikimedia: return Bry_.Add(domain_itm.Lang_orig_key(), suffix);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
private static final Btrie_bwd_mgr bry_trie = Init_trie();
|
||||
private static Hash_adp int_hash;
|
||||
private static Btrie_bwd_mgr Init_trie() {
|
||||
int_hash = Hash_adp_.new_();
|
||||
Btrie_bwd_mgr rv = new Btrie_bwd_mgr(false);
|
||||
Init_trie_itm(rv, int_hash, "wiki" , Xow_domain_type_.Int__wikipedia);
|
||||
Init_trie_itm(rv, int_hash, "wiktionary" , Xow_domain_type_.Int__wiktionary);
|
||||
Init_trie_itm(rv, int_hash, "wikisource" , Xow_domain_type_.Int__wikisource);
|
||||
Init_trie_itm(rv, int_hash, "wikibooks" , Xow_domain_type_.Int__wikibooks);
|
||||
Init_trie_itm(rv, int_hash, "wikiversity" , Xow_domain_type_.Int__wikiversity);
|
||||
Init_trie_itm(rv, int_hash, "wikiquote" , Xow_domain_type_.Int__wikiquote);
|
||||
Init_trie_itm(rv, int_hash, "wikinews" , Xow_domain_type_.Int__wikinews);
|
||||
Init_trie_itm(rv, int_hash, "wikivoyage" , Xow_domain_type_.Int__wikivoyage);
|
||||
Init_trie_itm(rv, int_hash, "wikimedia" , Xow_domain_type_.Int__wikimedia);
|
||||
Init_trie_itm(rv, int_hash, "commonswiki" , Xow_domain_type_.Int__commons);
|
||||
Init_trie_itm(rv, int_hash, "specieswiki" , Xow_domain_type_.Int__species);
|
||||
Init_trie_itm(rv, int_hash, "metawiki" , Xow_domain_type_.Int__meta);
|
||||
Init_trie_itm(rv, int_hash, "incubatorwiki" , Xow_domain_type_.Int__incubator);
|
||||
Init_trie_itm(rv, int_hash, "wikidatawiki" , Xow_domain_type_.Int__wikidata);
|
||||
Init_trie_itm(rv, int_hash, "mediawikiwiki" , Xow_domain_type_.Int__mediawiki);
|
||||
Init_trie_itm(rv, int_hash, "foundationwiki" , Xow_domain_type_.Int__wmfblog);
|
||||
return rv;
|
||||
}
|
||||
private static void Init_trie_itm(Btrie_bwd_mgr trie, Hash_adp hash, String str, int tid) {
|
||||
Int_obj_ref itm = Int_obj_ref.new_(tid);
|
||||
trie.Add(str, itm);
|
||||
hash.Add(itm, Bry_.new_u8(str));
|
||||
}
|
||||
}
|
||||
class Xow_abrv_wm_override {
|
||||
public static Xow_abrv_wm To_abrv_itm_or_null(byte[] abrv) {
|
||||
Object o = itm_hash.Get_by_bry(abrv);
|
||||
return o == null ? null : (Xow_abrv_wm)o;
|
||||
}
|
||||
public static byte[] To_lang_key_or_null(byte[] domain_bry) {
|
||||
Object o = lang_hash.Get_by_bry(domain_bry);
|
||||
return o == null ? null : (byte[])o;
|
||||
}
|
||||
private static final Hash_adp_bry itm_hash = itm_hash__make();
|
||||
private static Hash_adp_bry lang_hash;
|
||||
private static Hash_adp_bry itm_hash__make() {
|
||||
Hash_adp_bry rv = Hash_adp_bry.cs();
|
||||
lang_hash = Hash_adp_bry.cs();
|
||||
itm_hash__add(rv, lang_hash, "ar.wikimedia.org", "arwikimedia", "ar", Xol_lang_itm_.Id_es, Xow_domain_type_.Int__wikimedia); // NOTE: ar means Argentina not Arabic
|
||||
itm_hash__add(rv, lang_hash, "br.wikimedia.org", "brwikimedia", "br", Xol_lang_itm_.Id_es, Xow_domain_type_.Int__wikimedia); // NOTE: br means Brazil not Breto
|
||||
itm_hash__add(rv, lang_hash, "co.wikimedia.org", "cowikimedia", "co", Xol_lang_itm_.Id_es, Xow_domain_type_.Int__wikimedia); // NOTE: co means Columbia not Corsican
|
||||
itm_hash__add(rv, lang_hash, "ua.wikimedia.org", "ukwikimedia", "ua", Xol_lang_itm_.Id_uk, Xow_domain_type_.Int__wikimedia); // NOTE: ua means Ukrainian; NOTE: uk does not means United Kingdom (which redirects to https://wikimedia.org.uk)
|
||||
itm_hash__add(rv, lang_hash, "ca.wikimedia.org", "cawikimedia", "ca", Xol_lang_itm_.Id_en, Xow_domain_type_.Int__wikimedia); // NOTE: ca means Canada not Catalan
|
||||
itm_hash__add(rv, lang_hash, "be.wikimedia.org", "bewikimedia", "be", Xol_lang_itm_.Id_en, Xow_domain_type_.Int__wikimedia); // NOTE: be means Belgium not Belarusian
|
||||
itm_hash__add(rv, lang_hash, "se.wikimedia.org", "sewikimedia", "se", Xol_lang_itm_.Id_sv, Xow_domain_type_.Int__wikimedia); // NOTE: se means Swedish not Northern Sami
|
||||
return rv;
|
||||
}
|
||||
private static void itm_hash__add(Hash_adp_bry hash, Hash_adp_bry lang_hash, String domain, String raw, String lang_domain, int lang_actl, int domain_type) {
|
||||
byte[] abrv_bry = Bry_.new_u8(raw);
|
||||
Xol_lang_itm lang_actl_itm = Xol_lang_itm_.Get_by_id(lang_actl);
|
||||
Xow_abrv_wm itm = new Xow_abrv_wm(abrv_bry, Bry_.new_a7(lang_domain), lang_actl_itm, domain_type);
|
||||
hash.Add_bry_obj(abrv_bry, itm);
|
||||
lang_hash.Add_str_obj(domain, lang_actl_itm.Key());
|
||||
}
|
||||
}
|
||||
96
400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_tst.java
Normal file
96
400_xowa/src/gplx/xowa/wikis/domains/Xow_abrv_wm_tst.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*;
|
||||
public class Xow_abrv_wm_tst {
|
||||
private Xow_abrv_wm_fxt fxt = new Xow_abrv_wm_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse("foundationwiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__wmfblog);
|
||||
fxt.Test_parse("wikidatawiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__wikidata);
|
||||
fxt.Test_parse("mediawikiwiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__mediawiki);
|
||||
fxt.Test_parse("commonswiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__commons);
|
||||
fxt.Test_parse("specieswiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__species);
|
||||
fxt.Test_parse("metawiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__meta);
|
||||
fxt.Test_parse("incubatorwiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__incubator);
|
||||
fxt.Test_parse("enwiki" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikipedia);
|
||||
fxt.Test_parse("enwiktionary" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wiktionary);
|
||||
fxt.Test_parse("enwikisource" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikisource);
|
||||
fxt.Test_parse("enwikibooks" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikibooks);
|
||||
fxt.Test_parse("enwikiversity" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikiversity);
|
||||
fxt.Test_parse("enwikiquote" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikiquote);
|
||||
fxt.Test_parse("enwikinews" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikinews);
|
||||
fxt.Test_parse("enwikivoyage" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikivoyage);
|
||||
fxt.Test_parse("frwiki" , Xol_lang_itm_.Id_fr , Xow_domain_type_.Int__wikipedia);
|
||||
fxt.Test_parse_null("unknown");
|
||||
fxt.Test_parse("plwikimedia" , Xol_lang_itm_.Id_pl , Xow_domain_type_.Int__wikimedia);
|
||||
}
|
||||
@Test public void Parse_override() {
|
||||
fxt.Test_parse("arwikimedia" , Xol_lang_itm_.Id_es , Xow_domain_type_.Int__wikimedia);
|
||||
fxt.Test_parse("ukwikimedia" , Xol_lang_itm_.Id_uk , Xow_domain_type_.Int__wikimedia);
|
||||
}
|
||||
@Test public void To_domain_itm() {
|
||||
fxt.Test_to_domain_itm("enwiki" , "en" , "en.wikipedia.org");
|
||||
fxt.Test_to_domain_itm("zh_yuewiki" , "zh-yue" , "zh-yue.wikipedia.org");
|
||||
}
|
||||
@Test public void To_domain_bry() {
|
||||
fxt.Test_to_domain_bry("enwiki" , "en.wikipedia.org");
|
||||
fxt.Test_to_domain_bry("zh_yuewiki" , "zh-yue.wikipedia.org");
|
||||
fxt.Test_to_domain_bry("arwikimedia", "ar.wikimedia.org");
|
||||
fxt.Test_to_domain_bry("ukwikimedia", "ua.wikimedia.org");
|
||||
}
|
||||
@Test public void To_abrv() {
|
||||
fxt.Test_to_abrv("simple.wikipedia.org" , "simplewiki");
|
||||
fxt.Test_to_abrv("en.wikipedia.org" , "enwiki");
|
||||
fxt.Test_to_abrv("commons.wikimedia.org" , "commonswiki");
|
||||
}
|
||||
@Test public void To_abrv_by_lang() {
|
||||
fxt.Test_to_abrv_by_lang("en", Xow_domain_type_.Int__wikipedia, "enwiki");
|
||||
}
|
||||
}
|
||||
class Xow_abrv_wm_fxt {
|
||||
public void Test_parse(String raw, int expd_lang_id, int expd_domain_tid) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Xow_abrv_wm abrv = Xow_abrv_wm_.Parse_to_abrv_or_null(raw_bry);
|
||||
Xol_lang_itm actl_lang_itm = abrv.Lang_actl();
|
||||
Tfds.Eq(expd_lang_id , actl_lang_itm == null ? Xol_lang_itm_.Id__unknown : actl_lang_itm.Id());
|
||||
Tfds.Eq(expd_domain_tid , abrv.Domain_type());
|
||||
}
|
||||
public void Test_parse_null(String raw) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Xow_abrv_wm abrv = Xow_abrv_wm_.Parse_to_abrv_or_null(raw_bry);
|
||||
Tfds.Eq_true(abrv == null);
|
||||
}
|
||||
public void Test_to_abrv(String domain_str, String expd) {
|
||||
Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_a7(domain_str));
|
||||
byte[] actl = Xow_abrv_wm_.To_abrv(domain);
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
public void Test_to_abrv_by_lang(String lang_key, int wiki_tid, String expd) {
|
||||
Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
Xow_abrv_wm_.To_abrv(tmp_bfr, Bry_.new_a7(lang_key), gplx.core.primitives.Int_obj_ref.new_(wiki_tid));
|
||||
Tfds.Eq_str(expd, tmp_bfr.Xto_str_and_clear(), "to_abrv");
|
||||
}
|
||||
public void Test_to_domain_bry(String wmf_key, String expd_domain) {
|
||||
Tfds.Eq(expd_domain , String_.new_a7(Xow_abrv_wm_.Parse_to_domain_bry(Bry_.new_a7(wmf_key))));
|
||||
}
|
||||
public void Test_to_domain_itm(String wmf_key, String expd_lang_key, String expd_domain) {
|
||||
Xow_domain_itm domain = Xow_abrv_wm_.Parse_to_domain_itm(Bry_.new_a7(wmf_key));
|
||||
Tfds.Eq(expd_lang_key , String_.new_a7(domain.Lang_actl_key()));
|
||||
Tfds.Eq(expd_domain , String_.new_a7(domain.Domain_bry()));
|
||||
}
|
||||
}
|
||||
@@ -17,21 +17,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_domain_abrv_xo_ {
|
||||
public class Xow_abrv_xo_ {
|
||||
public static byte[] To_bry(byte[] domain_bry) {
|
||||
Xow_domain domain_itm = Xow_domain_.parse(domain_bry);
|
||||
return Xow_domain_abrv_xo_.To_bry(domain_itm.Domain_bry(), domain_itm.Lang_orig_itm(), domain_itm.Domain_type());
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
return Xow_abrv_xo_.To_bry(domain_itm.Domain_bry(), domain_itm.Lang_orig_key(), domain_itm.Domain_type());
|
||||
}
|
||||
public static byte[] To_bry(byte[] domain_bry, Xol_lang_itm lang, Xow_domain_type type) { // en.wikipedia.org -> en.w
|
||||
public static byte[] To_bry(byte[] domain_bry, byte[] lang_key, Xow_domain_type type) { // en.wikipedia.org -> en.w
|
||||
byte[] type_abrv = type.Abrv();
|
||||
if (type.Multi_lang()) // wikipedia,wiktionary,etc..
|
||||
return Bry_.Add(lang.Key(), Byte_ascii.Dot_bry, type_abrv);
|
||||
return Bry_.Add(lang_key, Byte_ascii.Dot_bry, type_abrv);
|
||||
else if (type_abrv.length > 0) // commons,wbase,species,etc..
|
||||
return type_abrv;
|
||||
else // home;wikia;others
|
||||
return domain_bry;
|
||||
}
|
||||
public static Xow_domain To_itm(byte[] src) {
|
||||
public static Xow_domain_itm To_itm(byte[] src) {
|
||||
int src_len = src.length;
|
||||
byte[] domain_bry = src; // default to src; handles unknown abrv like "a.wikia.com";"xowa";others
|
||||
Xow_domain_type type = null;
|
||||
@@ -50,6 +50,6 @@ public class Xow_domain_abrv_xo_ {
|
||||
domain_bry = type.Domain_bry();
|
||||
}
|
||||
}
|
||||
return Xow_domain_.parse(domain_bry); // for consolidation's sake, parse abrv to domain_bry and pass to Xow_domain_.parse_()
|
||||
return Xow_domain_itm_.parse(domain_bry); // for consolidation's sake, parse abrv to domain_bry and pass to Xow_domain_itm_.parse_()
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xow_domain_abrv_xo__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xow_domain_abrv_xo__fxt fxt = new Xow_domain_abrv_xo__fxt();
|
||||
public class Xow_abrv_xo__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xow_abrv_xo__fxt fxt = new Xow_abrv_xo__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test("en.wikipedia.org" , "en.w"); // multi.enwiki
|
||||
fxt.Test("fr.wiktionary.org" , "fr.d"); // multi.frwiktionary
|
||||
@@ -30,13 +30,13 @@ public class Xow_domain_abrv_xo__tst {
|
||||
fxt.Test("a.b.c" , "a.b.c"); // unkonwn
|
||||
}
|
||||
}
|
||||
class Xow_domain_abrv_xo__fxt {
|
||||
class Xow_abrv_xo__fxt {
|
||||
public void Clear() {}
|
||||
public void Test(String domain_str, String expd_abrv) {
|
||||
Xow_domain domain = Xow_domain_.parse(Bry_.new_u8(domain_str));
|
||||
byte[] actl_abrv = Xow_domain_abrv_xo_.To_bry(domain.Domain_bry(), domain.Lang_itm(), domain.Domain_type());
|
||||
Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
|
||||
byte[] actl_abrv = Xow_abrv_xo_.To_bry(domain.Domain_bry(), domain.Lang_actl_key(), domain.Domain_type());
|
||||
Tfds.Eq(expd_abrv, String_.new_u8(actl_abrv), "To_bry");
|
||||
domain = Xow_domain_abrv_xo_.To_itm(actl_abrv);
|
||||
domain = Xow_abrv_xo_.To_itm(actl_abrv);
|
||||
Tfds.Eq(domain_str, domain.Domain_str(), "To_itm");
|
||||
}
|
||||
}
|
||||
48
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm.java
Normal file
48
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_domain_itm {
|
||||
Xow_domain_itm(byte[] domain_bry, Xow_domain_type domain_type, Xol_lang_itm lang_actl_itm, byte[] lang_orig_key) {
|
||||
this.domain_bry = domain_bry; this.domain_type = domain_type; this.lang_actl_itm = lang_actl_itm; this.lang_orig_key = lang_orig_key;
|
||||
this.domain_str = String_.new_u8(domain_bry);
|
||||
this.abrv_wm = Xow_abrv_wm_.To_abrv(this);
|
||||
this.abrv_xo = Xow_abrv_xo_.To_bry(domain_bry, lang_orig_key, domain_type);
|
||||
}
|
||||
public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry;
|
||||
public String Domain_str() {return domain_str;} private final String domain_str;
|
||||
public Xow_domain_type Domain_type() {return domain_type;} private final Xow_domain_type domain_type;
|
||||
public int Domain_type_id() {return domain_type.Tid();}
|
||||
public byte[] Abrv_wm() {return abrv_wm;} private final byte[] abrv_wm; // EX: enwiki
|
||||
public byte[] Abrv_xo() {return abrv_xo;} private final byte[] abrv_xo; // EX: en.w
|
||||
public Xol_lang_itm Lang_actl_itm() {return lang_actl_itm;} private final Xol_lang_itm lang_actl_itm; // EX: zh
|
||||
public int Lang_actl_uid() {return lang_actl_itm.Id();}
|
||||
public byte[] Lang_actl_key() {return lang_actl_itm.Key();}
|
||||
public byte[] Lang_orig_key() {return lang_orig_key;} private final byte[] lang_orig_key; // EX: lzh
|
||||
public int Sort_idx() {return sort_idx;} public void Sort_idx_(int v) {sort_idx = v;} private int sort_idx = -1; // used for Search
|
||||
public static Xow_domain_itm new_(byte[] domain_bry, int domain_tid, byte[] lang_key) {
|
||||
Xol_lang_itm lang_actl_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key);
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_actl_itm, lang_actl_itm.Key());
|
||||
}
|
||||
public static Xow_domain_itm new_(byte[] domain_bry, int domain_tid, Xol_lang_itm lang_actl, byte[] lang_orig) {
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_actl, lang_orig);
|
||||
}
|
||||
public static Xow_domain_itm new_(byte[] domain_bry, int domain_tid, byte[] lang_actl_key, byte[] lang_orig_key) {
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), Xol_lang_itm_.Get_by_key_or_intl(lang_actl_key), lang_orig_key);
|
||||
}
|
||||
}
|
||||
108
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_.java
Normal file
108
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_.java
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_domain_itm_ {
|
||||
public static Xow_domain_itm parse(byte[] raw) {
|
||||
/*
|
||||
~{type}.org EX: wikimediafoundation
|
||||
~{type}.wikimedia.org EX: commons; species; meta; incubator
|
||||
~{lang}.~{type}.org EX: en.wikipedia, etc;
|
||||
~www.~{type}.org EX: mediawiki; wikidata;
|
||||
*/
|
||||
int raw_len = raw.length;
|
||||
int dot_0 = Bry_finder.Find_fwd(raw, Byte_ascii.Dot, 0, raw_len);
|
||||
if (dot_0 == Bry_.NotFound) { // 0 dots; check for "home"
|
||||
return Bry_.Eq(raw, Xow_domain_type_.Bry__home)
|
||||
? Xow_domain_uid_.To_domain(Xow_domain_uid_.Tid_xowa)
|
||||
: new_other(raw);
|
||||
}
|
||||
int dot_1 = Bry_finder.Find_fwd(raw, Byte_ascii.Dot, dot_0 + 1, raw_len);
|
||||
if (dot_1 == Bry_.NotFound) { // 1 dot; check for "wikimediafoundation.org"
|
||||
return Bry_.Match(raw, 0, dot_0, Xow_domain_type_.Bry__wmforg)
|
||||
? Xow_domain_itm.new_(raw, Xow_domain_type_.Int__wmfblog, Xol_lang_itm_.Key__unknown)
|
||||
: new_other(raw);
|
||||
}
|
||||
// 2 dots
|
||||
int seg_1_tid = Xow_domain_type_.Get_type_as_tid(raw, dot_0 + 1, dot_1); // parse middle; EX: ".wikipedia."
|
||||
if (seg_1_tid == Xow_domain_type_.Int__null) return new_other(raw); // seg_1 is unknown; return other;
|
||||
switch (seg_1_tid) {
|
||||
case Xow_domain_type_.Int__wikipedia: case Xow_domain_type_.Int__wiktionary: case Xow_domain_type_.Int__wikisource: case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity: case Xow_domain_type_.Int__wikiquote: case Xow_domain_type_.Int__wikinews: case Xow_domain_type_.Int__wikivoyage: // ~{lang}.~{type}.org
|
||||
byte[] lang_orig = Bry_.Mid(raw, 0, dot_0);
|
||||
byte[] lang_actl = Get_lang_code_for_mw_messages_file(lang_orig);
|
||||
return Xow_domain_itm.new_(raw, seg_1_tid, lang_actl, lang_orig); // NOTE: seg_tids must match wiki_tids
|
||||
case Xow_domain_type_.Int__wikidata: case Xow_domain_type_.Int__mediawiki:// ~www.~{type}.org
|
||||
return Xow_domain_itm.new_(raw, seg_1_tid, Xol_lang_itm_.Key__unknown);
|
||||
case Xow_domain_type_.Int__wikimedia: // ~{type}.wikimedia.org;
|
||||
int seg_0_tid = Xow_domain_type_.Get_type_as_tid(raw, 0, dot_0); // try to get "incubator", "meta", etc..
|
||||
if (seg_0_tid == Xow_domain_type_.Int__null) { // not a known name; try language
|
||||
byte[] lang_override = Xow_abrv_wm_override.To_lang_key_or_null(raw); // handle "lang-like" wikimedia domains like "ar.wikimedia.org" which is actually to "Argentina Wikimedia"
|
||||
if (lang_override == null) {
|
||||
Xol_lang_itm wikimedia_lang = Xol_lang_itm_.Get_by_key_or_null(raw, 0, dot_0);
|
||||
return wikimedia_lang == null ? new_other(raw) : Xow_domain_itm.new_(raw, Xow_domain_type_.Int__wikimedia, wikimedia_lang.Key());
|
||||
}
|
||||
else
|
||||
return Xow_domain_itm.new_(raw, Xow_domain_type_.Int__wikimedia, lang_override, Bry_.Mid(raw, 0, dot_0));
|
||||
}
|
||||
switch (seg_0_tid) {
|
||||
case Xow_domain_type_.Int__commons: case Xow_domain_type_.Int__species: case Xow_domain_type_.Int__meta: case Xow_domain_type_.Int__incubator:
|
||||
return Xow_domain_itm.new_(raw, seg_0_tid, Xol_lang_itm_.Key__unknown); // NOTE: seg_tids must match wiki_tids; NOTE: lang_key is "en" (really, "multi" but making things easier)
|
||||
default:
|
||||
return new_other(raw);
|
||||
}
|
||||
case Xow_domain_type_.Int__other:
|
||||
default:
|
||||
return new_other(raw);
|
||||
}
|
||||
}
|
||||
private static Xow_domain_itm new_other(byte[] raw) {return Xow_domain_itm.new_(raw, Xow_domain_type_.Int__other, Xol_lang_itm_.Key__unknown);}
|
||||
private static byte[] Get_lang_code_for_mw_messages_file(byte[] v) {
|
||||
Object o = lang_to_gfs_hash.Get_by_bry(v);
|
||||
return o == null ? v : (byte[])o;
|
||||
}
|
||||
private static final Hash_adp_bry lang_to_gfs_hash = Hash_adp_bry.ci_a7() // ASCII:lang_code
|
||||
.Add_str_obj("simple" , Bry_.new_a7("en"))
|
||||
.Add_str_obj("zh-classical" , Bry_.new_a7("lzh"))
|
||||
.Add_str_obj("no" , Bry_.new_a7("nb"))
|
||||
;
|
||||
public static final String
|
||||
Str__enwiki = "en.wikipedia.org"
|
||||
, Str__species = "species.wikimedia.org"
|
||||
, Str__commons = "commons.wikimedia.org"
|
||||
, Str__wikidata = "www.wikidata.org"
|
||||
, Str__mediawiki = "www.mediawiki.org"
|
||||
, Str__meta = "meta.wikimedia.org"
|
||||
, Str__incubator = "incubator.wikimedia.org"
|
||||
, Str__wmforg = "wikimediafoundation.org"
|
||||
, Str__home = "home"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__enwiki = Bry_.new_a7(Str__enwiki)
|
||||
, Bry__species = Bry_.new_a7(Str__species)
|
||||
, Bry__commons = Bry_.new_a7(Str__commons)
|
||||
, Bry__wikidata = Bry_.new_a7(Str__wikidata)
|
||||
, Bry__mediawiki = Bry_.new_a7(Str__mediawiki)
|
||||
, Bry__meta = Bry_.new_a7(Str__meta)
|
||||
, Bry__incubator = Bry_.new_a7(Str__incubator)
|
||||
, Bry__wmforg = Bry_.new_a7(Str__wmforg)
|
||||
, Bry__home = Bry_.new_a7(Str__home)
|
||||
;
|
||||
public static final byte[] Seg__org = Bry_.new_a7("org"), Seg__www = Bry_.new_a7("www");
|
||||
}
|
||||
41
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_tst.java
Normal file
41
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_itm_tst.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xow_domain_itm_tst {
|
||||
private final Xow_domain_fxt fxt = new Xow_domain_fxt();
|
||||
@Test public void Parse_en_wikipedia() {fxt.Test_parse("en.wikipedia.org" , "en" , "en" , Xow_domain_type_.Int__wikipedia);}
|
||||
@Test public void Parse_fr_wikipedia() {fxt.Test_parse("fr.wikipedia.org" , "fr" , "fr" , Xow_domain_type_.Int__wikipedia);}
|
||||
@Test public void Parse_en_wiktionary() {fxt.Test_parse("en.wiktionary.org" , "en" , "en" , Xow_domain_type_.Int__wiktionary);}
|
||||
@Test public void Parse_zh_classical_wikipedia() {fxt.Test_parse("zh-classical.wikipedia.org" , "zh-classical" , "lzh" , Xow_domain_type_.Int__wikipedia);}
|
||||
@Test public void Parse_commons() {fxt.Test_parse("commons.wikimedia.org" , "" , "" , Xow_domain_type_.Int__commons);}
|
||||
@Test public void Parse_species() {fxt.Test_parse("species.wikimedia.org" , "" , "" , Xow_domain_type_.Int__species);}
|
||||
@Test public void Parse_ru_wikimedia_org() {fxt.Test_parse("ru.wikimedia.org" , "ru" , "ru" , Xow_domain_type_.Int__wikimedia);}
|
||||
@Test public void Parse_home() {fxt.Test_parse("home" , "" , "" , Xow_domain_type_.Int__home);}
|
||||
@Test public void Parse_other() {fxt.Test_parse("other.wiki" , "" , "" , Xow_domain_type_.Int__other);}
|
||||
@Test public void Parse_ua_wikimedia_org() {fxt.Test_parse("ua.wikimedia.org" , "ua" , "uk" , Xow_domain_type_.Int__wikimedia);}
|
||||
@Test public void Parse_ar_wikimedia_org() {fxt.Test_parse("ar.wikimedia.org" , "ar" , "es" , Xow_domain_type_.Int__wikimedia);}
|
||||
}
|
||||
class Xow_domain_fxt {
|
||||
public void Test_parse(String domain, String expd_orig_lang, String expd_actl_lang, int expd_tid) {
|
||||
Xow_domain_itm actl = Xow_domain_itm_.parse(Bry_.new_a7(domain));
|
||||
Tfds.Eq_str(expd_orig_lang, String_.new_a7((actl.Lang_orig_key())));
|
||||
Tfds.Eq_str(expd_actl_lang, String_.new_a7((actl.Lang_actl_key())));
|
||||
Tfds.Eq_int(expd_tid, actl.Domain_type_id());
|
||||
}
|
||||
}
|
||||
39
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_type.java
Normal file
39
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_type.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_domain_type {
|
||||
public Xow_domain_type(boolean multi_lang, int src, int tid, byte[] key_bry, byte[] abrv, byte[] domain_bry) {
|
||||
this.multi_lang = multi_lang; this.src = src; this.tid = tid; this.key_bry = key_bry; this.abrv = abrv; this.domain_bry = domain_bry;
|
||||
this.key_str = String_.new_u8(key_bry);
|
||||
}
|
||||
public boolean Multi_lang() {return multi_lang;} private final boolean multi_lang; // EX: y
|
||||
public int Src() {return src;} private final int src; // EX: 1 (wm,mw,wk,xo)
|
||||
public int Tid() {return tid;} private final int tid; // EX: 1 (Tid_wikipedia)
|
||||
public String Key_str() {return key_str;} private final String key_str; // EX: wikipedia
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry; // EX: wikipedia
|
||||
public byte[] Abrv() {return abrv;} private final byte[] abrv; // EX: w
|
||||
public byte[] Domain_bry() {return domain_bry;} private byte[] domain_bry; // EX: .wikipedia.org
|
||||
}
|
||||
class Xow_domain_type_src_ {
|
||||
public static final int
|
||||
Int__wmf = 1 // administered by wmf; wikipedia, etc.
|
||||
, Int__wikia = 2 // *.wikia.com
|
||||
, Int__mw = 3 // mediawiki installations not part of wmf, wikia
|
||||
, Int__xowa = 4 // xowa
|
||||
;
|
||||
}
|
||||
121
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_type_.java
Normal file
121
400_xowa/src/gplx/xowa/wikis/domains/Xow_domain_type_.java
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_domain_type_ {
|
||||
public static final int
|
||||
Int__null = 0
|
||||
, Int__wikipedia = 1
|
||||
, Int__wiktionary = 2
|
||||
, Int__wikisource = 3
|
||||
, Int__wikivoyage = 4
|
||||
, Int__wikiquote = 5
|
||||
, Int__wikibooks = 6
|
||||
, Int__wikiversity = 7
|
||||
, Int__wikinews = 8
|
||||
, Int__wikimedia = 9
|
||||
, Int__species = 10
|
||||
, Int__commons = 11
|
||||
, Int__wikidata = 12
|
||||
, Int__mediawiki = 13
|
||||
, Int__meta = 14
|
||||
, Int__incubator = 15
|
||||
, Int__wmfblog = 16
|
||||
, Int__home = 17
|
||||
, Int__other = 18
|
||||
, Int___len = 19
|
||||
;
|
||||
public static final String // SERIALIZED:xowa.gfs
|
||||
Str__wikipedia = "wikipedia"
|
||||
, Str__wiktionary = "wiktionary"
|
||||
, Str__wikisource = "wikisource"
|
||||
, Str__wikivoyage = "wikivoyage"
|
||||
, Str__wikiquote = "wikiquote"
|
||||
, Str__wikibooks = "wikibooks"
|
||||
, Str__wikiversity = "wikiversity"
|
||||
, Str__wikinews = "wikinews"
|
||||
, Str__wikimedia = "wikimedia"
|
||||
, Str__species = "species"
|
||||
, Str__commons = "commons"
|
||||
, Str__wikidata = "wikidata"
|
||||
, Str__mediawiki = "mediawiki"
|
||||
, Str__meta = "meta"
|
||||
, Str__incubator = "incubator"
|
||||
, Str__wmforg = "wikimediafoundation"
|
||||
, Str__home = "home"
|
||||
, Str__other = "other"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__wikipedia = Bry_.new_a7(Str__wikipedia)
|
||||
, Bry__wiktionary = Bry_.new_a7(Str__wiktionary)
|
||||
, Bry__wikisource = Bry_.new_a7(Str__wikisource)
|
||||
, Bry__wikivoyage = Bry_.new_a7(Str__wikivoyage)
|
||||
, Bry__wikiquote = Bry_.new_a7(Str__wikiquote)
|
||||
, Bry__wikibooks = Bry_.new_a7(Str__wikibooks)
|
||||
, Bry__wikiversity = Bry_.new_a7(Str__wikiversity)
|
||||
, Bry__wikinews = Bry_.new_a7(Str__wikinews)
|
||||
, Bry__wikimedia = Bry_.new_a7(Str__wikimedia)
|
||||
, Bry__species = Bry_.new_a7(Str__species)
|
||||
, Bry__commons = Bry_.new_a7(Str__commons)
|
||||
, Bry__wikidata = Bry_.new_a7(Str__wikidata)
|
||||
, Bry__mediawiki = Bry_.new_a7(Str__mediawiki)
|
||||
, Bry__meta = Bry_.new_a7(Str__meta)
|
||||
, Bry__incubator = Bry_.new_a7(Str__incubator)
|
||||
, Bry__wmforg = Bry_.new_a7(Str__wmforg)
|
||||
, Bry__home = Bry_.new_a7(Str__home)
|
||||
, Bry__other = Bry_.new_a7(Str__other)
|
||||
;
|
||||
private static final Xow_domain_type[] ary = new Xow_domain_type[Int___len];
|
||||
private static final Hash_adp_bry type_regy = Hash_adp_bry.ci_a7(); // LOC:must go before new_()
|
||||
private static final Hash_adp_bry abrv_regy = Hash_adp_bry.cs(); // LOC:must go before new_()
|
||||
public static final Xow_domain_type
|
||||
Itm__wikipedia = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikipedia , Bry__wikipedia , "w" , ".wikipedia.org")
|
||||
, Itm__wiktionary = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wiktionary , Bry__wiktionary , "d" , ".wiktionary.org")
|
||||
, Itm__wikisource = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikisource , Bry__wikisource , "s" , ".wikisource.org")
|
||||
, Itm__wikivoyage = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikivoyage , Bry__wikivoyage , "v" , ".wikivoyage.org")
|
||||
, Itm__wikiquote = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikiquote , Bry__wikiquote , "q" , ".wikiquote.org")
|
||||
, Itm__wikibooks = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikibooks , Bry__wikibooks , "b" , ".wikibooks.org")
|
||||
, Itm__wikiversity = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikiversity , Bry__wikiversity , "u" , ".wikiversity.org")
|
||||
, Itm__wikinews = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikinews , Bry__wikinews , "n" , ".wikinews.org")
|
||||
, Itm__wikimedia = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikimedia , Bry__wikimedia , "m" , ".wikimedia.org")
|
||||
, Itm__species = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__species , Bry__species , "species" , Xow_domain_itm_.Str__species)
|
||||
, Itm__commons = new_(Bool_.N , Xow_domain_type_src_.Int__wmf , Int__commons , Bry__commons , "c" , Xow_domain_itm_.Str__commons)
|
||||
, Itm__wikidata = new_(Bool_.N , Xow_domain_type_src_.Int__wmf , Int__wikidata , Bry__wikidata , "wd" , Xow_domain_itm_.Str__wikidata)
|
||||
, Itm__mediawiki = new_(Bool_.N , Xow_domain_type_src_.Int__wmf , Int__mediawiki , Bry__mediawiki , "mw" , Xow_domain_itm_.Str__mediawiki)
|
||||
, Itm__meta = new_(Bool_.N , Xow_domain_type_src_.Int__wmf , Int__meta , Bry__meta , "meta" , Xow_domain_itm_.Str__meta)
|
||||
, Itm__incubator = new_(Bool_.N , Xow_domain_type_src_.Int__wmf , Int__incubator , Bry__incubator , "qb" , Xow_domain_itm_.Str__incubator)
|
||||
, Itm__wmforg = new_(Bool_.N , Xow_domain_type_src_.Int__wmf , Int__wmfblog , Bry__wmforg , "wmf" , Xow_domain_itm_.Str__wmforg)
|
||||
, Itm__home = new_(Bool_.N , Xow_domain_type_src_.Int__xowa, Int__home , Bry__home , "home" , Xow_domain_itm_.Str__home)
|
||||
, Itm__other = new_(Bool_.N , Xow_domain_type_src_.Int__mw , Int__other , Bry__other , "" , "")
|
||||
;
|
||||
private static Xow_domain_type new_(boolean multi_lang, int src, int tid, byte[] key_bry, String abrv_xo_str, String domain_bry) {
|
||||
byte[] abrv_xo_bry = Bry_.new_u8(abrv_xo_str);
|
||||
Xow_domain_type rv = new Xow_domain_type(multi_lang, src, tid, key_bry, abrv_xo_bry, Bry_.new_u8(domain_bry));
|
||||
ary[tid] = rv;
|
||||
type_regy.Add(key_bry, rv);
|
||||
abrv_regy.Add(abrv_xo_bry, rv);
|
||||
return rv;
|
||||
}
|
||||
public static Xow_domain_type Get_abrv_as_itm(byte[] src, int bgn, int end) {return (Xow_domain_type)abrv_regy.Get_by_mid(src, bgn, end);}
|
||||
public static Xow_domain_type Get_type_as_itm(int tid) {return ary[tid];}
|
||||
public static byte[] Get_type_as_bry(int tid) {return ary[tid].Key_bry();}
|
||||
public static int Get_type_as_tid(byte[] src) {return Get_type_as_tid(src, 0, src.length);}
|
||||
public static int Get_type_as_tid(byte[] src, int bgn, int end) {
|
||||
Object o = type_regy.Get_by_mid(src, bgn, end);
|
||||
return o == null ? Xow_domain_type_.Int__null : ((Xow_domain_type)o).Tid();
|
||||
}
|
||||
}
|
||||
@@ -41,65 +41,65 @@ public class Xow_domain_uid_ {
|
||||
, Tid_sub_wikimedia = 8
|
||||
;
|
||||
private static final int Const_system_reserved = 100, Const_lang_reserved = 20;
|
||||
public static int To_int(Xow_domain domain) {
|
||||
public static int To_int(Xow_domain_itm domain) {
|
||||
int domain_tid = 0;
|
||||
switch (domain.Domain_tid()) {
|
||||
case Xow_domain_type_.Tid_home: return Tid_xowa;
|
||||
case Xow_domain_type_.Tid_commons: return Tid_commons;
|
||||
case Xow_domain_type_.Tid_wikidata: return Tid_wikidata;
|
||||
case Xow_domain_type_.Tid_mediawiki: return Tid_mediawiki;
|
||||
case Xow_domain_type_.Tid_meta: return Tid_meta;
|
||||
case Xow_domain_type_.Tid_incubator: return Tid_incubator;
|
||||
case Xow_domain_type_.Tid_wmfblog: return Tid_wmfblog;
|
||||
case Xow_domain_type_.Tid_species: return Tid_species;
|
||||
case Xow_domain_type_.Tid_wikipedia: domain_tid = Tid_sub_wikipedia; break;
|
||||
case Xow_domain_type_.Tid_wiktionary: domain_tid = Tid_sub_wiktionary; break;
|
||||
case Xow_domain_type_.Tid_wikisource: domain_tid = Tid_sub_wikisource; break;
|
||||
case Xow_domain_type_.Tid_wikivoyage: domain_tid = Tid_sub_wikivoyage; break;
|
||||
case Xow_domain_type_.Tid_wikiquote: domain_tid = Tid_sub_wikiquote; break;
|
||||
case Xow_domain_type_.Tid_wikibooks: domain_tid = Tid_sub_wikibooks; break;
|
||||
case Xow_domain_type_.Tid_wikiversity: domain_tid = Tid_sub_wikiversity; break;
|
||||
case Xow_domain_type_.Tid_wikinews: domain_tid = Tid_sub_wikinews; break;
|
||||
case Xow_domain_type_.Tid_wikimedia: domain_tid = Tid_sub_wikimedia; break;
|
||||
default: throw Err_.new_unhandled(domain.Domain_tid());
|
||||
switch (domain.Domain_type_id()) {
|
||||
case Xow_domain_type_.Int__home: return Tid_xowa;
|
||||
case Xow_domain_type_.Int__commons: return Tid_commons;
|
||||
case Xow_domain_type_.Int__wikidata: return Tid_wikidata;
|
||||
case Xow_domain_type_.Int__mediawiki: return Tid_mediawiki;
|
||||
case Xow_domain_type_.Int__meta: return Tid_meta;
|
||||
case Xow_domain_type_.Int__incubator: return Tid_incubator;
|
||||
case Xow_domain_type_.Int__wmfblog: return Tid_wmfblog;
|
||||
case Xow_domain_type_.Int__species: return Tid_species;
|
||||
case Xow_domain_type_.Int__wikipedia: domain_tid = Tid_sub_wikipedia; break;
|
||||
case Xow_domain_type_.Int__wiktionary: domain_tid = Tid_sub_wiktionary; break;
|
||||
case Xow_domain_type_.Int__wikisource: domain_tid = Tid_sub_wikisource; break;
|
||||
case Xow_domain_type_.Int__wikivoyage: domain_tid = Tid_sub_wikivoyage; break;
|
||||
case Xow_domain_type_.Int__wikiquote: domain_tid = Tid_sub_wikiquote; break;
|
||||
case Xow_domain_type_.Int__wikibooks: domain_tid = Tid_sub_wikibooks; break;
|
||||
case Xow_domain_type_.Int__wikiversity: domain_tid = Tid_sub_wikiversity; break;
|
||||
case Xow_domain_type_.Int__wikinews: domain_tid = Tid_sub_wikinews; break;
|
||||
case Xow_domain_type_.Int__wikimedia: domain_tid = Tid_sub_wikimedia; break;
|
||||
default: throw Err_.new_unhandled(domain.Domain_type_id());
|
||||
}
|
||||
return Const_system_reserved // reserve first 100 slots
|
||||
+ domain_tid // domain_tid assigned above
|
||||
+ (domain.Lang_uid() * Const_lang_reserved) // reserve 20 wikis per lang
|
||||
return Const_system_reserved // reserve first 100 slots
|
||||
+ domain_tid // domain_tid assigned above
|
||||
+ (domain.Lang_actl_uid() * Const_lang_reserved) // reserve 20 wikis per lang
|
||||
;
|
||||
}
|
||||
public static Xow_domain To_domain(int tid) {
|
||||
public static Xow_domain_itm To_domain(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_xowa: return Xow_domain.new_(Xow_domain_.Domain_bry_home, Xow_domain_type_.Tid_home, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_commons: return Xow_domain.new_(Xow_domain_.Domain_bry_commons, Xow_domain_type_.Tid_commons, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_wikidata: return Xow_domain.new_(Xow_domain_.Domain_bry_wikidata, Xow_domain_type_.Tid_commons, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_mediawiki: return Xow_domain.new_(Xow_domain_.Domain_bry_mediawiki, Xow_domain_type_.Tid_mediawiki, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_meta: return Xow_domain.new_(Xow_domain_.Domain_bry_meta, Xow_domain_type_.Tid_meta, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_incubator: return Xow_domain.new_(Xow_domain_.Domain_bry_incubator, Xow_domain_type_.Tid_incubator, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_wmfblog: return Xow_domain.new_(Xow_domain_.Domain_bry_wmforg, Xow_domain_type_.Tid_wmfblog, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_species: return Xow_domain.new_(Xow_domain_.Domain_bry_species, Xow_domain_type_.Tid_species, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_xowa: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__home, Xow_domain_type_.Int__home, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_commons: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__commons, Xow_domain_type_.Int__commons, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_wikidata: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wikidata, Xow_domain_type_.Int__commons, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_mediawiki: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__mediawiki, Xow_domain_type_.Int__mediawiki, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_meta: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__meta, Xow_domain_type_.Int__meta, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_incubator: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__incubator, Xow_domain_type_.Int__incubator, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_wmfblog: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wmforg, Xow_domain_type_.Int__wmfblog, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_species: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__species, Xow_domain_type_.Int__species, Xol_lang_itm_.Key__unknown);
|
||||
}
|
||||
int tmp = tid - Const_system_reserved;
|
||||
int lang_id = tmp / 20;
|
||||
int type_id = tmp % 20;
|
||||
int tid_int = 0; byte[] tid_bry = null;
|
||||
switch (type_id) {
|
||||
case Tid_sub_wikipedia: tid_int = Xow_domain_type_.Tid_wikipedia; tid_bry = Xow_domain_type_.Key_bry_wikipedia; break;
|
||||
case Tid_sub_wiktionary: tid_int = Xow_domain_type_.Tid_wiktionary; tid_bry = Xow_domain_type_.Key_bry_wiktionary; break;
|
||||
case Tid_sub_wikisource: tid_int = Xow_domain_type_.Tid_wikisource; tid_bry = Xow_domain_type_.Key_bry_wikisource; break;
|
||||
case Tid_sub_wikivoyage: tid_int = Xow_domain_type_.Tid_wikivoyage; tid_bry = Xow_domain_type_.Key_bry_wikivoyage; break;
|
||||
case Tid_sub_wikiquote: tid_int = Xow_domain_type_.Tid_wikiquote; tid_bry = Xow_domain_type_.Key_bry_wikiquote; break;
|
||||
case Tid_sub_wikibooks: tid_int = Xow_domain_type_.Tid_wikibooks; tid_bry = Xow_domain_type_.Key_bry_wikibooks; break;
|
||||
case Tid_sub_wikiversity: tid_int = Xow_domain_type_.Tid_wikiversity; tid_bry = Xow_domain_type_.Key_bry_wikiversity; break;
|
||||
case Tid_sub_wikinews: tid_int = Xow_domain_type_.Tid_wikinews; tid_bry = Xow_domain_type_.Key_bry_wikinews; break;
|
||||
case Tid_sub_wikimedia: tid_int = Xow_domain_type_.Tid_wikimedia; tid_bry = Xow_domain_type_.Key_bry_wikimedia; break;
|
||||
case Tid_sub_wikipedia: tid_int = Xow_domain_type_.Int__wikipedia; tid_bry = Xow_domain_type_.Bry__wikipedia; break;
|
||||
case Tid_sub_wiktionary: tid_int = Xow_domain_type_.Int__wiktionary; tid_bry = Xow_domain_type_.Bry__wiktionary; break;
|
||||
case Tid_sub_wikisource: tid_int = Xow_domain_type_.Int__wikisource; tid_bry = Xow_domain_type_.Bry__wikisource; break;
|
||||
case Tid_sub_wikivoyage: tid_int = Xow_domain_type_.Int__wikivoyage; tid_bry = Xow_domain_type_.Bry__wikivoyage; break;
|
||||
case Tid_sub_wikiquote: tid_int = Xow_domain_type_.Int__wikiquote; tid_bry = Xow_domain_type_.Bry__wikiquote; break;
|
||||
case Tid_sub_wikibooks: tid_int = Xow_domain_type_.Int__wikibooks; tid_bry = Xow_domain_type_.Bry__wikibooks; break;
|
||||
case Tid_sub_wikiversity: tid_int = Xow_domain_type_.Int__wikiversity; tid_bry = Xow_domain_type_.Bry__wikiversity; break;
|
||||
case Tid_sub_wikinews: tid_int = Xow_domain_type_.Int__wikinews; tid_bry = Xow_domain_type_.Bry__wikinews; break;
|
||||
case Tid_sub_wikimedia: tid_int = Xow_domain_type_.Int__wikimedia; tid_bry = Xow_domain_type_.Bry__wikimedia; break;
|
||||
default: throw Err_.new_unhandled(type_id);
|
||||
}
|
||||
Xol_lang_itm lang = Xol_lang_itm_.Get_by_id(lang_id);
|
||||
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
bfr.Add(lang.Key()).Add_byte_dot().Add(tid_bry).Add_byte_dot().Add(Xow_domain_.Seg_bry_org);
|
||||
bfr.Add(lang.Key()).Add_byte_dot().Add(tid_bry).Add_byte_dot().Add(Xow_domain_itm_.Seg__org);
|
||||
byte[] domain_bry = bfr.Xto_bry_and_clear();
|
||||
bfr.Mkr_rls();
|
||||
return Xow_domain.new_(domain_bry, tid_int, lang);
|
||||
return Xow_domain_itm.new_(domain_bry, tid_int, lang, lang.Key());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,18 +20,18 @@ import org.junit.*;
|
||||
public class Xow_domain_uid__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xow_domain_uid__fxt fxt = new Xow_domain_uid__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test(Xow_domain_uid_.Tid_commons , "commons.wikimedia.org" , "", Xow_domain_type_.Tid_commons);
|
||||
fxt.Test(100 , "en.wikipedia.org" , "en", Xow_domain_type_.Tid_wikipedia);
|
||||
fxt.Test(Xow_domain_uid_.Tid_commons , "commons.wikimedia.org" , "", Xow_domain_type_.Int__commons);
|
||||
fxt.Test(100 , "en.wikipedia.org" , "en", Xow_domain_type_.Int__wikipedia);
|
||||
}
|
||||
}
|
||||
class Xow_domain_uid__fxt {
|
||||
public void Clear() {}
|
||||
public void Test(int tid, String domain_str, String expd_lang, int expd_tid) {
|
||||
byte[] domain_bry = Bry_.new_a7(domain_str);
|
||||
Xow_domain actl_domain = Xow_domain_uid_.To_domain(tid);
|
||||
Xow_domain_itm actl_domain = Xow_domain_uid_.To_domain(tid);
|
||||
Tfds.Eq_bry(domain_bry , actl_domain.Domain_bry());
|
||||
Tfds.Eq_bry(Bry_.new_a7(expd_lang) , actl_domain.Lang_key());
|
||||
Tfds.Eq(expd_tid , actl_domain.Domain_tid());
|
||||
Tfds.Eq_bry(Bry_.new_a7(expd_lang) , actl_domain.Lang_actl_key());
|
||||
Tfds.Eq(expd_tid , actl_domain.Domain_type_id());
|
||||
Tfds.Eq(tid, Xow_domain_uid_.To_int(actl_domain));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
import gplx.core.primitives.*;
|
||||
public interface Xow_domain_crt_itm {
|
||||
boolean Matches(Xow_domain cur, Xow_domain comp);
|
||||
boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp);
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ class Xow_domain_crt_itm_ {
|
||||
public static final Xow_domain_crt_itm Null = null;
|
||||
}
|
||||
class Xow_domain_crt_itm__any_wiki implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return true;}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return true;}
|
||||
public static final Xow_domain_crt_itm__any_wiki I = new Xow_domain_crt_itm__any_wiki(); Xow_domain_crt_itm__any_wiki() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__in implements Xow_domain_crt_itm {
|
||||
private final Xow_domain_crt_itm[] ary;
|
||||
public Xow_domain_crt_itm__in(Xow_domain_crt_itm[] ary) {this.ary = ary;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_crt_itm itm = ary[i];
|
||||
@@ -36,49 +36,49 @@ class Xow_domain_crt_itm__in implements Xow_domain_crt_itm {
|
||||
}
|
||||
}
|
||||
class Xow_domain_crt_itm__any_standard implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {
|
||||
switch (comp.Domain_tid()) {
|
||||
case Xow_domain_type_.Tid_wikipedia:
|
||||
case Xow_domain_type_.Tid_wiktionary:
|
||||
case Xow_domain_type_.Tid_wikisource:
|
||||
case Xow_domain_type_.Tid_wikivoyage:
|
||||
case Xow_domain_type_.Tid_wikiquote:
|
||||
case Xow_domain_type_.Tid_wikibooks:
|
||||
case Xow_domain_type_.Tid_wikiversity:
|
||||
case Xow_domain_type_.Tid_wikinews: return true;
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {
|
||||
switch (comp.Domain_type_id()) {
|
||||
case Xow_domain_type_.Int__wikipedia:
|
||||
case Xow_domain_type_.Int__wiktionary:
|
||||
case Xow_domain_type_.Int__wikisource:
|
||||
case Xow_domain_type_.Int__wikivoyage:
|
||||
case Xow_domain_type_.Int__wikiquote:
|
||||
case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity:
|
||||
case Xow_domain_type_.Int__wikinews: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static final Xow_domain_crt_itm__any_standard I = new Xow_domain_crt_itm__any_standard(); Xow_domain_crt_itm__any_standard() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__none implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return false;}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return false;}
|
||||
public static final Xow_domain_crt_itm__none I = new Xow_domain_crt_itm__none(); Xow_domain_crt_itm__none() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__self implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return Bry_.Eq(cur.Domain_bry(), comp.Domain_bry());}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return Bry_.Eq(cur.Domain_bry(), comp.Domain_bry());}
|
||||
public static final Xow_domain_crt_itm__self I = new Xow_domain_crt_itm__self(); Xow_domain_crt_itm__self() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__same_lang implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return Bry_.Eq(cur.Lang_orig_key(), comp.Lang_orig_key());}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return Bry_.Eq(cur.Lang_orig_key(), comp.Lang_orig_key());}
|
||||
public static final Xow_domain_crt_itm__same_lang I = new Xow_domain_crt_itm__same_lang(); Xow_domain_crt_itm__same_lang() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__same_type implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return cur.Domain_tid() == comp.Domain_tid();}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return cur.Domain_type_id() == comp.Domain_type_id();}
|
||||
public static final Xow_domain_crt_itm__same_type I = new Xow_domain_crt_itm__same_type(); Xow_domain_crt_itm__same_type() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__lang implements Xow_domain_crt_itm {
|
||||
private final int lang_uid;
|
||||
public Xow_domain_crt_itm__lang(int lang_uid) {this.lang_uid = lang_uid;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return comp.Lang_orig_uid() == lang_uid;}
|
||||
private final byte[] lang_key;
|
||||
public Xow_domain_crt_itm__lang(byte[] lang_key) {this.lang_key = lang_key;}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return Bry_.Eq(comp.Lang_orig_key(), lang_key);}
|
||||
}
|
||||
class Xow_domain_crt_itm__type implements Xow_domain_crt_itm {
|
||||
private final int wiki_tid;
|
||||
public Xow_domain_crt_itm__type(int wiki_tid) {this.wiki_tid = wiki_tid;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return comp.Domain_tid() == wiki_tid;}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return comp.Domain_type_id() == wiki_tid;}
|
||||
}
|
||||
class Xow_domain_crt_itm__wiki implements Xow_domain_crt_itm {
|
||||
private final byte[] domain;
|
||||
public Xow_domain_crt_itm__wiki(byte[] domain) {this.domain = domain;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return Bry_.Eq(comp.Domain_bry(), domain);}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return Bry_.Eq(comp.Domain_bry(), domain);}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,11 @@ class Xow_domain_crt_itm_parser {
|
||||
int raw_len = raw.length;
|
||||
if (Bry_.Has_at_bgn(raw, Wild_lang)) { // EX: *.wikipedia
|
||||
int wiki_tid = Xow_domain_type_.Get_type_as_tid(raw, Wild_lang.length, raw_len);
|
||||
return wiki_tid == Xow_domain_type_.Tid_null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__type(wiki_tid);
|
||||
return wiki_tid == Xow_domain_type_.Int__null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__type(wiki_tid);
|
||||
}
|
||||
else if (Bry_.Has_at_end(raw, Wild_type)) { // EX: en.*
|
||||
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(raw, 0, raw_len - Wild_type.length);
|
||||
return lang_itm == null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__lang(lang_itm.Id());
|
||||
return lang_itm == null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__lang(lang_itm.Key());
|
||||
}
|
||||
else
|
||||
return new Xow_domain_crt_itm__wiki(raw); // EX: en.wikipedia.org
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Xow_domain_crt_kv_itm_mgr {
|
||||
list.Add(ary[i]);
|
||||
return true;
|
||||
}
|
||||
public Xow_domain_crt_itm Find_itm(Xow_domain cur, Xow_domain comp) {
|
||||
public Xow_domain_crt_itm Find_itm(Xow_domain_itm cur, Xow_domain_itm comp) {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_crt_kv_itm kv = (Xow_domain_crt_kv_itm)list.Get_at(i);
|
||||
@@ -46,7 +46,7 @@ public class Xow_domain_crt_kv_itm_mgr {
|
||||
}
|
||||
return Xow_domain_crt_itm__none.I;
|
||||
}
|
||||
public Xow_domain_crt_itm[] Find_ary(Xow_domain cur, Xow_domain comp) {
|
||||
public Xow_domain_crt_itm[] Find_ary(Xow_domain_itm cur, Xow_domain_itm comp) {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_crt_kv_ary kv = (Xow_domain_crt_kv_ary)list.Get_at(i);
|
||||
|
||||
Reference in New Issue
Block a user