1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-08-24 00:32:13 -04:00
parent df10db140c
commit ed911e3de5
220 changed files with 2618 additions and 1569 deletions

View File

@@ -16,6 +16,7 @@ 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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
public class Xoa_wiki_regy {
private Xoae_app app;
private boolean init_needed = true;
@@ -28,8 +29,8 @@ public class Xoa_wiki_regy {
}
public boolean Url_is_invalid_domain(Xoa_url url) {
if (!Bry_.Eq(url.Page_bry(), Xoa_page_.Main_page_bry)) return false; // page is not "Main_Page"; assume not an invalid domain str; EX: "uk/wiki/Main_Page"
if ( Bry_.Eq(Xow_domain_type_.Key_bry_home, url.Wiki_bry()) // wiki is "home"
&& !Bry_.Eq(Xow_domain_type_.Key_bry_home, url.Raw())) // raw is "home"; should be "home/wiki/Main_Page"; DATE:2014-02-09
if ( Bry_.Eq(Xow_domain_type_.Bry__home, url.Wiki_bry()) // wiki is "home"
&& !Bry_.Eq(Xow_domain_type_.Bry__home, url.Raw())) // raw is "home"; should be "home/wiki/Main_Page"; DATE:2014-02-09
return false; // special case to handle "home" which should mean "home" in any wiki, but "home/wiki/Main_Page" in home wiki
return !this.Has(url.Wiki_bry());
}

View File

@@ -16,7 +16,8 @@ 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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.wikis.domains.crts.*;
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.domains.crts.*;
public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
private Xoae_app app;
private List_adp list = List_adp_.new_(); private Hash_adp_bry hash = Hash_adp_bry.ci_a7(); // ASCII:url_domain; EX:en.wikipedia.org
@@ -51,7 +52,7 @@ public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
return rv;
}
public Xowe_wiki Wiki_commons() {
Xowe_wiki rv = this.Get_by_key_or_null(Xow_domain_.Domain_bry_commons);
Xowe_wiki rv = this.Get_by_key_or_null(Xow_domain_itm_.Bry__commons);
if (rv != null) rv.Init_assert();
return rv;
}
@@ -93,13 +94,14 @@ public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
} private static final String Invk_get = "get", Invk_groups = "groups", Invk_scripts = "scripts", Invk_wdata = "wdata";
private static final String Invk_len = "len", Invk_get_at = "get_at";
private Xowe_wiki New_wiki(byte[] key) {
Xow_domain domain_itm = Xow_domain_.parse(key);
byte[] lang_key = domain_itm.Lang_key();
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(key);
byte[] lang_key = domain_itm.Lang_actl_key();
if (lang_key == Xol_lang_itm_.Key__unknown) lang_key = Xol_lang_.Key_en; // unknown langs default to english; note that this makes nonwmf english by default
Xol_lang lang =
domain_itm.Domain_tid() == Xow_domain_type_.Tid_other
? new Xol_lang(app.Lang_mgr(), Xol_lang_.Key_en).Kwd_mgr__strx_(true)
: app.Lang_mgr().Get_by_key_or_new(lang_key);
Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(lang_key);
if (domain_itm.Domain_type_id() == Xow_domain_type_.Int__other) {
lang = new Xol_lang(app.Lang_mgr(), Xol_lang_.Key_en).Kwd_mgr__strx_(true); // create a new english lang, but enable strx functions; DATE:2015-08-23
Xol_lang_.Lang_init(lang);
}
Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(lang.Case_mgr());
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(domain_itm.Domain_str());
Xowe_wiki rv = new Xowe_wiki(app, lang, ns_mgr, domain_itm, wiki_dir);

View File

@@ -1,50 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.langs.*;
public class Xow_domain {
Xow_domain(byte[] domain_bry, Xow_domain_type domain_type, Xol_lang_itm lang_itm, Xol_lang_itm lang_orig_itm) {
this.domain_bry = domain_bry; this.domain_type = domain_type; this.lang_itm = lang_itm; this.lang_orig_itm = lang_orig_itm;
this.domain_str = String_.new_u8(domain_bry);
this.abrv_xo = Xow_domain_abrv_xo_.To_bry(domain_bry, lang_orig_itm, 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 int Domain_tid() {return domain_type.Tid();}
public Xow_domain_type Domain_type() {return domain_type;} private final Xow_domain_type domain_type;
public byte[] Abrv_wm() {return abrv_wm;} public void Abrv_wm_(byte[] v) {abrv_wm = v;} private byte[] abrv_wm; // EX: enwiki
public byte[] Abrv_xo() {return abrv_xo;} private final byte[] abrv_xo;
public Xol_lang_itm Lang_itm() {return lang_itm;} private final Xol_lang_itm lang_itm;
public int Lang_uid() {return lang_itm.Id();}
public byte[] Lang_key() {return lang_itm.Key();}
public Xol_lang_itm Lang_orig_itm() {return lang_orig_itm;} private final Xol_lang_itm lang_orig_itm;
public int Lang_orig_uid() {return lang_orig_itm.Id();}
public byte[] Lang_orig_key() {return lang_orig_itm.Key();}
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 new_(byte[] domain_bry, int domain_tid, byte[] lang_key) {
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key);
return new Xow_domain(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_itm, lang_itm);
}
public static Xow_domain new_(byte[] domain_bry, int domain_tid, Xol_lang_itm lang) {return new Xow_domain(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang, lang);}
public static Xow_domain new_orig(byte[] domain_bry, int domain_tid, byte[] lang_key, byte[] lang_orig_key) {
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key);
Xol_lang_itm lang_orig_itm = Bry_.Eq(lang_key, lang_orig_key) ? lang_itm : Xol_lang_itm_.Get_by_key_or_intl(lang_orig_key);
return new Xow_domain(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_itm, lang_orig_itm);
}
}

View File

@@ -1,104 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.core.primitives.*;
import gplx.xowa.langs.*;
public class Xow_domain_ {
public static final String
Domain_str_enwiki = "en.wikipedia.org"
, Domain_str_species = "species.wikimedia.org"
, Domain_str_commons = "commons.wikimedia.org"
, Domain_str_wikidata = "www.wikidata.org"
, Domain_str_mediawiki = "www.mediawiki.org"
, Domain_str_meta = "meta.wikimedia.org"
, Domain_str_incubator = "incubator.wikimedia.org"
, Domain_str_wmforg = "wikimediafoundation.org"
, Domain_str_home = "home"
;
public static final byte[]
Domain_bry_enwiki = Bry_.new_a7(Domain_str_enwiki)
, Domain_bry_species = Bry_.new_a7(Domain_str_species)
, Domain_bry_commons = Bry_.new_a7(Domain_str_commons)
, Domain_bry_wikidata = Bry_.new_a7(Domain_str_wikidata)
, Domain_bry_mediawiki = Bry_.new_a7(Domain_str_mediawiki)
, Domain_bry_meta = Bry_.new_a7(Domain_str_meta)
, Domain_bry_incubator = Bry_.new_a7(Domain_str_incubator)
, Domain_bry_wmforg = Bry_.new_a7(Domain_str_wmforg)
, Domain_bry_home = Bry_.new_a7(Domain_str_home)
;
public static final byte[] Seg_bry_org = Bry_.new_a7("org"), Seg_bry_www = Bry_.new_a7("www");
public static Xow_domain 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_.Key_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_.Key_bry_wmforg)
? Xow_domain.new_(raw, Xow_domain_type_.Tid_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_.Tid_null) return new_other(raw); // seg_1 is unknown; return other;
switch (seg_1_tid) {
case Xow_domain_type_.Tid_wikipedia: case Xow_domain_type_.Tid_wiktionary: case Xow_domain_type_.Tid_wikisource: case Xow_domain_type_.Tid_wikibooks:
case Xow_domain_type_.Tid_wikiversity: case Xow_domain_type_.Tid_wikiquote: case Xow_domain_type_.Tid_wikinews: case Xow_domain_type_.Tid_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.new_orig(raw, seg_1_tid, lang_actl, lang_orig); // NOTE: seg_tids must match wiki_tids
case Xow_domain_type_.Tid_wikidata: case Xow_domain_type_.Tid_mediawiki: // ~www.~{type}.org
return Xow_domain.new_(raw, seg_1_tid, Xol_lang_itm_.Key__unknown);
case Xow_domain_type_.Tid_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_.Tid_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.new_(raw, Xow_domain_type_.Tid_wikimedia, wikimedia_lang.Key());
}
switch (seg_0_tid) {
case Xow_domain_type_.Tid_commons: case Xow_domain_type_.Tid_species: case Xow_domain_type_.Tid_meta: case Xow_domain_type_.Tid_incubator:
return Xow_domain.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_.Tid_other:
default:
return new_other(raw);
}
}
private static Xow_domain new_other(byte[] raw) {return Xow_domain.new_(raw, Xow_domain_type_.Tid_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"))
;
}

View File

@@ -1,39 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*;
public class Xow_domain_tst {
@Before public void init() {fxt.Clear();} private final Xow_domain_fxt fxt = new Xow_domain_fxt();
@Test public void Parse_en_wikipedia() {fxt.Test_parse("en.wikipedia.org" , "en" , Xow_domain_type_.Tid_wikipedia);}
@Test public void Parse_fr_wikipedia() {fxt.Test_parse("fr.wikipedia.org" , "fr" , Xow_domain_type_.Tid_wikipedia);}
@Test public void Parse_en_wiktionary() {fxt.Test_parse("en.wiktionary.org" , "en" , Xow_domain_type_.Tid_wiktionary);}
@Test public void Parse_zh_classical_wikipedia() {fxt.Test_parse("zh-classical.wikipedia.org" , "lzh" , Xow_domain_type_.Tid_wikipedia);}
@Test public void Parse_commons() {fxt.Test_parse("commons.wikimedia.org" , "" , Xow_domain_type_.Tid_commons);}
@Test public void Parse_species() {fxt.Test_parse("species.wikimedia.org" , "" , Xow_domain_type_.Tid_species);}
@Test public void Parse_ru_wikimedia_org() {fxt.Test_parse("ru.wikimedia.org" , "ru" , Xow_domain_type_.Tid_wikimedia);}
@Test public void Parse_home() {fxt.Test_parse("home" , "" , Xow_domain_type_.Tid_home);}
@Test public void Parse_other() {fxt.Test_parse("other.wiki" , "" , Xow_domain_type_.Tid_other);}
}
class Xow_domain_fxt {
public void Clear() {}
public void Test_parse(String domain, String expd_lang, int expd_tid) {
Xow_domain actl = Xow_domain_.parse(Bry_.new_a7(domain));
Tfds.Eq(expd_lang, String_.new_a7((actl.Lang_key())));
Tfds.Eq(expd_tid, actl.Domain_tid());
}
}

View File

@@ -1,131 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xow_domain_type_ {
public static final int
Tid_null = 0
, Tid_wikipedia = 1
, Tid_wiktionary = 2
, Tid_wikisource = 3
, Tid_wikivoyage = 4
, Tid_wikiquote = 5
, Tid_wikibooks = 6
, Tid_wikiversity = 7
, Tid_wikinews = 8
, Tid_wikimedia = 9
, Tid_species = 10
, Tid_commons = 11
, Tid_wikidata = 12
, Tid_mediawiki = 13
, Tid_meta = 14
, Tid_incubator = 15
, Tid_wmfblog = 16
, Tid_home = 17
, Tid_other = 18
, Tid__len = 19
;
public static final String // SERIALIZED:xowa.gfs
Key_str_wikipedia = "wikipedia"
, Key_str_wiktionary = "wiktionary"
, Key_str_wikisource = "wikisource"
, Key_str_wikivoyage = "wikivoyage"
, Key_str_wikiquote = "wikiquote"
, Key_str_wikibooks = "wikibooks"
, Key_str_wikiversity = "wikiversity"
, Key_str_wikinews = "wikinews"
, Key_str_wikimedia = "wikimedia"
, Key_str_species = "species"
, Key_str_commons = "commons"
, Key_str_wikidata = "wikidata"
, Key_str_mediawiki = "mediawiki"
, Key_str_meta = "meta"
, Key_str_incubator = "incubator"
, Key_str_wmforg = "wikimediafoundation"
, Key_str_home = "home"
, Key_str_other = "other"
;
public static final byte[]
Key_bry_wikipedia = Bry_.new_a7(Key_str_wikipedia)
, Key_bry_wiktionary = Bry_.new_a7(Key_str_wiktionary)
, Key_bry_wikisource = Bry_.new_a7(Key_str_wikisource)
, Key_bry_wikivoyage = Bry_.new_a7(Key_str_wikivoyage)
, Key_bry_wikiquote = Bry_.new_a7(Key_str_wikiquote)
, Key_bry_wikibooks = Bry_.new_a7(Key_str_wikibooks)
, Key_bry_wikiversity = Bry_.new_a7(Key_str_wikiversity)
, Key_bry_wikinews = Bry_.new_a7(Key_str_wikinews)
, Key_bry_wikimedia = Bry_.new_a7(Key_str_wikimedia)
, Key_bry_species = Bry_.new_a7(Key_str_species)
, Key_bry_commons = Bry_.new_a7(Key_str_commons)
, Key_bry_wikidata = Bry_.new_a7(Key_str_wikidata)
, Key_bry_mediawiki = Bry_.new_a7(Key_str_mediawiki)
, Key_bry_meta = Bry_.new_a7(Key_str_meta)
, Key_bry_incubator = Bry_.new_a7(Key_str_incubator)
, Key_bry_wmforg = Bry_.new_a7(Key_str_wmforg)
, Key_bry_home = Bry_.new_a7(Key_str_home)
, Key_bry_other = Bry_.new_a7(Key_str_other)
;
private static final Xow_domain_type[] ary = new Xow_domain_type[Tid__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_.Tid_wmf , Tid_wikipedia , Key_bry_wikipedia , "w" , ".wikipedia.org")
, Itm_wiktionary = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wiktionary , Key_bry_wiktionary , "d" , ".wiktionary.org")
, Itm_wikisource = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikisource , Key_bry_wikisource , "s" , ".wikisource.org")
, Itm_wikivoyage = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikivoyage , Key_bry_wikivoyage , "v" , ".wikivoyage.org")
, Itm_wikiquote = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikiquote , Key_bry_wikiquote , "q" , ".wikiquote.org")
, Itm_wikibooks = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikibooks , Key_bry_wikibooks , "b" , ".wikibooks.org")
, Itm_wikiversity = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikiversity , Key_bry_wikiversity , "u" , ".wikiversity.org")
, Itm_wikinews = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikinews , Key_bry_wikinews , "n" , ".wikinews.org")
, Itm_wikimedia = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikimedia , Key_bry_wikimedia , "m" , ".wikimedia.org")
, Itm_species = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_species , Key_bry_species , "species" , Xow_domain_.Domain_str_species)
, Itm_commons = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_commons , Key_bry_commons , "c" , Xow_domain_.Domain_str_commons)
, Itm_wikidata = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_wikidata , Key_bry_wikidata , "wd" , Xow_domain_.Domain_str_wikidata)
, Itm_mediawiki = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_mediawiki , Key_bry_mediawiki , "mw" , Xow_domain_.Domain_str_mediawiki)
, Itm_meta = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_meta , Key_bry_meta , "meta" , Xow_domain_.Domain_str_meta)
, Itm_incubator = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_incubator , Key_bry_incubator , "qb" , Xow_domain_.Domain_str_incubator)
, Itm_wmforg = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_wmfblog , Key_bry_wmforg , "wmf" , Xow_domain_.Domain_str_wmforg)
, Itm_home = new_(Bool_.N , Xow_domain_type_src_.Tid_xowa , Tid_home , Key_bry_home , "home" , Xow_domain_.Domain_str_home)
, Itm_other = new_(Bool_.N , Xow_domain_type_src_.Tid_mw , Tid_other , Key_bry_other , "" , "")
;
private static Xow_domain_type new_(boolean multi_lang, int src, int tid, byte[] key_bry, String abrv_str, String domain_bry) {
byte[] abrv_bry = Bry_.new_u8(abrv_str);
Xow_domain_type rv = new Xow_domain_type(multi_lang, src, tid, key_bry, abrv_bry, Bry_.new_u8(domain_bry));
ary[tid] = rv;
type_regy.Add(key_bry , rv);
abrv_regy.Add(abrv_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_.Tid_null : ((Xow_domain_type)o).Tid();
}
}
class Xow_domain_type_src_ {
public static final int
Tid_wmf = 1 // administered by wmf; wikipedia, etc.
, Tid_wikia = 2 // *.wikia.com
, Tid_mw = 3 // mediawiki installations not part of wmf, wikia
, Tid_xowa = 4 // xowa
;
}

View File

@@ -1,73 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.xowa.langs.*;
public class Xow_wiki_abrv_ {
public static boolean parse_(Xow_wiki_abrv rv, byte[] src, int bgn, int end) {
rv.Clear();
if (end - bgn == 0) return false; // empty bry
Object o = trie.Match_bgn(src, end - 1, bgn - 1); if (o == null) return false;
byte tid = ((Byte_obj_val)o).Val();
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(src, bgn, trie.Match_pos() + 1);
rv.Ctor_by_parse(lang_itm, tid);
return true;
}
public static final byte
Tid_null = Xow_domain_type_.Tid_other
, Tid_wikipedia = Xow_domain_type_.Tid_wikipedia
, Tid_wiktionary = Xow_domain_type_.Tid_wiktionary
, Tid_wikisource = Xow_domain_type_.Tid_wikisource
, Tid_wikibooks = Xow_domain_type_.Tid_wikibooks
, Tid_wikiversity = Xow_domain_type_.Tid_wikiversity
, Tid_wikiquote = Xow_domain_type_.Tid_wikiquote
, Tid_wikinews = Xow_domain_type_.Tid_wikinews
, Tid_wikivoyage = Xow_domain_type_.Tid_wikivoyage
, Tid_commons = Xow_domain_type_.Tid_commons
, Tid_species = Xow_domain_type_.Tid_species
, Tid_meta = Xow_domain_type_.Tid_meta
, Tid_incubator = Xow_domain_type_.Tid_incubator
, Tid_wikidata = Xow_domain_type_.Tid_wikidata
, Tid_mediawiki = Xow_domain_type_.Tid_mediawiki
, Tid_wmfblog = Xow_domain_type_.Tid_wmfblog
;
private static final Btrie_bwd_mgr trie = Init_trie();
private static Btrie_bwd_mgr Init_trie() {
Btrie_bwd_mgr rv = new Btrie_bwd_mgr(false);
Init_trie_itm(rv, "wiki" , Tid_wikipedia);
Init_trie_itm(rv, "wiktionary" , Tid_wiktionary);
Init_trie_itm(rv, "wikisource" , Tid_wikisource);
Init_trie_itm(rv, "wikibooks" , Tid_wikibooks);
Init_trie_itm(rv, "wikiversity" , Tid_wikiversity);
Init_trie_itm(rv, "wikiquote" , Tid_wikiquote);
Init_trie_itm(rv, "wikinews" , Tid_wikinews);
Init_trie_itm(rv, "wikivoyage" , Tid_wikivoyage);
Init_trie_itm(rv, "commonswiki" , Tid_commons);
Init_trie_itm(rv, "specieswiki" , Tid_species);
Init_trie_itm(rv, "metawiki" , Tid_meta);
Init_trie_itm(rv, "incubatorwiki" , Tid_incubator);
Init_trie_itm(rv, "wikidatawiki" , Tid_wikidata);
Init_trie_itm(rv, "mediawikiwiki" , Tid_mediawiki);
Init_trie_itm(rv, "foundationwiki" , Tid_wmfblog);
return rv;
}
private static void Init_trie_itm(Btrie_bwd_mgr rv, String abrv_name, byte abrv_tid) {
rv.Add(abrv_name, Byte_obj_val.new_(abrv_tid));
}
}

View File

@@ -1,52 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Xow_wiki_abrv_tst {
@Before public void init() {fxt.Clear();} private Xow_wiki_abrv_fxt fxt = new Xow_wiki_abrv_fxt();
@Test public void Parse() {
fxt.Parse("foundationwiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_wmfblog);
fxt.Parse("wikidatawiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_wikidata);
fxt.Parse("mediawikiwiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_mediawiki);
fxt.Parse("commonswiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_commons);
fxt.Parse("specieswiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_species);
fxt.Parse("metawiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_meta);
fxt.Parse("incubatorwiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_incubator);
fxt.Parse("enwiki" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikipedia);
fxt.Parse("enwiktionary" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wiktionary);
fxt.Parse("enwikisource" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikisource);
fxt.Parse("enwikibooks" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikibooks);
fxt.Parse("enwikiversity" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikiversity);
fxt.Parse("enwikiquote" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikiquote);
fxt.Parse("enwikinews" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikinews);
fxt.Parse("enwikivoyage" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikivoyage);
fxt.Parse("frwiki" , Xol_lang_itm_.Id_fr , Xow_wiki_abrv_.Tid_wikipedia);
fxt.Parse("unknown" , Xol_lang_itm_.Id__unknown , Xow_wiki_abrv_.Tid_null);
}
}
class Xow_wiki_abrv_fxt {
private Xow_wiki_abrv abrv = new Xow_wiki_abrv();
public void Clear() {}
public void Parse(String raw, int expd_lang_id, byte expd_domain_tid) {
byte[] raw_bry = Bry_.new_a7(raw);
Xow_wiki_abrv_.parse_(abrv, raw_bry, 0, raw_bry.length);
Xol_lang_itm actl_lang_itm = abrv.Lang_itm();
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_tid());
}
}

View File

@@ -1,244 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
public class Xow_wiki_alias {
public Io_url Fil() {return fil;} public Xow_wiki_alias Fil_(Io_url v) {fil = v; return this;} Io_url fil;
public byte Tid() {return tid;} private byte tid;
public byte[] Domain() {return domain;} private byte[] domain;
public String Date() {return date;} private String date; // needs to be String to handle "latest"
public Xow_wiki_alias Parse(String fil_name) {return Parse(Bry_.new_a7(fil_name));}
public Xow_wiki_alias Parse(byte[] fil_name) {
int fil_name_len = fil_name.length;
int dash_0 = Bry_finder.Find_fwd(fil_name, Byte_ascii.Dash, 0 , fil_name_len); if (dash_0 == Bry_.NotFound) throw Err_.new_parse_type(Xow_wiki_alias.class, String_.new_u8(fil_name));
int dash_1 = Bry_finder.Find_fwd(fil_name, Byte_ascii.Dash, dash_0 + 1 , fil_name_len); if (dash_1 == Bry_.NotFound) throw Err_.new_parse_type(Xow_wiki_alias.class, String_.new_u8(fil_name));
domain = Parse__domain_name(fil_name, 0, dash_0);
date = String_.new_a7(fil_name, dash_0 + 1, dash_1);
tid = Parse__tid(fil_name, dash_1 + 1, fil_name_len);
return this;
}
public static int Extract_lang(byte[] src) {
if (alias_bry_trie == null) Init_aliases();
Object o = alias_bry_trie.Match_bgn(src, src.length - 1, 0 - 1);
return (o == null) ? -1 : alias_bry_trie.Match_pos();
}
public static byte[] Build_alias(Xow_domain wiki_type) {
if (alias_bry_trie == null) Init_aliases();
int tid = wiki_type.Domain_tid();
byte[] alias = (byte[])alias_val_hash.Get_by(Int_obj_ref.new_(tid));
if (alias == null) return null;
switch (tid) {
case Xow_domain_type_.Tid_commons:
case Xow_domain_type_.Tid_species:
case Xow_domain_type_.Tid_meta:
case Xow_domain_type_.Tid_incubator:
case Xow_domain_type_.Tid_wikidata:
case Xow_domain_type_.Tid_mediawiki:
case Xow_domain_type_.Tid_wmfblog:
return alias;
case Xow_domain_type_.Tid_wikipedia:
case Xow_domain_type_.Tid_wiktionary:
case Xow_domain_type_.Tid_wikisource:
case Xow_domain_type_.Tid_wikibooks:
case Xow_domain_type_.Tid_wikiversity:
case Xow_domain_type_.Tid_wikiquote:
case Xow_domain_type_.Tid_wikinews:
case Xow_domain_type_.Tid_wikivoyage:
case Xow_domain_type_.Tid_wikimedia:
return Bry_.Add(wiki_type.Lang_orig_key(), alias);
default:
throw Err_.new_unhandled(tid);
}
}
public static byte[] Parse_wmf_key(byte[] src) {return Parse__domain_name(src, 0, src.length);}
public static byte[] Parse__domain_name_null = null;
public static byte[] Parse__domain_name(byte[] src, int bgn, int end) {
if (end - bgn == 0) return null; // empty bry;
if (alias_bry_trie == null) Init_aliases();
Object o = alias_bry_trie.Match_bgn(src, end - 1, bgn - 1); if (o == null) return Parse__domain_name_null;
int domain_tid = ((Int_obj_ref)o).Val();
Bry_bfr bfr = Bry_bfr.reset_(255);
switch (domain_tid) {
case Domain_wikimediafoundation: return bfr.Add(Xow_domain_type_.Key_bry_wmforg).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
case Domain_wikidata:
case Domain_mediawiki: return bfr.Add(Xow_domain_.Seg_bry_www).Add_byte(Byte_ascii.Dot).Add(Xow_domain_type_.Get_type_as_bry(domain_tid)).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
case Domain_commons:
case Domain_species:
case Domain_meta:
case Domain_incubator: return bfr.Add(Xow_domain_type_.Get_type_as_bry(domain_tid)).Add_byte(Byte_ascii.Dot).Add(Xow_domain_type_.Key_bry_wikimedia).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
case Domain_wikipedia:
case Domain_wiktionary:
case Domain_wikisource:
case Domain_wikibooks:
case Domain_wikiversity:
case Domain_wikiquote:
case Domain_wikinews:
case Domain_wikivoyage:
case Domain_wikimedia:
bfr.Add_mid(src, 0, alias_bry_trie.Match_pos() + 1);
bfr.Add_byte(Byte_ascii.Dot);
return bfr.Add(Xow_domain_type_.Get_type_as_bry(domain_tid)).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
}
return null;
}
// TODO: swap out above with below
// public byte[] Domain() {if (domain == null) domain = Domain_init(lang_itm, domain_tid); return domain;} private byte[] domain;
// private static byte[] Domain_init(Xol_lang_itm lang_itm, byte domain_tid) {
// switch (domain_tid) {
// case Xow_wiki_abrv_.Tid_wmfblog: return Xow_domain_.Bry_wikimediafoundation;
// case Xow_wiki_abrv_.Tid_wikidata: return Xow_domain_.Domain_bry_wikidata;
// case Xow_wiki_abrv_.Tid_mediawiki: return Xow_domain_.Bry_mediawiki;
// case Xow_wiki_abrv_.Tid_commons: return Xow_domain_.Domain_bry_commons;
// case Xow_wiki_abrv_.Tid_species: return Xow_domain_.Bry_species;
// case Xow_wiki_abrv_.Tid_meta: return Xow_domain_.Bry_meta;
// case Xow_wiki_abrv_.Tid_incubator: return Xow_domain_.Bry_incubator;
// case Xow_wiki_abrv_.Tid_wikipedia:
// case Xow_wiki_abrv_.Tid_wiktionary:
// case Xow_wiki_abrv_.Tid_wikisource:
// case Xow_wiki_abrv_.Tid_wikibooks:
// case Xow_wiki_abrv_.Tid_wikiversity:
// case Xow_wiki_abrv_.Tid_wikiquote:
// case Xow_wiki_abrv_.Tid_wikinews:
// case Xow_wiki_abrv_.Tid_wikivoyage:
// return Bry_.Add
// ( lang_itm.Key() // en
// , Byte_ascii.Dot_bry // .
// , Xow_domain_type_.Get_type_as_bry(domain_tid) // wikipedia
// , Byte_ascii.Dot_bry // .
// , Xow_domain_.Seg_bry_org // org
// );
// default:
// return Bry_.Empty;
// }
// }
public static byte Parse__tid(String src) {return Parse__tid(Bry_.new_u8(src));}
public static byte Parse__tid(byte[] src) {return Parse__tid(src, 0, src.length);}
public static byte Parse__tid(byte[] src, int bgn, int end) {
if (tid_bry_trie == null) Init_tids();
Object o = tid_bry_trie.Match_bgn(src, bgn, end); if (o == null) throw Err_.new_parse_type(Xow_wiki_alias.class, String_.new_u8(src));
return ((Byte_obj_ref)o).Val();
}
public static void Build_alias_by_lang_tid(Bry_bfr bfr, byte[] lang_key, Int_obj_ref wiki_tid) {
if (alias_bry_trie == null) Init_aliases();
byte[] domain_suffix = (byte[])alias_val_hash.Get_by(wiki_tid);
if (domain_suffix == null) return;
switch (wiki_tid.Val()) {
case Xow_domain_type_.Tid_commons:
case Xow_domain_type_.Tid_species:
case Xow_domain_type_.Tid_meta:
case Xow_domain_type_.Tid_incubator:
case Xow_domain_type_.Tid_wikidata:
case Xow_domain_type_.Tid_mediawiki:
case Xow_domain_type_.Tid_wmfblog:
bfr.Add(domain_suffix);
break;
case Xow_domain_type_.Tid_other:
break;
default:
bfr.Add(lang_key).Add(domain_suffix);
break;
}
}
public static Xow_domain parse_by_wmf_key(byte[] wmf_key) {
if (Bry_.Has(wmf_key, Byte_ascii.Underline)) // convert "_" to "-"; note that wmf_keys have a strict format of langtype; EX: "zh_yuewiki"; DATE:2014-10-06
wmf_key = Bry_.Replace_create(wmf_key, Byte_ascii.Underline, Byte_ascii.Dash);
byte[] domain_bry = Parse__domain_name(wmf_key, 0, wmf_key.length);
Xow_domain rv = Xow_domain_.parse(domain_bry);
rv.Abrv_wm_(wmf_key);
return rv;
}
public static final byte Tid_null = 0, Tid_pages_articles = 1, Tid_pages_meta_current = 2, Tid_categorylinks = 3, Tid_page_props = 4, Tid_image = 5;
public static final String Key_null = ""
, Key_pages_articles = "pages-articles", Key_pages_meta_current = "pages-meta-current"
, Key_categorylinks = "categorylinks", Key_page_props = "page_props"
, Key_image = "image"
;
private static final byte
Domain_wikipedia = Xow_domain_type_.Tid_wikipedia
, Domain_wiktionary = Xow_domain_type_.Tid_wiktionary
, Domain_wikisource = Xow_domain_type_.Tid_wikisource
, Domain_wikibooks = Xow_domain_type_.Tid_wikibooks
, Domain_wikiversity = Xow_domain_type_.Tid_wikiversity
, Domain_wikiquote = Xow_domain_type_.Tid_wikiquote
, Domain_wikinews = Xow_domain_type_.Tid_wikinews
, Domain_wikivoyage = Xow_domain_type_.Tid_wikivoyage
, Domain_wikimedia = Xow_domain_type_.Tid_wikimedia
, Domain_commons = Xow_domain_type_.Tid_commons
, Domain_species = Xow_domain_type_.Tid_species
, Domain_meta = Xow_domain_type_.Tid_meta
, Domain_incubator = Xow_domain_type_.Tid_incubator
, Domain_wikidata = Xow_domain_type_.Tid_wikidata
, Domain_mediawiki = Xow_domain_type_.Tid_mediawiki
, Domain_wikimediafoundation = Xow_domain_type_.Tid_wmfblog;
private static void Init_aliases() {
alias_bry_trie = new Btrie_bwd_mgr(false);
alias_val_hash = Hash_adp_.new_();
Init_alias("wiki" , Domain_wikipedia);
Init_alias("wiktionary" , Domain_wiktionary);
Init_alias("wikisource" , Domain_wikisource);
Init_alias("wikibooks" , Domain_wikibooks);
Init_alias("wikiversity" , Domain_wikiversity);
Init_alias("wikiquote" , Domain_wikiquote);
Init_alias("wikinews" , Domain_wikinews);
Init_alias("wikivoyage" , Domain_wikivoyage);
Init_alias("wikimedia" , Domain_wikimedia);
Init_alias("commonswiki" , Domain_commons);
Init_alias("specieswiki" , Domain_species);
Init_alias("metawiki" , Domain_meta);
Init_alias("incubatorwiki" , Domain_incubator);
Init_alias("wikidatawiki" , Domain_wikidata);
Init_alias("mediawikiwiki" , Domain_mediawiki);
Init_alias("foundationwiki" , Domain_wikimediafoundation);
}
private static void Init_alias(String alias_str, byte domain) {
byte[] alias_bry = Bry_.new_a7(alias_str);
Int_obj_ref domain_bval = Int_obj_ref.new_(domain);
alias_bry_trie.Add(alias_bry, domain_bval);
alias_val_hash.Add(domain_bval, alias_bry);
}
private static void Init_tids() {
tid_bry_trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en
tid_val_hash = Hash_adp_.new_();
Init_tid(Key_pages_articles , Tid_pages_articles);
Init_tid(Key_pages_meta_current , Tid_pages_meta_current);
Init_tid(Key_categorylinks , Tid_categorylinks);
Init_tid(Key_page_props , Tid_page_props);
Init_tid(Key_image , Tid_image);
}
public static String Tid_to_str(byte v) {
switch (v) {
case Tid_pages_articles : return Key_pages_articles;
case Tid_pages_meta_current : return Key_pages_meta_current;
case Tid_categorylinks : return Key_categorylinks;
case Tid_page_props : return Key_page_props;
case Tid_image : return Key_image;
default : throw Err_.new_unhandled(v);
}
}
private static void Init_tid(String tid_str, byte tid) {
byte[] tid_bry = Bry_.new_a7(tid_str);
Byte_obj_ref tid_val = Byte_obj_ref.new_(tid);
tid_bry_trie.Add_obj(tid_bry, tid_val);
tid_val_hash.Add(tid_val, tid_bry);
}
private static Hash_adp alias_val_hash;
private static Btrie_bwd_mgr alias_bry_trie;
private static Hash_adp tid_val_hash;
private static Btrie_slim_mgr tid_bry_trie;
}

View File

@@ -1,97 +0,0 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.wikis.*;
public class Xow_wiki_alias_tst {
Xow_wiki_alias_fxt fxt = new Xow_wiki_alias_fxt();
@Test public void Parse() {fxt.Parse("enwiki-20121201-pages-articles.xml.bz2", "en.wikipedia.org", "20121201", Xow_wiki_alias.Tid_pages_articles);}
@Test public void Parse__domain_name() {
fxt.Parse__domain_name("foundationwiki" , "wikimediafoundation.org");
fxt.Parse__domain_name("wikidatawiki" , "www.wikidata.org");
fxt.Parse__domain_name("mediawikiwiki" , "www.mediawiki.org");
fxt.Parse__domain_name("commonswiki" , "commons.wikimedia.org");
fxt.Parse__domain_name("specieswiki" , "species.wikimedia.org");
fxt.Parse__domain_name("metawiki" , "meta.wikimedia.org");
fxt.Parse__domain_name("incubatorwiki" , "incubator.wikimedia.org");
fxt.Parse__domain_name("enwiki" , "en.wikipedia.org");
fxt.Parse__domain_name("enwiktionary" , "en.wiktionary.org");
fxt.Parse__domain_name("enwikisource" , "en.wikisource.org");
fxt.Parse__domain_name("enwikibooks" , "en.wikibooks.org");
fxt.Parse__domain_name("enwikiversity" , "en.wikiversity.org");
fxt.Parse__domain_name("enwikiquote" , "en.wikiquote.org");
fxt.Parse__domain_name("enwikinews" , "en.wikinews.org");
fxt.Parse__domain_name("enwikivoyage" , "en.wikivoyage.org");
fxt.Parse__domain_name("plwikimedia" , "pl.wikimedia.org");
}
@Test public void Parse__tid() {
fxt.Parse__tid("pages-articles.xml" , Xow_wiki_alias.Tid_pages_articles);
fxt.Parse__tid("pages-meta-current.xml" , Xow_wiki_alias.Tid_pages_meta_current);
}
@Test public void Build_alias() {
fxt.Build_alias("simple.wikipedia.org", "simplewiki");
fxt.Build_alias("en.wikipedia.org", "enwiki");
fxt.Build_alias("commons.wikimedia.org", "commonswiki");
}
@Test public void Build_wmf_src_dir() {
fxt.Build_wmf_src_dir("simplewiki", "latest", "http://dumps.wikimedia.your.org/simplewiki/latest/");
}
@Test public void Build_wmf_src_name() {
fxt.Build_wmf_src_name("simplewiki", "latest", Xow_wiki_alias.Key_pages_articles, "simplewiki-latest-pages-articles.xml.bz2");
}
@Test public void Build_alias_by_lang_tid() {
fxt.Build_alias_by_lang_tid("en", Xow_domain_type_.Tid_wikipedia, "enwiki");
}
@Test public void Parse_by_wmf_key() {
fxt.Test_parse_by_wmf_key("enwiki", "en", "en.wikipedia.org");
fxt.Test_parse_by_wmf_key("zh_yuewiki", "zh-yue", "zh-yue.wikipedia.org");
}
}
class Xow_wiki_alias_fxt {
Xow_wiki_alias file = new Xow_wiki_alias();
public void Parse(String name, String domain, String date, byte tid) {
Io_url fil = Io_url_.mem_fil_("mem/xowa/temp/" + name);
file.Fil_(fil).Parse(fil.NameOnly());
Tfds.Eq(domain , String_.new_a7(file.Domain()));
Tfds.Eq(date , file.Date());
Tfds.Eq(tid , file.Tid());
}
public void Parse__domain_name(String raw_str, String expd) {byte[] raw = Bry_.new_a7(raw_str); Tfds.Eq(expd, String_.new_a7(Xow_wiki_alias.Parse__domain_name(raw, 0, raw.length)));}
public void Parse__tid(String raw_str, byte expd) {Tfds.Eq(expd, Xow_wiki_alias.Parse__tid(raw_str));}
public void Build_alias(String domain_str, String expd) {
Xow_domain domain = Xow_domain_.parse(Bry_.new_a7(domain_str));
byte[] actl = Xow_wiki_alias.Build_alias(domain);
Tfds.Eq(expd, String_.new_a7(actl));
} private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public void Build_wmf_src_dir(String alias, String date, String expd) {
byte[] actl = Xob_dump_file_.Bld_dump_dir_url(Bry_.new_a7(Xob_dump_file_.Server_your_org), Bry_.new_a7(alias), Bry_.new_a7(date));
Tfds.Eq(expd, String_.new_a7(actl));
}
public void Build_wmf_src_name(String alias, String date, String dump_type, String expd) {
byte[] actl = Xob_dump_file_.Bld_dump_file_name(Bry_.new_a7(alias), Bry_.new_a7(date), Bry_.new_a7(dump_type), Xob_dump_file_.Ext_xml_bz2);
Tfds.Eq(expd, String_.new_a7(actl));
}
public void Build_alias_by_lang_tid(String lang_key, int wiki_tid, String expd) {
Xow_wiki_alias.Build_alias_by_lang_tid(tmp_bfr, Bry_.new_a7(lang_key), wiki_tid_ref.Val_(wiki_tid));
Tfds.Eq_bry(Bry_.new_u8(expd), tmp_bfr.Xto_bry_and_clear());
} static final Int_obj_ref wiki_tid_ref = Int_obj_ref.zero_();
public void Test_parse_by_wmf_key(String wmf_key, String expd_lang_key, String expd_domain) {
Xow_domain domain = Xow_wiki_alias.parse_by_wmf_key(Bry_.new_a7(wmf_key));
Tfds.Eq(expd_lang_key , String_.new_a7(domain.Lang_key()));
Tfds.Eq(expd_domain , String_.new_a7(domain.Domain_bry()));
}
}

View File

@@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*;
import gplx.xowa.dbs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.*; import gplx.xowa.bldrs.infos.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
public class Xowd_db_mgr {
private Xowd_db_file[] dbs__ary = new Xowd_db_file[0]; private int dbs__ary_len = 0; private final Xowd_db_file_hash db_file_hash = new Xowd_db_file_hash();
private final Xow_wiki wiki; private final Io_url wiki_root_dir; private final Xow_domain domain_itm;
public Xowd_db_mgr(Xow_wiki wiki, Io_url wiki_root_dir, Xow_domain domain_itm) {this.wiki = wiki; this.wiki_root_dir = wiki_root_dir; this.domain_itm = domain_itm;}
private final Xow_wiki wiki; private final Io_url wiki_root_dir; private final Xow_domain_itm domain_itm;
public Xowd_db_mgr(Xow_wiki wiki, Io_url wiki_root_dir, Xow_domain_itm domain_itm) {this.wiki = wiki; this.wiki_root_dir = wiki_root_dir; this.domain_itm = domain_itm;}
public Xowd_core_db_props Props() {return props;} private Xowd_core_db_props props = Xowd_core_db_props.Test;
public Db_cfg_tbl Tbl__cfg() {return db__core.Tbl__cfg();}
public Xowd_page_tbl Tbl__page() {return db__core.Tbl__page();}

View File

@@ -15,16 +15,17 @@ 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; import gplx.*; import gplx.xowa.*;
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*;
public class Xow_wiki_abrv {
public Xol_lang_itm Lang_itm() {return lang_itm;} private Xol_lang_itm lang_itm;
public byte Domain_tid() {return domain_tid;} private byte domain_tid;
public void Ctor_by_parse(Xol_lang_itm lang_itm, byte domain_tid) {
this.lang_itm = lang_itm; this.domain_tid = domain_tid;
}
public void Clear() {
lang_itm = null;
domain_tid = Xow_wiki_abrv_.Tid_null;
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;
}

View 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());
}
}

View 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()));
}
}

View File

@@ -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_()
}
}

View File

@@ -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");
}
}

View 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);
}
}

View 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");
}

View 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());
}
}

View File

@@ -15,7 +15,7 @@ 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; import gplx.*; import gplx.xowa.*;
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;
@@ -23,9 +23,17 @@ public class Xow_domain_type {
}
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
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
;
}

View 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();
}
}

View File

@@ -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());
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}

View File

@@ -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);}
}

View File

@@ -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

View File

@@ -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);

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.net.*;
import gplx.xowa.langs.*;
import gplx.xowa.wikis.domains.*;
public class Xow_xwiki_itm implements gplx.CompareAble {
public Xow_xwiki_itm(byte[] key_bry, byte[] url_fmt, int lang_id, int domain_tid, byte[] domain_bry, byte[] domain_name) {
this.key_bry = key_bry; this.key_str = String_.new_u8(key_bry);
@@ -35,10 +36,10 @@ public class Xow_xwiki_itm implements gplx.CompareAble {
public byte[] Domain_name() {return domain_name;} private final byte[] domain_name; // EX: Wikimedia Commons
public boolean Offline() {return offline;} public Xow_xwiki_itm Offline_(boolean v) {offline = v; return this;} private boolean offline;
public int compareTo(Object obj) {Xow_xwiki_itm comp = (Xow_xwiki_itm)obj; return Bry_.Compare(key_bry, comp.key_bry);}
public boolean Type_is_xwiki_lang(int cur_lang_id) {
public boolean Type_is_xwiki_lang(byte[] cur_lang_key) {
return lang_id != Xol_lang_itm_.Id__unknown // valid lang code
&& domain_tid != Xow_domain_type_.Tid_commons // commons should never be considered an xwiki_lang; EX:[[commons:A]] PAGE:species:Scarabaeidae; DATE:2014-09-10
&& lang_id != cur_lang_id // lang is different than current; EX: [[en:A]] in en.wikipedia.org shouldn't link back to self
&& domain_tid != Xow_domain_type_.Int__commons // commons should never be considered an xwiki_lang; EX:[[commons:A]] PAGE:species:Scarabaeidae; DATE:2014-09-10
&& !Bry_.Eq(key_bry, cur_lang_key) // lang is different than current; EX: [[en:A]] in en.wikipedia.org shouldn't link back to self
&& Bry_.Len_gt_0(url_fmt) // url_fmt exists
;
}
@@ -50,9 +51,9 @@ public class Xow_xwiki_itm implements gplx.CompareAble {
byte[] gfs_url = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_gfs(bfr, mw_url); // EX: "//commons.wikimedia.org/wiki/Category:$1" -> "//commons.wikimedia.org/wiki/Category:~{0}"
url_parser.Parse(url, gfs_url, 0, gfs_url.length);
byte[] domain_bry = url.Segs__get_at_1st(); // extract "commons.wikimedia.org"
Xow_domain domain = Xow_domain_.parse(domain_bry);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_key());
Xow_domain_itm domain = Xow_domain_itm_.parse(domain_bry);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_actl_key());
int lang_id = lang_itm == null ? Xol_lang_itm_.Id__unknown : lang_itm.Id();
return new Xow_xwiki_itm(key, gfs_url, lang_id, domain.Domain_tid(), domain_bry, domain_name);
return new Xow_xwiki_itm(key, gfs_url, lang_id, domain.Domain_type_id(), domain_bry, domain_name);
}
}

View File

@@ -16,12 +16,14 @@ 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.core.net.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.*;
import org.junit.*; import gplx.core.net.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.langs.*;
public class Xow_xwiki_itm_tst {
@Before public void init() {fxt.Clear();} private Xow_xwiki_itm_fxt fxt = new Xow_xwiki_itm_fxt();
@Test public void Commons() {fxt.Test_new_by_mw("commons.wikimedia.org/wiki/$1" , "commons.wikimedia.org" , "commons.wikimedia.org/wiki/~{0}" , Xow_domain_type_.Tid_commons , Xol_lang_itm_.Id__unknown);}
@Test public void Wiktionary() {fxt.Test_new_by_mw("fr.wiktionary.org/wiki/$1" , "fr.wiktionary.org" , "fr.wiktionary.org/wiki/~{0}" , Xow_domain_type_.Tid_wiktionary , Xol_lang_itm_.Id_fr);}
@Test public void Lang() {fxt.Test_new_by_mw("fr.wikipedia.org/wiki/$1" , "fr.wikipedia.org" , "fr.wikipedia.org/wiki/~{0}" , Xow_domain_type_.Tid_wikipedia , Xol_lang_itm_.Id_fr);}
@Test public void Commons() {fxt.Test_new_by_mw("commons.wikimedia.org/wiki/$1" , "commons.wikimedia.org" , "commons.wikimedia.org/wiki/~{0}" , Xow_domain_type_.Int__commons , Xol_lang_itm_.Id__unknown);}
@Test public void Wiktionary() {fxt.Test_new_by_mw("fr.wiktionary.org/wiki/$1" , "fr.wiktionary.org" , "fr.wiktionary.org/wiki/~{0}" , Xow_domain_type_.Int__wiktionary , Xol_lang_itm_.Id_fr);}
@Test public void Lang() {fxt.Test_new_by_mw("fr.wikipedia.org/wiki/$1" , "fr.wikipedia.org" , "fr.wikipedia.org/wiki/~{0}" , Xow_domain_type_.Int__wikipedia , Xol_lang_itm_.Id_fr);}
}
class Xow_xwiki_itm_fxt {
private Bry_bfr tmp_bfr;

View File

@@ -19,6 +19,7 @@ package gplx.xowa.wikis.xwikis; import gplx.*; import gplx.xowa.*; import gplx.x
import gplx.core.net.*;
import gplx.xowa.langs.*;
import gplx.xowa.html.hrefs.*;
import gplx.xowa.wikis.domains.*;
public class Xow_xwiki_mgr implements GfoInvkAble {
private Xowe_wiki wiki; private Xow_xwiki_mgr_srl srl;
private final Ordered_hash list = Ordered_hash_.new_bry_();
@@ -39,10 +40,10 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
public Xow_xwiki_itm Add_full(byte[] alias, byte[] domain_bry, byte[] url_fmt) {
int domain_tid = Byte_.Zero;
int lang_id = -1;
Xow_domain wiki_type = Xow_domain_.parse(domain_bry);
domain_tid = wiki_type.Domain_tid();
if (Bry_.Len_gt_0(wiki_type.Lang_key())) { // domain_bry has lang (EX: "en.")
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang_key());
Xow_domain_itm wiki_type = Xow_domain_itm_.parse(domain_bry);
domain_tid = wiki_type.Domain_type_id();
if (Bry_.Len_gt_0(wiki_type.Lang_actl_key())) { // domain_bry has lang (EX: "en.")
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang_actl_key());
if (lang_itm == null) return null; // unknown lang: do not add to wiki collection; EX: en1.wikipedia.org
lang_id = lang_itm.Id();
}
@@ -53,16 +54,16 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
public void Sort_by_key() {
list.Sort();
}
public Xow_domain[] Get_by_crt(Xow_domain cur, gplx.xowa.wikis.domains.crts.Xow_domain_crt_itm crt) {
public Xow_domain_itm[] Get_by_crt(Xow_domain_itm cur, gplx.xowa.wikis.domains.crts.Xow_domain_crt_itm crt) {
List_adp rv = List_adp_.new_();
int len = this.Len();
for (int i = 0; i < len; ++i) {
Xow_xwiki_itm wiki = this.Get_at(i);
if (!wiki.Offline()) continue;
Xow_domain domain_itm = Xow_domain_.parse(wiki.Domain_bry());
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(wiki.Domain_bry());
if (crt.Matches(cur, domain_itm)) rv.Add(domain_itm);
}
return (Xow_domain[])rv.To_ary_and_clear(Xow_domain.class);
return (Xow_domain_itm[])rv.To_ary_and_clear(Xow_domain_itm.class);
}
public void Add_bulk(byte[] raw) {
byte[][] rows = Bry_.Split(raw, Byte_ascii.Nl);
@@ -86,16 +87,16 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
default: throw Err_.new_unhandled(j);
}
}
Xow_domain domain = Xow_domain_.parse(domain_bry);
Xow_domain_itm domain = Xow_domain_itm_.parse(domain_bry);
int lang_id = Xol_lang_itm_.Id__unknown;
if (Bry_.Len_gt_0(domain.Lang_key())) {
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_key());
if (Bry_.Len_gt_0(domain.Lang_actl_key())) {
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_actl_key());
if (lang_itm != null // lang exists
&& Bry_.Eq(alias, lang_itm.Key())) // alias == lang.key; only assign langs to aliases that have lang key; EX: w|en.wikipedia.org; "w" alias should not be registered for "en"; DATE:2013-07-25
lang_id = lang_itm.Id();
}
byte[] url_fmt = Bry_.Add(Xoh_href_.Bry__https, domain_bry, Xoh_href_.Bry__wiki, Arg_0);
return Xow_xwiki_itm.new_(alias, url_fmt, lang_id, domain.Domain_tid(), domain_bry);
return Xow_xwiki_itm.new_(alias, url_fmt, lang_id, domain.Domain_type_id(), domain_bry);
} static final byte[] Arg_0 = Bry_.new_a7("~{0}");
String Exec_itms_print(byte[] raw) {
Bry_fmtr fmtr = Bry_fmtr.new_bry_(raw, "wiki_key");//, "wiki_type_url", "wiki_lang", "wiki_name", "wiki_logo_url");
@@ -105,7 +106,7 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
for (int i = 0; i < wikis_len; i++) {
Xow_xwiki_itm itm = (Xow_xwiki_itm)list.Get_at(i);
byte[] key = itm.Key_bry();
if (Bry_.Eq(key, Xow_domain_type_.Key_bry_home)) continue; // skip home
if (Bry_.Eq(key, Xow_domain_type_.Bry__home)) continue; // skip home
byte[] domain = itm.Domain_bry();
if (seen.Has(domain)) continue;
seen.Add_as_key_and_val(domain);
@@ -139,13 +140,13 @@ public class Xow_xwiki_mgr implements GfoInvkAble {
String domain_str = null;
int domain_tid = Xow_domain_type_.Get_type_as_tid(wiki_name_bry);
switch (domain_tid) {
case Xow_domain_type_.Tid_commons:
case Xow_domain_type_.Tid_species:
case Xow_domain_type_.Tid_meta:
case Xow_domain_type_.Tid_incubator: domain_str = String_.Format("{0}.wikimedia.org", wiki_name); break; // EX: commons.wikimedia.org
case Xow_domain_type_.Tid_wikidata: domain_str = String_.Format("www.wikidata.org", wiki_name); break; // EX: www.wikidata.org
case Xow_domain_type_.Tid_mediawiki: domain_str = String_.Format("www.mediawiki.org", wiki_name); break;
case Xow_domain_type_.Tid_wmfblog: domain_str = String_.Format("wikimediafoundation.org", wiki_name); break;
case Xow_domain_type_.Int__commons:
case Xow_domain_type_.Int__species:
case Xow_domain_type_.Int__meta:
case Xow_domain_type_.Int__incubator: domain_str = String_.Format("{0}.wikimedia.org", wiki_name); break; // EX: commons.wikimedia.org
case Xow_domain_type_.Int__wikidata: domain_str = String_.Format("www.wikidata.org", wiki_name); break; // EX: www.wikidata.org
case Xow_domain_type_.Int__mediawiki: domain_str = String_.Format("www.mediawiki.org", wiki_name); break;
case Xow_domain_type_.Int__wmfblog: domain_str = String_.Format("wikimediafoundation.org", wiki_name); break;
default: domain_str = String_.Format("{0}.{1}.org", lang_key_str, wiki_name); break; // EX: en.wiktionary.org
}
byte[] domain_bry = Bry_.new_u8(domain_str);

View File

@@ -16,20 +16,21 @@ 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.core.strings.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.*;
import org.junit.*; import gplx.core.strings.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.langs.*;
public class Xow_xwiki_mgr_tst {
@Before public void init() {fxt.Clear();} private Xow_xwiki_mgr_fxt fxt = new Xow_xwiki_mgr_fxt();
@Test public void Add_bulk_wiki_en() {fxt.Test_add_bulk("w|en.wikipedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_wikipedia , "w" , "https://en.wikipedia.org/wiki/~{0}", "en.wikipedia.org");}
@Test public void Add_bulk_wiki_fr() {fxt.Test_add_bulk("fr|fr.wikipedia.org" , Xol_lang_itm_.Id_fr , Xow_domain_type_.Tid_wikipedia , "fr" , "https://fr.wikipedia.org/wiki/~{0}", "fr.wikipedia.org");}
@Test public void Add_bulk_wikt_en() {fxt.Test_add_bulk("wikt|en.wiktionary.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_wiktionary , "wikt" , "https://en.wiktionary.org/wiki/~{0}", "en.wiktionary.org");}
@Test public void Add_bulk_commons() {fxt.Test_add_bulk("commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_commons , "commons" , "https://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
@Test public void Add_bulk_commons_cap() {fxt.Test_add_bulk("Commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_commons , "Commons" , "https://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
@Test public void Add_bulk_wiki_en() {fxt.Test_add_bulk("w|en.wikipedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Int__wikipedia , "w" , "https://en.wikipedia.org/wiki/~{0}", "en.wikipedia.org");}
@Test public void Add_bulk_wiki_fr() {fxt.Test_add_bulk("fr|fr.wikipedia.org" , Xol_lang_itm_.Id_fr , Xow_domain_type_.Int__wikipedia , "fr" , "https://fr.wikipedia.org/wiki/~{0}", "fr.wikipedia.org");}
@Test public void Add_bulk_wikt_en() {fxt.Test_add_bulk("wikt|en.wiktionary.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Int__wiktionary , "wikt" , "https://en.wiktionary.org/wiki/~{0}", "en.wiktionary.org");}
@Test public void Add_bulk_commons() {fxt.Test_add_bulk("commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Int__commons , "commons" , "https://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
@Test public void Add_bulk_commons_cap() {fxt.Test_add_bulk("Commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Int__commons , "Commons" , "https://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
@Test public void Add_bulk_langs_wiki() {fxt.Init_langs().Test_add_bulk_langs("wiki", fxt.xwiki_("en", "en.wikipedia.org", "http://en.wikipedia.org/wiki/~{0}"), fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
@Test public void Add_bulk_langs_grps() {fxt.Init_langs().Test_add_bulk_langs("europe_west~asia_east", fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
@Test public void Add_bulk_langs_grp_itm() {fxt.Init_langs().Test_add_bulk_langs("europe_west~ja", fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
@Test public void Add_bulk_langs_grp_commons() {
fxt.Init_langs();
fxt.Wiki().Xwiki_mgr().Add_bulk_langs(Bry_.new_a7("europe_west"), Xow_domain_type_.Tid_wikipedia);
fxt.Wiki().Xwiki_mgr().Add_bulk_langs(Bry_.new_a7("europe_west"), Xow_domain_type_.Int__wikipedia);
fxt.Tst_itms(fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"));
}
@Test public void Add_bulk_peers() {fxt.Init_peers().Test_add_bulk_peers("peer", fxt.xwiki_null_("commons"), fxt.xwiki_null_("m"), fxt.xwiki_("wikt", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("wiktionary", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("s", "en.wikisource.org", "http://en.wikisource.org/wiki/~{0}"));}
@@ -55,10 +56,10 @@ class Xow_xwiki_mgr_fxt {
lang_mgr.Clear();
}
public Xowe_wiki Wiki() {return wiki;}
public Xow_xwiki_itm xwiki_null_(String key) {return Xow_xwiki_itm.new_(Bry_.new_u8(key), Bry_.Empty, Xol_lang_itm_.Id__unknown, Xow_domain_type_.Tid_other, Bry_.Empty);}
public Xow_xwiki_itm xwiki_null_(String key) {return Xow_xwiki_itm.new_(Bry_.new_u8(key), Bry_.Empty, Xol_lang_itm_.Id__unknown, Xow_domain_type_.Int__other, Bry_.Empty);}
public Xow_xwiki_itm xwiki_(String key, String domain_str, String url_fmt) {
Xow_domain domain = Xow_domain_.parse(Bry_.new_u8(domain_str));
return Xow_xwiki_itm.new_(Bry_.new_u8(key), Bry_.new_u8(url_fmt), domain.Lang_itm().Id(), domain.Domain_tid(), domain.Domain_bry());
Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
return Xow_xwiki_itm.new_(Bry_.new_u8(key), Bry_.new_u8(url_fmt), domain.Lang_actl_itm().Id(), domain.Domain_type_id(), domain.Domain_bry());
}
public Xow_xwiki_mgr_fxt Test_add_bulk(String raw, int lang_tid, int wiki_tid, String alias, String fmt, String domain) {
Xow_xwiki_itm itm = xwiki_mgr.Add_bulk_row(Xol_lang_itm_.Regy(), Bry_.new_a7(raw));