1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.8.1.1'

This commit is contained in:
gnosygnu
2016-07-31 21:41:19 -04:00
parent 8e91ac0bc4
commit b0fdf78a41
388 changed files with 3517 additions and 2553 deletions

View File

@@ -0,0 +1,71 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Wbase_doc_mgr {
private final Xoae_app app;
private final Wdata_wiki_mgr wbase_mgr;
private final Wbase_qid_mgr qid_mgr;
private final gplx.xowa.apps.caches.Wdata_doc_cache hash;
public Wbase_doc_mgr(Xoae_app app, Wdata_wiki_mgr wbase_mgr, Wbase_qid_mgr qid_mgr) {
this.app = app; this.wbase_mgr = wbase_mgr; this.qid_mgr = qid_mgr;
this.hash = app.Cache_mgr().Doc_cache();
}
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
public void Clear() {
synchronized (hash) { // LOCK:app-level
hash.Clear();
}
}
public void Add(byte[] full_db, Wdata_doc page) { // TEST:
synchronized (hash) { // LOCK:app-level
if (hash.Get_or_null(full_db) == null)
hash.Add(full_db, page);
}
}
public Wdata_doc Get_by_ttl_or_null(Xowe_wiki wiki, Xoa_ttl ttl) {
byte[] qid_bry = qid_mgr.Get_or_null(wiki, ttl); // EX: "enwiki","Earth" -> "Q2"
return qid_bry == null ? null : this.Get_by_bry_or_null(qid_bry);
}
public Wdata_doc Get_by_xid_or_null(byte[] xid) {return Get_by_bry_or_null(Prepend_property_if_needed(xid));}// scribunto passes either p1 or q1; convert p1 to "Property:P1"
public Wdata_doc Get_by_bry_or_null(byte[] full_db) { // must be correct format; EX:"Q2" or "Property:P1"
Wdata_doc rv = hash.Get_or_null(full_db);
if (rv == null) {
byte[] page_src = Load_or_null(full_db); if (page_src == null) return null; // page not found
synchronized (hash) { // LOCK:app-level; both hash and jdoc_parser
rv = new Wdata_doc(full_db, wbase_mgr, wbase_mgr.Jdoc_parser().Parse(page_src));
}
Add(full_db, rv);
}
return rv;
}
private byte[] Load_or_null(byte[] full_db) {
if (!enabled) return null;
Xoa_ttl page_ttl = Xoa_ttl.Parse(wbase_mgr.Wdata_wiki(), full_db); if (page_ttl == null) {app.Usr_dlg().Warn_many("", "", "invalid qid for ttl: qid=~{0}", full_db); return null;}
Xoae_page page_itm = wbase_mgr.Wdata_wiki().Data_mgr().Load_page_by_ttl(page_ttl);
return page_itm.Db().Page().Exists() ? page_itm.Db().Text().Text_bry() : null;
}
private static byte[] Prepend_property_if_needed(byte[] bry) {
int len = bry == null ? 0 : bry.length;
return len > 1
&& Byte_ascii.Case_lower(bry[0]) == Byte_ascii.Ltr_p
&& Byte_ascii.Is_num(bry[1])
? Bry_.Add(Wdata_wiki_mgr.Ns_property_name_bry, Byte_ascii.Colon_bry, bry) // if ttl starts with "p#", prepend "Property:" to get "Property:P#"; NOTE: do not ucase P b/c it breaks a test; DATE:2014-02-18
: bry;
}
}

View File

@@ -0,0 +1,55 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Wbase_pid_mgr { // EX: "en|road_map" -> 15 ("Property:P15")
private final Wdata_wiki_mgr wbase_mgr;
private final Hash_adp_bry hash = Hash_adp_bry.cs();
public Wbase_pid_mgr(Wdata_wiki_mgr wbase_mgr) {this.wbase_mgr = wbase_mgr;}
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
public void Clear() {
synchronized (hash) { // LOCK:app-level
hash.Clear();
}
}
public void Add(byte[] pid_key, int pid_id) {
synchronized (hash) { // LOCK:app-level
if (!hash.Has(pid_key))
hash.Add_bry_int(pid_key, pid_id);
}
}
public int Get_or_null(byte[] lang_key, byte[] pid_name) {
if (!enabled) return Wdata_wiki_mgr.Pid_null;
byte[] pid_key = Bry_.Add(lang_key, Byte_ascii.Pipe_bry, pid_name); // EX: "en|road_map"
int rv = hash.Get_as_int_or(pid_key, -1);
if (rv == -1) {
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_pid(lang_key, pid_name); if (rv == Wdata_wiki_mgr.Pid_null) return rv;
Add(pid_key, rv);
}
return rv;
}
public static int To_int_or_null(byte[] pid_ttl) { // EX: "p123" -> "123"
int len = pid_ttl.length; if (len == 0) return Wdata_wiki_mgr.Pid_null;
byte ltr_p = pid_ttl[0]; // make sure 1st char is "P" or "p"
switch (ltr_p) {
case Byte_ascii.Ltr_P:
case Byte_ascii.Ltr_p: break;
default: return Wdata_wiki_mgr.Pid_null;
}
return Bry_.To_int_or(pid_ttl, 1, len, Wdata_wiki_mgr.Pid_null);
}
}

View File

@@ -0,0 +1,57 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.domains.*;
public class Wbase_qid_mgr {// EX: "enwiki|0|Earth" -> "Q2"
private final Wdata_wiki_mgr wbase_mgr;
private final Hash_adp_bry hash = Hash_adp_bry.cs();
private final gplx.core.primitives.Int_obj_ref tmp_wiki_tid = gplx.core.primitives.Int_obj_ref.New_zero(); // NOTE: return value is not checked; only used for function signature
public Wbase_qid_mgr(Wdata_wiki_mgr wbase_mgr) {
this.wbase_mgr = wbase_mgr;
}
public void Enabled_(boolean v) {this.enabled = v;} private boolean enabled;
public void Clear() {
synchronized (hash) { // LOCK:app-level
hash.Clear();
}
}
public void Add(Bry_bfr bfr, byte[] lang_key, int wiki_tid, byte[] ns_num, byte[] ttl, byte[] qid) { // TEST:
Xow_abrv_wm_.To_abrv(bfr, lang_key, tmp_wiki_tid.Val_(wiki_tid));
byte[] qids_key = bfr.Add_byte(Byte_ascii.Pipe).Add(ns_num).Add_byte(Byte_ascii.Pipe).Add(ttl).To_bry();
this.Add(qids_key, qid);
}
public byte[] Get_or_null(Xowe_wiki wiki, Xoa_ttl ttl) {return Get_or_null(wiki.Wdata_wiki_abrv(), ttl);}
public byte[] Get_or_null(byte[] wiki_abrv, Xoa_ttl ttl) {
if (!enabled) return null;
if (Bry_.Len_eq_0(wiki_abrv)) return null; // "other" wikis will never call wikidata
byte[] key = Bry_.Add(wiki_abrv, Byte_ascii.Pipe_bry, ttl.Ns().Num_bry(), Byte_ascii.Pipe_bry, ttl.Page_db()); // EX: "enwiki|014|Earth"
byte[] rv = (byte[])hash.Get_by(key);
if (rv == null) { // not in cache; load from db
rv = wbase_mgr.Wdata_wiki().Db_mgr().Load_mgr().Load_qid(wiki_abrv, ttl.Ns().Num_bry(), ttl.Page_db());
byte[] val_for_hash = rv == null ? Bry_.Empty : rv; // JAVA: hashtable does not accept null as value; use Bry_.Empty
this.Add(key, val_for_hash); // NOTE: if not in db, will insert Bry_.Empty; DATE:2014-07-23
}
return Bry_.Len_eq_0(rv) ? null : rv; // JAVA: convert Bry_.Empty to null which is what callers expect
}
private void Add(byte[] key, byte[] val) {
synchronized (hash) { // LOCK:app-level
if (!hash.Has(key))
hash.Add(key, val);
}
}
}

View File

@@ -0,0 +1,69 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*;
import gplx.langs.jsons.*;
import gplx.xowa.langs.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.parsers.*;
public class Wdata_doc {
private Wdata_wiki_mgr mgr; private Int_obj_ref tmp_key;
public Wdata_doc(byte[] qid, Wdata_wiki_mgr mgr, Json_doc jdoc) {this.qid = qid; this.mgr = mgr; this.jdoc = jdoc;}
public Wdata_doc(byte[] qid, Ordered_hash slink_list, Ordered_hash label_list, Ordered_hash descr_list, Ordered_hash alias_list, Ordered_hash claim_list) { // TEST
this.qid = qid;
this.slink_list = slink_list; this.label_list = label_list; this.descr_list = descr_list; this.alias_list = alias_list; this.claim_list = claim_list;
}
public Json_doc Jdoc() {return jdoc;} private Json_doc jdoc;
public byte[] Qid() {return qid;} private byte[] qid;
public byte[][] Sort_langs() {return sort_langs;} public void Sort_langs_(byte[][] v) {sort_langs = v;} private byte[][] sort_langs = Bry_.Ary_empty;
public Ordered_hash Slink_list() {if (slink_list == null) slink_list = mgr.Wdoc_parser(jdoc).Parse_sitelinks(qid, jdoc); return slink_list;} private Ordered_hash slink_list;
public Ordered_hash Label_list() {if (label_list == null) label_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.Y); return label_list;} private Ordered_hash label_list;
public Ordered_hash Descr_list() {if (descr_list == null) descr_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return descr_list;} private Ordered_hash descr_list;
public Ordered_hash Alias_list() {if (alias_list == null) alias_list = mgr.Wdoc_parser(jdoc).Parse_aliases(qid, jdoc); return alias_list;} private Ordered_hash alias_list;
public Ordered_hash Claim_list() {if (claim_list == null) claim_list = mgr.Wdoc_parser(jdoc).Parse_claims(qid, jdoc); return claim_list;} private Ordered_hash claim_list;
public Wbase_claim_grp Claim_list_get(int pid) {
if (tmp_key == null) tmp_key = Int_obj_ref.New_neg1();
Object o = this.Claim_list().Get_by(tmp_key.Val_(pid));
return (Wbase_claim_grp)o;
}
public byte[] Label_list__get(byte[] lang_key) {return Lang_text_list__get(this.Label_list(), lang_key);}
public byte[] Label_list__get_or_fallback(Xol_lang_itm lang) {return Lang_text_list__get_or_fallback(this.Label_list(), lang);}
public byte[] Descr_list__get_or_fallback(Xol_lang_itm lang) {return Lang_text_list__get_or_fallback(this.Descr_list(), lang);}
public byte[] Slink_list__get_or_fallback(byte[] abrv_wm) {
Wdata_sitelink_itm rv = (Wdata_sitelink_itm)this.Slink_list().Get_by(abrv_wm);
return rv == null ? null : rv.Name();
}
private byte[] Lang_text_list__get(Ordered_hash hash, byte[] lang_key) {
Object rv_obj = hash.Get_by(lang_key); if (rv_obj == null) return null;
Wdata_langtext_itm rv = (Wdata_langtext_itm)rv_obj;
return rv.Text();
}
public byte[] Lang_text_list__get_or_fallback(Ordered_hash lang_text_list, Xol_lang_itm lang) {
byte[] rv = Lang_text_list__get(lang_text_list, lang.Key_bry()); if (rv != null) return rv;
byte[][] ary = lang.Fallback_bry_ary(); // NOTE: en is currently automatically being added by Xol_lang_itm
int len = ary.length;
for (int i = 0; i < len; ++i) {
byte[] lang_key = ary[i];
Object itm_obj = lang_text_list.Get_by(lang_key);
if (itm_obj != null) {
Wdata_langtext_itm itm = (Wdata_langtext_itm)itm_obj;
return itm.Text();
}
}
return null;
}
}

View File

@@ -0,0 +1,49 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*;
import gplx.langs.jsons.*;
import gplx.xowa.xtns.wbases.core.*;
import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*;
public class Wdata_doc_bldr {
private Ordered_hash descr_list, label_list, slink_list, alias_list, claim_list;
public Wdata_doc_bldr() {this.Init();}
public Wdata_doc_bldr Qid_(String v) {this.qid = Bry_.new_a7(v); return this;} private byte[] qid;
public Wdata_doc_bldr Add_claims(Wbase_claim_base... ary) {
if (ary.length == 0) throw Err_.new_wo_type("claims must be greater than 0");
Wbase_claim_base itm = ary[0];
Wbase_claim_grp grp = new Wbase_claim_grp(Int_obj_ref.New(itm.Pid()), ary);
claim_list.Add(grp.Id_ref(), grp);
return this;
}
public Wdata_doc_bldr Add_description(String lang, String text) {byte[] key = Bry_.new_u8(lang); descr_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_u8(text))); return this;}
public Wdata_doc_bldr Add_label(String lang, String text) {byte[] key = Bry_.new_u8(lang); label_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_u8(text))); return this;}
public Wdata_doc_bldr Add_sitelink(String site, String link, String... bdgs) {
byte[] key = Bry_.new_u8(site); slink_list.Add(key, new Wdata_sitelink_itm(key, Bry_.new_u8(link), Bry_.Ary(bdgs)));
return this;
}
public Wdata_doc_bldr Add_alias(String lang, String... ary){byte[] key = Bry_.new_u8(lang); alias_list.Add(key, new Wdata_alias_itm (key, Bry_.Ary(ary))); return this;}
public Wdata_doc Xto_wdoc() {
Wdata_doc rv = new Wdata_doc(qid, slink_list, label_list, descr_list, alias_list, claim_list);
this.Init();
return rv;
}
private void Init() {
descr_list = Ordered_hash_.New_bry(); label_list = Ordered_hash_.New_bry(); slink_list = Ordered_hash_.New_bry(); alias_list = Ordered_hash_.New_bry(); claim_list = Ordered_hash_.New();
}
}

View File

@@ -0,0 +1,172 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.jsons.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*;
public class Wdata_doc_wtr {
private Json_doc_wtr wtr = new Json_doc_wtr();
public byte[] Xto_bry(Wdata_doc wdoc) {
wtr.Nde_bgn();
wtr.Kv(Bool_.N, Wdata_doc_parser_v1.Bry_entity, wdoc.Qid());
Xto_bry__list(Wdata_doc_parser_v1.Bry_label, wdoc.Label_list());
Xto_bry__list(Wdata_doc_parser_v1.Bry_description, wdoc.Descr_list());
Xto_bry__sitelinks(Wdata_doc_parser_v1.Bry_links, wdoc.Slink_list());
Xto_bry__aliases(wdoc.Alias_list());
Xto_bry__claims(wdoc.Qid(), wdoc.Claim_list());
wtr.Nde_end();
return wtr.Bld();
}
private void Xto_bry__list(byte[] key, Ordered_hash list) {
int len = list.Count();
if (len == 0) return;
wtr.Key(true, key);
wtr.Nde_bgn();
for (int i = 0; i < len; i++) {
Keyval kv = (Keyval)list.Get_at(i);
wtr.Kv(i != 0, Bry_.new_u8(kv.Key()), Bry_.new_u8(kv.Val_to_str_or_empty()));
}
wtr.Nde_end();
list.Clear();
}
private void Xto_bry__sitelinks(byte[] key, Ordered_hash list) { // NOTE: changed to reflect new sitelinks structure; DATE:2014-02-04
int len = list.Count();
if (len == 0) return;
wtr.Key(true, key);
wtr.Nde_bgn();
for (int i = 0; i < len; i++) {
if (i != 0) wtr.Comma();
Keyval kv = (Keyval)list.Get_at(i);
wtr.Key(false, Bry_.new_u8(kv.Key())); // write key; EX: enwiki:
wtr.Nde_bgn(); // bgn nde; EX: {
wtr.Kv(false, Wdata_doc_parser_v1.Bry_name, Bry_.new_u8(kv.Val_to_str_or_empty())); // write name; EX: name=Earth
wtr.Nde_end(); // end nde; EX: }
}
wtr.Nde_end();
list.Clear();
}
private void Xto_bry__aliases(Ordered_hash aliases) {
int len = aliases.Count();
if (len == 0) return;
wtr.Key(true, Wdata_doc_parser_v1.Bry_aliases);
wtr.Nde_bgn();
for (int i = 0; i < len; i++) {
Wdata_alias_itm alias = (Wdata_alias_itm)aliases.Get_at(i);
wtr.Key(i != 0, alias.Lang());
wtr.Ary_bgn();
byte[][] aliases_ary = alias.Vals();
int aliases_len = aliases_ary.length;
for (int j = 0; j < aliases_len; j++) {
byte[] aliases_itm = aliases_ary[j];
wtr.Val(j != 0, aliases_itm);
}
wtr.Ary_end();
}
wtr.Nde_end();
aliases.Clear();
}
private void Xto_bry__claims(byte[] qid, Ordered_hash props) {
int len = props.Count();
if (len == 0) return;
wtr.Key(true, Wdata_doc_parser_v1.Bry_claims);
wtr.Ary_bgn();
for (int i = 0; i < len; i++) {
if (i != 0) wtr.Comma();
Wbase_claim_base prop = (Wbase_claim_base)props.Get_at(i);
wtr.Nde_bgn();
wtr.Key(false, Wdata_dict_claim_v1.Bry_m);
wtr.Ary_bgn();
wtr.Val(Bool_.N, Wbase_claim_value_type_.To_bry_or_fail(prop.Snak_tid()));
wtr.Val(Bool_.Y, prop.Pid());
if (prop.Snak_tid() == Wbase_claim_value_type_.Tid__value) {
switch (prop.Val_tid()) {
case Wbase_claim_type_.Tid__string:
Wbase_claim_string claim_str = (Wbase_claim_string)prop;
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__string.Key_bry());
wtr.Val(Bool_.Y, claim_str.Val_str());
break;
case Wbase_claim_type_.Tid__entity:
Wbase_claim_entity claim_entity = (Wbase_claim_entity)prop;
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__entity.Key_bry());
wtr.Comma();
wtr.Nde_bgn();
wtr.Kv(Bool_.N, Wbase_claim_entity_.Itm__entity_type.Key_bry() , claim_entity.Entity_tid_bry());
wtr.Kv(Bool_.Y, Wbase_claim_entity_.Itm__numeric_id.Key_bry() , claim_entity.Entity_id());
wtr.Nde_end();
break;
case Wbase_claim_type_.Tid__time:
Wbase_claim_time claim_time = (Wbase_claim_time)prop;
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__time.Key_bry());
wtr.Comma();
wtr.Nde_bgn();
wtr.Kv(Bool_.N, Wbase_claim_time_.Itm__time.Key_bry() , claim_time.Time());
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__precision.Key_bry() , Wbase_claim_time_.Dflt__timezone.Val_bry());
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__before.Key_bry() , Wbase_claim_time_.Dflt__before.Val_bry());
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__after.Key_bry() , Wbase_claim_time_.Dflt__after.Val_bry());
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__timezone.Key_bry() , Wbase_claim_time_.Dflt__timezone.Val_bry());
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__calendarmodel.Key_bry() , Wbase_claim_time_.Dflt__calendarmodel.Val_bry());
wtr.Nde_end();
break;
case Wbase_claim_type_.Tid__globecoordinate: {
Wbase_claim_globecoordinate claim_globecoordinate = (Wbase_claim_globecoordinate)prop;
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__globecoordinate.Key_bry());
wtr.Comma();
wtr.Nde_bgn();
wtr.Kv_double (Bool_.N, Wbase_claim_globecoordinate_.Itm__latitude.Key_bry() , Double_.parse(String_.new_a7(claim_globecoordinate.Lat())));
wtr.Kv_double (Bool_.Y, Wbase_claim_globecoordinate_.Itm__longitude.Key_bry() , Double_.parse(String_.new_a7(claim_globecoordinate.Lng())));
wtr.Kv (Bool_.Y, Wbase_claim_globecoordinate_.Itm__altitude.Key_bry() , null);
wtr.Kv (Bool_.Y, Wbase_claim_globecoordinate_.Itm__globe.Key_bry() , Wbase_claim_globecoordinate_.Val_globe_dflt_bry);
wtr.Kv_double (Bool_.Y, Wbase_claim_globecoordinate_.Itm__precision.Key_bry() , .00001d);
wtr.Nde_end();
break;
}
case Wbase_claim_type_.Tid__quantity: {
Wbase_claim_quantity claim_quantity = (Wbase_claim_quantity)prop;
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__quantity.Key_bry());
wtr.Comma();
wtr.Nde_bgn();
wtr.Kv (Bool_.N, Wbase_claim_quantity_.Itm__amount.Key_bry() , claim_quantity.Amount()); // +1,234
wtr.Kv (Bool_.Y, Wbase_claim_quantity_.Itm__unit.Key_bry() , claim_quantity.Unit()); // 1
wtr.Kv (Bool_.Y, Wbase_claim_quantity_.Itm__upperbound.Key_bry() , claim_quantity.Ubound()); // +1,235
wtr.Kv (Bool_.Y, Wbase_claim_quantity_.Itm__lowerbound.Key_bry() , claim_quantity.Lbound()); // +1,233
wtr.Nde_end();
break;
}
case Wbase_claim_type_.Tid__monolingualtext: {
Wbase_claim_monolingualtext claim_monolingualtext = (Wbase_claim_monolingualtext)prop;
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__monolingualtext.Key_bry());
wtr.Comma();
wtr.Nde_bgn();
wtr.Kv (Bool_.N, Wbase_claim_monolingualtext_.Itm__text.Key_bry() , claim_monolingualtext.Text()); // text
wtr.Kv (Bool_.Y, Wbase_claim_monolingualtext_.Itm__language.Key_bry() , claim_monolingualtext.Lang()); // en
wtr.Nde_end();
break;
}
default: throw Err_.new_unhandled(prop.Val_tid());
}
}
wtr.Ary_end();
wtr.Kv_ary_empty(Bool_.Y, Wdata_dict_claim_v1.Bry_q);
wtr.Kv(Bool_.Y, Wdata_dict_claim_v1.Bry_g, qid);
wtr.Kv(Bool_.Y, Wdata_dict_claim_v1.Bry_rank, Wbase_claim_rank_.Tid__normal);
wtr.Kv_ary_empty(Bool_.Y, Wdata_dict_claim_v1.Bry_refs);
wtr.Nde_end();
}
wtr.Ary_end();
props.Clear();
}
}

View File

@@ -0,0 +1,61 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.langs.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.hwtrs.*;
class Wdata_prop_val_visitor implements Wbase_claim_visitor {
private Wdata_wiki_mgr wdata_mgr; private Xoae_app app; private Bry_bfr bfr; private byte[] lang_key;
private final Bry_bfr tmp_time_bfr = Bry_bfr_.Reset(255); private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_();
private Wdata_hwtr_msgs msgs;
public Wdata_prop_val_visitor(Xoae_app app, Wdata_wiki_mgr wdata_mgr) {this.app = app; this.wdata_mgr = wdata_mgr;}
public void Init(Bry_bfr bfr, Wdata_hwtr_msgs msgs, byte[] lang_key) {
this.bfr = bfr; this.msgs = msgs; this.lang_key = lang_key;
}
public void Visit_str(Wbase_claim_string itm) {
bfr.Add(itm.Val_str());
}
public void Visit_time(Wbase_claim_time itm) {
itm.Write_to_bfr(bfr, tmp_time_bfr, tmp_time_fmtr, msgs, Bry_.Empty); // for now, don't bother passing ttl; only used for error msg; DATE:2015-08-03
}
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {bfr.Add(itm.Text());} // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28
public void Visit_entity(Wbase_claim_entity itm) {
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(itm.Page_ttl_db());
if (entity_doc == null) return; // NOTE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01
byte[] label = entity_doc.Label_list__get(lang_key);
if (label == null && !Bry_.Eq(lang_key, Xol_lang_itm_.Key_en)) // NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19
label = entity_doc.Label_list__get(Xol_lang_itm_.Key_en);
if (label != null) // if label is still not found, don't add null reference
bfr.Add(label);
}
public void Visit_quantity(Wbase_claim_quantity itm) {
byte[] amount_bry = itm.Amount();
long val = Bry_.To_long_or(amount_bry, Byte_ascii.Comma_bry, 0, amount_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
Xol_lang_itm lang = app.Lang_mgr().Get_by(lang_key);
bfr.Add(lang.Num_mgr().Format_num_by_long(val)); // amount; EX: 1,234
if (itm.Lbound_as_num().To_long() != val && itm.Ubound_as_num().To_long() != val) { // NOTE: do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
bfr.Add(Bry__quantity_margin_of_error); // symbol: EX: ±
bfr.Add(itm.Unit()); // unit; EX: 1
}
}
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
Wdata_prop_val_visitor_.Render__geo(bfr, itm.Lat(), itm.Lng());
}
public void Visit_system(Wbase_claim_value itm) {}
public static final byte[] Bry__quantity_margin_of_error = Bry_.new_u8("±");
}

View File

@@ -0,0 +1,151 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wbases.hwtrs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.commas.*;
import gplx.xowa.parsers.*;
public class Wdata_prop_val_visitor_ {
public static String Render_snaks(Xowe_wiki wiki, byte[] page_url, Keyval[] snaks) {
String rv = null;
int len = snaks.length;
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
try {
for (int i = 0; i < len; ++i) {
Keyval[] itm = (Keyval[])snaks[i].Val();
Render_snak(bfr, wiki, wiki.Lang(), page_url, itm, i, len);
}
wiki.Lang().Comma_wkr().Comma__end(bfr);
rv = bfr.To_str_and_clear();
} finally {bfr.Mkr_rls();}
return rv;
}
public static String Render_snak(Xowe_wiki wiki, byte[] page_url, Keyval[] props) {
String rv = null;
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
try {
Render_snak(bfr, wiki, wiki.Lang(), page_url, props, 0, 1);
rv = bfr.To_str_and_clear();
} finally {bfr.Mkr_rls();}
return rv;
}
private static void Render_snak(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang_itm lang, byte[] page_url, Keyval[] props, int sub_idx, int sub_len) {
Keyval[] datavalue_ary = (Keyval[])Scrib_kv_utl_.Get_sub_by_key_or_null(props, Wdata_dict_mainsnak.Str_datavalue);
// loop datavalue_ary to get tid, val_obj
byte tid = Byte_.Max_value_127;
Object val_obj = null;
int len = datavalue_ary.length;
for (int i = 0; i < len; ++i) {
String key = datavalue_ary[i].Key();
if (String_.Eq(key, Wdata_dict_datavalue.Str_type))
tid = Wbase_claim_type_.To_tid_or_unknown((String)datavalue_ary[i].Val());
else if (String_.Eq(key, Wdata_dict_datavalue.Str_value))
val_obj = datavalue_ary[i].Val();
}
// render val_obj based on tid
switch (tid) {
case Wbase_claim_type_.Tid__entity: throw Err_.new_unimplemented();
case Wbase_claim_type_.Tid__string: bfr.Add_str_u8((String)val_obj); break;
case Wbase_claim_type_.Tid__time: Render__time (bfr, wiki, page_url, (Keyval[])val_obj); break;
case Wbase_claim_type_.Tid__globecoordinate: Render__geo (bfr, lang, page_url, (Keyval[])val_obj); break;
case Wbase_claim_type_.Tid__quantity: Render__quantity (bfr, lang, page_url, (Keyval[])val_obj); break;
case Wbase_claim_type_.Tid__monolingualtext: Render__langtext (bfr, lang, (Keyval[])val_obj); break;
}
lang.Comma_wkr().Comma__itm(bfr, sub_idx, sub_len);
}
private static void Render__time(Bry_bfr bfr, Xowe_wiki wiki, byte[] page_url, Keyval[] kvs) {
Wbase_date date = null;
byte[] time = null;
int precision_int = 0, before_int = 0, after_int = 0;
boolean calendar_is_julian = true;
int len = kvs.length;
for (int i = 0; i < len; ++i) {
Keyval kv = kvs[i];
byte val_tid = Wbase_claim_time_.To_tid_or_invalid(page_url, kv.Key());
switch (val_tid) {
case Wbase_claim_time_.Tid__time: time = Bry_.new_u8((String)kv.Val()); break;
case Wbase_claim_time_.Tid__before: before_int = Int_.cast(kv.Val()); break;
case Wbase_claim_time_.Tid__after: after_int = Int_.cast(kv.Val()); break;
case Wbase_claim_time_.Tid__precision: precision_int = Int_.cast(kv.Val()); break;
case Wbase_claim_time_.Tid__calendarmodel: calendar_is_julian = Bry_.Eq(Bry_.new_u8((String)kv.Val()), Wbase_claim_time.Calendar_julian); break;
case Wbase_claim_time_.Tid__timezone: if (!String_.Eq((String)kv.Val(), "0")) throw Err_.new_unimplemented(); break;
}
}
Xow_parser_mgr parser_mgr = wiki.Parser_mgr();
date = Wbase_date.Parse(time, precision_int, before_int, after_int, calendar_is_julian);
Wbase_claim_time.Write_to_bfr(bfr, parser_mgr.Wbase__time__bfr(), parser_mgr.Wbase__time__fmtr()
, parser_mgr.Wbase__time__msgs(), page_url, Bry_.Empty, date, calendar_is_julian
);
}
private static void Render__quantity(Bry_bfr bfr, Xol_lang_itm lang, byte[] page_url, Keyval[] kvs) {
byte[] amount_bry = null, lbound_bry = null, ubound_bry = null, unit_bry = null;
int len = kvs.length;
for (int i = 0; i < len; ++i) {
Keyval kv = kvs[i];
byte val_tid = Wbase_claim_quantity_.To_tid_or_invalid(page_url, kv.Key());
byte[] val_bry = Bry_.new_u8((String)kv.Val());
switch (val_tid) {
case Wbase_claim_quantity_.Tid__amount: amount_bry = val_bry; break;
case Wbase_claim_quantity_.Tid__unit: unit_bry = val_bry; break;
case Wbase_claim_quantity_.Tid__lowerbound: lbound_bry = val_bry; break;
case Wbase_claim_quantity_.Tid__upperbound: ubound_bry = val_bry; break;
}
}
Render__quantity(bfr, lang, amount_bry, lbound_bry, ubound_bry, unit_bry);
}
private static void Render__quantity(Bry_bfr bfr, Xol_lang_itm lang, byte[] amount_bry, byte[] lbound_bry, byte[] ubound_bry, byte[] unit_bry) {
long val = Bry_.To_long_or(amount_bry, Byte_ascii.Comma_bry, 0, amount_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
bfr.Add(lang.Num_mgr().Format_num_by_long(val));// amount; EX: 1,234
long lbound = Bry_.To_long_or(lbound_bry, val);
long ubound = Bry_.To_long_or(lbound_bry, val);
if (lbound != val && ubound != val) { // NOTE: do not output <20> if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
bfr.Add(Wdata_prop_val_visitor.Bry__quantity_margin_of_error); // symbol: EX: <20>
bfr.Add(unit_bry); // unit; EX: 1
}
}
private static void Render__geo(Bry_bfr bfr, Xol_lang_itm lang, byte[] page_url, Keyval[] kvs) {
double lat = 0, lng = 0;
int len = kvs.length;
for (int i = 0; i < len; ++i) {
Keyval kv = kvs[i];
byte val_tid = Wbase_claim_globecoordinate_.To_tid_or_invalid(page_url, kv.Key());
switch (val_tid) {
case Wbase_claim_globecoordinate_.Tid__latitude: lat = Double_.cast(kv.Val()); break;
case Wbase_claim_globecoordinate_.Tid__longitude: lng = Double_.cast(kv.Val()); break;
default: break; // ignore others
}
}
Render__geo(bfr, lat, lng);
}
public static void Render__geo(Bry_bfr bfr, byte[] lat, byte[] lng) {
bfr.Add(lat);
bfr.Add(Bry__geo_dlm);
bfr.Add(lng);
}
public static void Render__geo(Bry_bfr bfr, double lat, double lng) {
bfr.Add_double(lat);
bfr.Add(Bry__geo_dlm);
bfr.Add_double(lng);
}
private static void Render__langtext(Bry_bfr bfr, Xol_lang_itm lang, Keyval[] kvs) {
bfr.Add_str_u8((String)Scrib_kv_utl_.Get_sub_by_key_or_null(kvs, Wbase_claim_monolingualtext_.Itm__text.Key_str()));
}
private static final byte[] Bry__geo_dlm = Bry_.new_a7(", ");
}

View File

@@ -0,0 +1,181 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*;
import gplx.langs.jsons.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.langs.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.htmls.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.apps.apis.xowa.xtns.*; import gplx.xowa.apps.apis.xowa.html.*; import gplx.xowa.users.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.pfuncs.*; import gplx.xowa.xtns.wbases.hwtrs.*;
import gplx.xowa.parsers.*;
public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
private final Xoae_app app;
private final Wdata_prop_val_visitor prop_val_visitor;
private final Wdata_doc_parser wdoc_parser_v1 = new Wdata_doc_parser_v1(), wdoc_parser_v2 = new Wdata_doc_parser_v2();
private Wdata_hwtr_mgr hwtr_mgr;
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32);
public Wdata_wiki_mgr(Xoae_app app) {
this.app = app;
this.evt_mgr = new Gfo_evt_mgr(this);
this.Qid_mgr = new Wbase_qid_mgr(this);
this.Pid_mgr = new Wbase_pid_mgr(this);
this.Doc_mgr = new Wbase_doc_mgr(app, this, this.Qid_mgr);
this.prop_val_visitor = new Wdata_prop_val_visitor(app, this);
this.Enabled_(true);
}
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private final Gfo_evt_mgr evt_mgr;
public final Wbase_qid_mgr Qid_mgr;
public final Wbase_pid_mgr Pid_mgr;
public final Wbase_doc_mgr Doc_mgr;
public boolean Enabled() {return enabled;} private boolean enabled;
public void Enabled_(boolean v) {
this.enabled = v;
Qid_mgr.Enabled_(v);
Pid_mgr.Enabled_(v);
Doc_mgr.Enabled_(v);
}
public byte[] Domain() {return domain;} public void Domain_(byte[] v) {domain = v;} private byte[] domain = Bry_.new_a7("www.wikidata.org");
public Xowe_wiki Wdata_wiki() {if (wdata_wiki == null) wdata_wiki = app.Wiki_mgr().Get_by_or_make(domain).Init_assert(); return wdata_wiki;} private Xowe_wiki wdata_wiki;
public Json_parser Jdoc_parser() {return jdoc_parser;} private Json_parser jdoc_parser = new Json_parser();
public void Init_by_app() {}
public Wdata_doc_parser Wdoc_parser(Json_doc jdoc) {
Json_kv itm_0 = Json_kv.cast(jdoc.Root_nde().Get_at(0)); // get 1st node
return Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_type)
|| Bry_.Eq(itm_0.Key().Data_bry(), Wdata_doc_parser_v2.Bry_id)
? wdoc_parser_v2 : wdoc_parser_v1; // if "type", must be v2
}
public Xop_log_property_wkr Property_wkr() {return property_wkr;} private Xop_log_property_wkr property_wkr;
public void Clear() {
synchronized (wdoc_parser_v2) { // LOCK:app-level
Qid_mgr.Clear();
Pid_mgr.Clear();
Doc_mgr.Clear();
}
}
public byte[] Get_claim_or(Xow_domain_itm domain, Xoa_ttl page_ttl, int pid, byte[] or) {
byte[] qid = this.Qid_mgr.Get_or_null(domain.Abrv_wm(), page_ttl); if (qid == null) return or;
Wdata_doc wdoc = Doc_mgr.Get_by_bry_or_null(qid); if (wdoc == null) return or;
Wbase_claim_grp claim_grp = wdoc.Claim_list_get(pid); if (claim_grp == null || claim_grp.Len() == 0) return or;
Wbase_claim_base claim_itm = claim_grp.Get_at(0);
synchronized (tmp_bfr) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
prop_val_visitor.Init(tmp_bfr, hwtr_mgr.Msgs(), domain.Lang_orig_key());
claim_itm.Welcome(prop_val_visitor);
return tmp_bfr.To_bry_and_clear();
}
}
public void Resolve_to_bfr(Bry_bfr bfr, Wbase_claim_grp prop_grp, byte[] lang_key) {
synchronized (this) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
Hwtr_mgr_assert();
int len = prop_grp.Len();
Wbase_claim_base selected = null;
for (int i = 0; i < len; i++) { // NOTE: multiple props possible; EX: {{#property:P1082}}; PAGE:en.w:Earth DATE:2015-08-02
Wbase_claim_base prop = prop_grp.Get_at(i);
if (selected == null) selected = prop; // if selected not set, set it; will always set to 1st prop
if (prop.Rank_tid() == Wbase_claim_rank_.Tid__preferred) { // if prop is preferred, select it and exit;
selected = prop;
break;
}
}
switch (selected.Snak_tid()) {
case Wbase_claim_value_type_.Tid__novalue : bfr.Add(Wbase_claim_value_type_.Itm__novalue.Key_bry()); break;
case Wbase_claim_value_type_.Tid__somevalue : bfr.Add(Wbase_claim_value_type_.Itm__somevalue.Key_bry()); break;
default: {
prop_val_visitor.Init(bfr, hwtr_mgr.Msgs(), lang_key);
selected.Welcome(prop_val_visitor);
break;
}
}
}
}
public byte[] Popup_text(Xoae_page page) {
Hwtr_mgr_assert();
Wdata_doc wdoc = Doc_mgr.Get_by_bry_or_null(page.Ttl().Full_db());
return hwtr_mgr.Popup(wdoc);
}
public void Write_json_as_html(Bry_bfr bfr, byte[] page_full_db, byte[] data_raw) {
Hwtr_mgr_assert();
Wdata_doc wdoc = Doc_mgr.Get_by_bry_or_null(page_full_db);
hwtr_mgr.Init_by_wdoc(wdoc);
bfr.Add(hwtr_mgr.Write(wdoc));
}
private void Hwtr_mgr_assert() {
if (hwtr_mgr != null) return;
Xoapi_toggle_mgr toggle_mgr = app.Api_root().Html().Page().Toggle_mgr();
Xoapi_wikibase wikibase_api = app.Api_root().Xtns().Wikibase();
hwtr_mgr = new Wdata_hwtr_mgr();
hwtr_mgr.Init_by_ctor(wikibase_api, new Wdata_lbl_wkr_wiki(wikibase_api, this), gplx.langs.htmls.encoders.Gfo_url_encoder_.Href, toggle_mgr, app.Usere().Wiki().Xwiki_mgr());
this.Hwtr_msgs_make();
Gfo_evt_mgr_.Sub_same_many(app.Usere(), this, Xoue_user.Evt_lang_changed);
}
private void Hwtr_msgs_make() {
if (!app.Wiki_mgr().Wiki_regy().Has(Xow_domain_itm_.Bry__wikidata)) return;
Xol_lang_itm new_lang = app.Usere().Lang();
Xowe_wiki cur_wiki = this.Wdata_wiki();
cur_wiki.Xtn_mgr().Xtn_wikibase().Load_msgs(cur_wiki, new_lang);
Wdata_hwtr_msgs hwtr_msgs = Wdata_hwtr_msgs.new_(cur_wiki.Msg_mgr());
hwtr_mgr.Init_by_lang(hwtr_msgs);
}
public static void Write_json_as_html(Json_parser jdoc_parser, Bry_bfr bfr, byte[] data_raw) {
bfr.Add(Xoh_consts.Span_bgn_open).Add(Xoh_consts.Id_atr).Add(Html_json_id).Add(Xoh_consts.__end_quote); // <span id="xowa-wikidata-json">
Json_doc json = jdoc_parser.Parse(data_raw);
json.Root_nde().Print_as_json(bfr, 0);
bfr.Add(Xoh_consts.Span_end);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.To_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
else if (ctx.Match(k, Invk_domain)) return String_.new_u8(domain);
else if (ctx.Match(k, Invk_domain_)) domain = m.ReadBry("v");
else if (ctx.Match(k, Invk_property_wkr)) return m.ReadYnOrY("v") ? Property_wkr_or_new() : Gfo_invk_.Noop;
else if (ctx.Match(k, Xoue_user.Evt_lang_changed)) Hwtr_msgs_make();
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_", Invk_domain = "domain", Invk_domain_ = "domain_", Invk_property_wkr = "property_wkr";
public Xop_log_property_wkr Property_wkr_or_new() {
if (property_wkr == null) property_wkr = app.Log_mgr().Make_wkr_property();
return property_wkr;
}
public static final int Ns_property = 120;
public static final String Ns_property_name = "Property";
public static final byte[] Ns_property_name_bry = Bry_.new_a7(Ns_property_name);
public static final byte[] Bry_q = Bry_.new_a7("q");
public static final byte[]
Ttl_prefix_qid_bry_db = Bry_.new_a7("q") // NOTE: for historical reasons this is standardized as lowercase q not Q; DATE:2015-06-12
, Ttl_prefix_qid_bry_gui = Bry_.new_a7("Q") // NOTE: use uppercase Q for writing html; DATE:2015-06-12
, Ttl_prefix_pid_bry = Bry_.new_a7("Property:P")
;
public static final int Pid_null = -1;
public static final byte[] Html_json_id = Bry_.new_a7("xowa-wikidata-json");
public static boolean Wiki_page_is_json(int wiki_tid, int ns_id) {
switch (wiki_tid) {
case Xow_domain_tid_.Int__wikidata:
if (ns_id == Xow_ns_.Tid__main || ns_id == gplx.xowa.xtns.wbases.Wdata_wiki_mgr.Ns_property)
return true;
break;
case Xow_domain_tid_.Int__home:
if (ns_id == gplx.xowa.xtns.wbases.Wdata_wiki_mgr.Ns_property)
return true;
break;
}
return false;
}
public static void Log_missing_qid(Xop_ctx ctx, byte[] qid) {
ctx.Wiki().Appe().Usr_dlg().Log_many("", "", "qid not found in wikidata; qid=~{0} page=~{1}", String_.new_u8(qid), String_.new_u8(ctx.Page().Ttl().Page_db()));
}
}

View File

@@ -0,0 +1,177 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*; import gplx.langs.jsons.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.guis.*; import gplx.xowa.xtns.wbases.imports.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.langs.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.pfuncs.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
public class Wdata_wiki_mgr_fxt {
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr();
private final Bry_bfr tmp_time_bfr = Bry_bfr_.New();
public Xowe_wiki Wiki() {return parser_fxt.Wiki();}
public Wdata_wiki_mgr_fxt Init() {return Init(new Xop_fxt(), true);}
public Wdata_wiki_mgr_fxt Init(Xop_fxt parser_fxt, boolean reset) {
this.parser_fxt = parser_fxt;
this.wiki = parser_fxt.Wiki();
app = wiki.Appe();
app.Xwiki_mgr__sitelink_mgr().Init_by_app();
wdoc_bldr = new Wdata_doc_bldr();
wdata_mgr = app.Wiki_mgr().Wdata_mgr();
wdata_mgr.Clear();
if (reset) {
Io_mgr.Instance.InitEngine_mem();
parser_fxt.Reset();
}
return this;
} private Xoae_app app; private Xowe_wiki wiki; private Wdata_wiki_mgr wdata_mgr; private Wdata_doc_bldr wdoc_bldr; private Xop_fxt parser_fxt;
public Xoae_app App() {return app;}
public void Init_lang_fallbacks(String... fallbacks) {
wiki.Lang().Fallback_bry_(Bry_.new_a7(String_.Concat_with_str(",", fallbacks)));
}
public Wdata_doc_bldr Wdoc_bldr(String qid) {return wdoc_bldr.Qid_(qid);}
public Json_doc Make_json(String src) {return app.Utl__json_parser().Parse_by_apos(src);}
public Wbase_claim_base Make_claim_novalue(int pid) {return Wbase_claim_value.New_novalue(pid);}
public Wbase_claim_base Make_claim_somevalue(int pid) {return Wbase_claim_value.New_somevalue(pid);}
public Wbase_claim_base Make_claim_string(int pid, String val) {return Make_claim_string(pid, Bry_.new_u8(val));}
public Wbase_claim_base Make_claim_string(int pid, byte[] val) {return new Wbase_claim_string(pid, Wbase_claim_value_type_.Tid__value, val);}
public Wbase_claim_base Make_claim_time(int pid, String val) {return Make_claim_time(pid, val, Bry_.Empty, Bry_.Empty);}
public Wbase_claim_base Make_claim_time(int pid, String val, int precision) {return Make_claim_time(pid, val, Int_.To_bry(precision), Bry_.Empty);}
public Wbase_claim_base Make_claim_time(int pid, String val, byte[] precision, byte[] calendar) {
return new Wbase_claim_time(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_time_.To_bry(tmp_time_bfr, val), Bry_.Empty, Bry_.Empty, Bry_.Empty, precision, calendar);
}
public Wbase_claim_base Make_claim_monolingual(int pid, String lang, String text) {return new Wbase_claim_monolingualtext(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_u8(lang), Bry_.new_u8(text));}
public Wbase_claim_base Make_claim_quantity(int pid, String amount, String unit, String ubound, String lbound) {return new Wbase_claim_quantity(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_a7(amount), Bry_.new_a7(unit), Bry_.new_a7(ubound), Bry_.new_a7(lbound));}
public Wbase_claim_base Make_claim_entity_qid(int pid, int val) {return new Wbase_claim_entity(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_entity_type_.Tid__item, Int_.To_bry(val));}
public Wbase_claim_base Make_claim_entity_pid(int pid, int val) {return new Wbase_claim_entity(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_entity_type_.Tid__property, Int_.To_bry(val));}
public Wbase_claim_base Make_claim_geo(int pid, String lon, String lat) {return Make_claim_geo(pid, lon, lat, ".00001", null, "http://www.wikidata.org/entity/Q2");}
public Wbase_claim_base Make_claim_geo(int pid, String lon, String lat, String prc, String alt, String glb) {
return new Wbase_claim_globecoordinate(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_a7(lat), Bry_.new_a7(lon), Bry_.new_a7(alt), Bry_.new_a7(prc), Bry_.new_a7(glb));
}
public Wbase_claim_grp Make_qualifiers_grp(int pid, Wbase_claim_base... ary) {return new Wbase_claim_grp(Int_obj_ref.New(pid), ary);}
public Wbase_claim_grp_list Make_qualifiers(Wbase_claim_grp... ary) {
Wbase_claim_grp_list rv = new Wbase_claim_grp_list();
int len = ary.length;
for (int i = 0; i < len; ++i)
rv.Add(ary[i]);
return rv;
}
public Wdata_doc doc_(String qid, Wbase_claim_base... props) {return wdoc_bldr.Qid_(qid).Add_claims(props).Xto_wdoc();}
public void Init_xwikis_add(String... prefixes) {
int len = prefixes.length;
for (int i = 0; i < len; i++) {
String prefix = prefixes[i];
wiki.Xwiki_mgr().Add_by_atrs(prefix, prefix + ".wikipedia.org");
}
}
public void Init_qids_add(String lang_key, int wiki_tid, String ttl, String qid) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
wdata_mgr.Qid_mgr.Add(tmp_bfr, Bry_.new_a7(lang_key), wiki_tid, Bry_.new_a7("000"), Bry_.new_a7(ttl), Bry_.new_a7(qid));
tmp_bfr.Mkr_rls();
}
public void Init_pids_add(String lang_key, String pid_name, int pid) {wdata_mgr.Pid_mgr.Add(Bry_.new_u8(lang_key + "|" + pid_name), pid);}
public void Init_links_add(String wiki, String ttl, String qid) {Init_links_add(wiki, "000", ttl, qid);}
public void Init_links_add(String wiki, String ns_num, String ttl, String qid) {
byte[] ttl_bry = Bry_.new_u8(ttl);
Xowd_regy_mgr regy_mgr = app.Hive_mgr().Regy_mgr();
Io_url regy_fil = wdata_mgr.Wdata_wiki().Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid").GenSubFil_nest(wiki, ns_num, "reg.csv");
regy_mgr.Init(regy_fil);
regy_mgr.Create(ttl_bry);
regy_mgr.Save();
Bry_bfr bfr = Bry_bfr_.New();
byte[] itm = bfr.Add(ttl_bry).Add_byte(Byte_ascii.Pipe).Add(Bry_.new_a7(qid)).Add_byte_nl().To_bry_and_clear();
Xob_xdat_file xdat_file = new Xob_xdat_file();
xdat_file.Insert(bfr, itm);
Io_url file_orig = Xob_wdata_qid_base_tst.ttl_(app.Wiki_mgr().Wdata_mgr().Wdata_wiki(), wiki, ns_num, 0);
xdat_file.Save(file_orig);
}
public void Init_external_links_mgr_clear() {wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links().Reset();}
public void Init_external_links_mgr_add(String... langs) {
Wdata_external_lang_links_data external_lang_links = wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links();
external_lang_links.Enabled_(true);
int len = langs.length;
for (int i = 0; i < len; i++) {
String lang = langs[i];
if (String_.Eq(lang, "*"))
external_lang_links.Sort_(true);
else
external_lang_links.Langs_add(Bry_.new_a7(lang));
}
}
public void Test_link(String ttl_str, String expd) {Test_link(Xoa_ttl.Parse(wiki, Xow_ns_.Tid__main, Bry_.new_u8(ttl_str)), expd);}
public void Test_link(Xoa_ttl ttl, String expd) {
byte[] qid_ttl = wdata_mgr.Qid_mgr.Get_or_null(wiki, ttl);
Tfds.Eq(expd, String_.new_u8(qid_ttl));
}
public void Test_parse_pid_null(String val) {Test_parse_pid(val, Wdata_wiki_mgr.Pid_null);}
public void Test_parse_pid(String val, int expd) {Tfds.Eq(expd, Wdata_pf_property.Parse_pid(num_parser, Bry_.new_a7(val)));} private Gfo_number_parser num_parser = new Gfo_number_parser();
public void Init__docs__add(Wdata_doc page) {wdata_mgr.Doc_mgr.Add(page.Qid(), page);}
public void Test_parse(String raw, String expd) {
parser_fxt.Test_parse_page_tmpl_str(raw, expd);
}
public void Test_parse_langs(String raw, String expd) {
// setup langs
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
app.Xwiki_mgr__sitelink_mgr().Parse(Bry_.new_u8(String_.Concat_lines_nl
( "0|grp1"
, "1|en|English"
, "1|fr|French"
, "1|de|German"
, "1|pl|Polish"
)));
wiki.Xwiki_mgr().Add_by_sitelink_mgr();
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_csv(Bry_.new_a7(String_.Concat_lines_nl
( "1|en.wikipedia.org|en.wikipedia.org"
, "1|fr.wikipedia.org|fr.wikipedia.org"
, "1|de.wikipedia.org|de.wikipedia.org"
, "1|pl.wikipedia.org|pl.wikipedia.org"
)));
parser_fxt.Page_ttl_("Q1_en");
parser_fxt.Exec_parse_page_all_as_str(raw);
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
wdata_lang_wtr.Page_(page).Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_rls());
}
public void Test_xwiki_links(String ttl, String... expd) {
tmp_langs.Clear();
Wdata_xwiki_link_wtr.Write_wdata_links(tmp_langs, wiki, Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl)), wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links());
Tfds.Eq_ary_str(expd, Test_xwiki_links_xto_str_ary(tmp_langs));
} List_adp tmp_langs = List_adp_.New();
String[] Test_xwiki_links_xto_str_ary(List_adp list) {
int len = list.Count();
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.Get_at(i);
rv[i] = String_.new_a7(itm.Page_ttl().Page_db());
}
tmp_langs.Clear();
return rv;
}
public void Test_write_json_as_html(String raw_str, String expd) {
byte[] raw_bry = Bry_.new_a7(raw_str);
raw_bry = gplx.langs.jsons.Json_parser_tst.Replace_apos(raw_bry);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
Wdata_wiki_mgr.Write_json_as_html(wdata_mgr.Jdoc_parser(), bfr, raw_bry);
Tfds.Eq(expd, bfr.To_str_and_rls());
}
}

View File

@@ -0,0 +1,57 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.xtns.wbases.imports.*;
public class Wdata_wiki_mgr_tst {
@Test public void Basic() {
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
fxt.Init_links_add("enwiki", "Q1", "Q1_en");
fxt.Test_link("Q1", "Q1_en");
fxt.Test_link("Q2", null);
}
@Test public void Case_sensitive() { // PURPOSE: wikidata lkp should be case_sensitive; a vs A DATE:2013-09-03
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
fxt.Init_links_add("enwiki", "Page", "Page_data");
fxt.Test_link("Page", "Page_data");
fxt.Test_link("PAGE", null);
}
@Test public void Non_canonical_ns() { // PURPOSE: handle wikidata entries in non-canonical ns; EX:ukwikisource and Author; PAGE:uk.s:Автор:Богдан_Гаврилишин DATE:2014-07-23
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
Xowe_wiki wiki = fxt.Wiki();
wiki.Ns_mgr().Add_new(124, "Test_ns");
fxt.Init_links_add("enwiki", "000", "Test_ns:Test_page", "pass"); // NOTE: wdata will save to "000" ns, b/c "124" ns is not canonical
Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), 124, Bry_.new_a7("Test_page"));
fxt.Test_link(ttl, "pass");
}
@Test public void Write_json_as_html() {
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
fxt.Test_write_json_as_html("{'a':'b','c':['d','e'],'f':{'g':'<h>'}}", String_.Concat_lines_nl_skip_last
( "<span id=\"xowa-wikidata-json\">"
, "{ \"a\":\"b\""
, ", \"c\":"
, " [ \"d\""
, " , \"e\""
, " ]"
, ", \"f\":"
, " { \"g\":\"&lt;h&gt;\""
, " }"
, "}"
, "</span>"
));
}
}

View File

@@ -0,0 +1,40 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.htmls.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.bldrs.*;
import gplx.xowa.wikis.*;
public class Wdata_xtn_mgr extends Xox_mgr_base {
private static final String XTN_KEY_STR = "Wikibase"; public static final byte[] XTN_KEY = Bry_.new_a7(XTN_KEY_STR);
@Override public boolean Enabled_default() {return false;}
@Override public byte[] Xtn_key() {return XTN_KEY;}
@Override public Xox_mgr Xtn_clone_new() {return new Wdata_xtn_mgr();}
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {
if (!Enabled()) return;
}
public void Load_msgs(Xowe_wiki wdata_wiki, Xol_lang_itm lang) {
wdata_wiki.Msg_mgr().Lang_(lang);
Xtn_load_i18n(wdata_wiki, XTN_KEY_STR, "lib" , "i18n", lang.Key_str() + ".json");
Xtn_load_i18n(wdata_wiki, XTN_KEY_STR, "repo", "i18n", lang.Key_str() + ".json");
}
private static void Xtn_load_i18n(Xowe_wiki wiki, String... nest_paths) {
Xoae_app app = wiki.Appe();
Io_url url = app.Fsys_mgr().Bin_xtns_dir().GenSubFil_nest(nest_paths);
Xob_i18n_parser.Load_msgs(false, wiki.Lang(), url);
}
}

View File

@@ -0,0 +1,81 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.jsons.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.pfuncs.*;
public class Wdata_xwiki_link_wtr implements gplx.core.brys.Bfr_arg {
public Wdata_xwiki_link_wtr Page_(Xoae_page page) {this.page = page; return this;} private Xoae_page page;
public void Bfr_arg__add(Bry_bfr bfr) {
List_adp slink_list = page.Slink_list();
Xoa_ttl page_ttl = page.Ttl();
byte[] qid = Write_wdata_links(slink_list, page.Wikie(), page_ttl, page.Wdata_external_lang_links());
if (!Bry_.Eq(qid, Qid_null) && !page_ttl.Ns().Id_is_special()) // don't write "In other languages" if no qid; also skip Special ns; needed for pages with wbase page, but no sitelinks; PAGE:en.w:Tintinan; DATE:2015-08-03
page.Wiki().App().Xwiki_mgr__sitelink_mgr().Write_html(bfr, page.Wikie(), slink_list, qid);
}
public static byte[] Write_wdata_links(List_adp slink_list, Xowe_wiki wiki, Xoa_ttl ttl, Wdata_external_lang_links_data external_links_mgr) {
try {
switch (wiki.Domain_tid()) {
case Xow_domain_tid_.Int__home: // home will never be in wikidata
case Xow_domain_tid_.Int__wikidata: // wikidata will never be in wikidata
return Qid_null;
}
Wdata_wiki_mgr wdata_mgr = wiki.Appe().Wiki_mgr().Wdata_mgr();
Wdata_doc doc = wdata_mgr.Doc_mgr.Get_by_ttl_or_null(wiki, ttl); if (doc == null) return Qid_null; // no links
boolean external_links_mgr_enabled = external_links_mgr.Enabled();
Ordered_hash links = doc.Slink_list();
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_k004();
int len = links.Count();
for (int i = 0; i < len; i++) {
Wdata_sitelink_itm slink = (Wdata_sitelink_itm)links.Get_at(i);
byte[] xwiki_key = slink.Site();
Xow_abrv_wm abrv_itm = Xow_abrv_wm_.Parse_to_abrv_or_null(xwiki_key);
if (abrv_itm == null) {
wiki.Appe().Usr_dlg().Warn_many("", "", "unknown wiki in wikidata: ttl=~{0} wiki=~{1}", ttl.Page_db_as_str(), String_.new_u8(xwiki_key));
continue;
}
if (abrv_itm.Domain_type() != wiki.Domain_tid()) continue; // ignore wikis in a different domain; EX: looking at enwiki:Earth, and wikidata has dewikiquote; ignore dewikiquote; DATE:2014-06-21
byte[] lang_key = abrv_itm.Lang_actl().Key();
if (external_links_mgr_enabled && external_links_mgr.Langs_hide(lang_key, 0, lang_key.length)) continue;
tmp_bfr.Add(lang_key);
tmp_bfr.Add_byte(Byte_ascii.Colon);
tmp_bfr.Add(slink.Name());
Xoa_ttl slink_ttl = Xoa_ttl.Parse(wiki, tmp_bfr.To_bry_and_clear());
if (slink_ttl == null) continue; // invalid ttl
Xow_xwiki_itm xwiki_itm = slink_ttl.Wik_itm();
if ( xwiki_itm == null // not a known xwiki; EX: [[zzz:abc]]
|| Bry_.Eq(xwiki_itm.Domain_bry(), wiki.Domain_bry()) // skip if same as self; i.e.: do not include links to enwiki if already in enwiki
) continue;
slink.Page_ttl_(slink_ttl);
slink_list.Add(slink);
}
tmp_bfr.Mkr_rls();
if (external_links_mgr_enabled && external_links_mgr.Sort())
slink_list.Sort_by(Xoa_ttl_sorter.Instance);
return doc.Qid();
} catch (Exception e) {Err_.Noop(e); return Qid_null;}
}
public static final byte[] Qid_null = Bry_.Empty; // NOTE: return Empty, not null else Bry_fmtr will fail
}
class Xoa_ttl_sorter implements gplx.core.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Xoa_ttl lhs = (Xoa_ttl)lhsObj, rhs = (Xoa_ttl)rhsObj;
return Bry_.Compare(lhs.Raw(), rhs.Raw());
}
public static final Xoa_ttl_sorter Instance = new Xoa_ttl_sorter(); Xoa_ttl_sorter() {}
}

View File

@@ -0,0 +1,140 @@
/*
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.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.langs.jsons.*;
import gplx.xowa.wikis.domains.*;
public class Wdata_xwiki_link_wtr_tst {
@Before public void init() {fxt.Init();} private final Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt();
@Test public void Skip_xwiki_lang_for_self() { // PURPOSE: list of language links should not include self
fxt.Init_xwikis_add("en", "fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Int__wikipedia, "Q1_en", "Q1");
fxt.Init__docs__add(fxt.Wdoc_bldr("Q1").Add_sitelink("enwiki", "Q1_en").Add_sitelink("frwiki", "Q1_fr").Add_sitelink("dewiki", "Q1_de").Xto_wdoc());
fxt.Test_xwiki_links("Q1_en", "Q1_fr", "Q1_de");
}
@Test public void No_external_lang_links__de() {
fxt.Init_xwikis_add("fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Int__wikipedia, "Q1_en", "Q1");
fxt.Init__docs__add(fxt.Wdoc_bldr("Q1").Add_sitelink("enwiki", "Q1_en").Add_sitelink("frwiki", "Q1_fr").Add_sitelink("dewiki", "Q1_de").Xto_wdoc());
fxt.Init_external_links_mgr_add("de");
fxt.Test_xwiki_links("Q1_en", "Q1_de");
fxt.Init_external_links_mgr_clear();
fxt.Test_parse_langs("{{noexternallanglinks:de}}", String_.Concat_lines_nl
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/bin/any/xowa/file/app.general/twisty_right.png' title='' /></a> (links: 1) (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td/>"
, " <td/>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Links_w_name_fmt() { // PURPOSE: wikidata changed links node from "enwiki:A" to "enwiki:{name:A,badges:[]}"; DATE:2013-09-14
fxt.Init_xwikis_add("en", "fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Int__wikipedia, "Q1_en", "Q1");
Json_doc jdoc = fxt.App().Utl__json_parser().Parse(String_.Concat_lines_nl
( "{ \"entity\":\"q1\""
, ", \"links\":"
, " { \"dewiki\":\"q1_de\""
, " , \"frwiki\":{\"name\":\"q1_fr\",\"badges\":[]}"
, " }"
, "}"
));
Wdata_doc wdata_doc = new Wdata_doc(Bry_.new_a7("Q1"), fxt.App().Wiki_mgr().Wdata_mgr(), jdoc);
fxt.Init__docs__add(wdata_doc);
fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr");
}
@Test public void Same_lang_but_different_domains() { // PURPOSE: if two entries for same lang, but one is in different domain, use the one for the current wiki DATE:2014-06-21
fxt.Init_xwikis_add("en", "fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Int__wikipedia, "Q1_en", "Q1");
Json_doc jdoc = fxt.App().Utl__json_parser().Parse(String_.Concat_lines_nl
( "{ \"entity\":\"q1\""
, ", \"links\":"
, " { \"dewiki\":\"q1_de\""
, " , \"frwiki\":{\"name\":\"q1_fr\",\"badges\":[]}"
, " , \"dewikisource\":\"q1_dewikisource\"" // this should be ignored
, " }"
, "}"
));
Wdata_doc wdata_doc = new Wdata_doc(Bry_.new_a7("Q1"), fxt.App().Wiki_mgr().Wdata_mgr(), jdoc);
fxt.Init__docs__add(wdata_doc);
fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr");
}
@Test public void Badges() {
fxt.Init_xwikis_add("de", "fr", "pl");
fxt.Init_qids_add("en", Xow_domain_tid_.Int__wikipedia, "Q1_en", "Q1");
fxt.Init__docs__add
( fxt.Wdoc_bldr("Q1")
.Add_sitelink("enwiki", "Q1_en")
.Add_sitelink("dewiki", "Q1_de", "Q17437796")
.Add_sitelink("frwiki", "Q1_fr", "Q17437798")
.Add_sitelink("plwiki", "Q1_pl", "Q17559452")
.Xto_wdoc());
fxt.Test_parse_langs("", String_.Concat_lines_nl
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/bin/any/xowa/file/app.general/twisty_right.png' title='' /></a> (links: 3) (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-goodarticle'><a hreflang=\"fr\" title=\"Q1 fr\" href=\"/site/fr.wikipedia.org/wiki/Q1 fr\">Q1 fr</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-featuredarticle'><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>Polish</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-recommendedarticle'><a hreflang=\"pl\" title=\"Q1 pl\" href=\"/site/pl.wikipedia.org/wiki/Q1 pl\">Q1 pl</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
// @Test public void No_wikidata_link() {
// fxt.Init_xwikis_add("fr", "de");
// fxt.Test_parse_langs("[[fr:A]]", String_.Concat_lines_nl
// ( "<div id=\"xowa-lang\">"
// , " <h5>In other languages</h5>"
// , " <h4>grp1</h4>"
// , " <ul style='-moz-column-count: 3; list-style:none;'>"
// , " <li><span style='display:inline-block; min-width:150px'>French</span><a hreflang=\"fr\" title=\"A\" href=\"/site/fr.wikipedia.org/wiki/A\">A</a></li>"
// , " <li><span style='display:inline-block; min-width:150px'>French</span><a hreflang=\"fr\" title=\"A\" href=\"/site/fr.wikipedia.org/wiki/A\">A</a></li>"
// , " </ul>"
// , "</div>"
// ));
// }
// @Test public void No_external_lang_links__sort() {
// fxt.Init_xwikis_add("de", "fr");
// fxt.Init_qids_add("en", Xow_domain_tid_.Int__wikipedia, "Q1_en", "Q1");
// fxt.Init__docs__add("Q1", fxt.page_bldr_("Q1").Add_sitelink("enwiki", "Q1_en").Add_sitelink("frwiki", "Q1_fr").Add_sitelink("dewiki", "Q1_de").Xto_page_doc());
// fxt.Init_external_links_mgr_add("*");
// fxt.Test_xwiki_links("Q1_en", "Q1_de", "Q1_fr");
// fxt.Init_external_links_mgr_clear();
// fxt.Test_parse_langs("{{noexternallanglinks:*}}", String_.Concat_lines_nl
// ( "<div id=\"xowa-lang\">"
// , " <h5>In other languages (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
// , " <h4>grp1</h4>"
// , " <ul style='-moz-column-count: 3; list-style:none;'>"
// , " <li><span style='display:inline-block; min-width:150px'>German</span><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li>"
// , " <li><span style='display:inline-block; min-width:150px'>French</span><a hreflang=\"fr\" title=\"Q1 fr\" href=\"/site/fr.wikipedia.org/wiki/Q1 fr\">Q1 fr</a></li>"
// , " </ul>"
// , "</div>"
// ));
// }
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.primitives.*;
import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wbase_claim_grp {
public Wbase_claim_grp(Int_obj_ref id_ref, Wbase_claim_base[] itms) {this.id_ref = id_ref; this.itms = itms;}
public Int_obj_ref Id_ref() {return id_ref;} private final Int_obj_ref id_ref;
public int Id() {return id_ref.Val();}
public String Id_str() {if (id_str == null) id_str = "P" + Int_.To_str(id_ref.Val()); return id_str;} private String id_str;
public int Len() {return itms.length;} private Wbase_claim_base[] itms;
public Wbase_claim_base Get_at(int i) {return itms[i];}
public static List_adp Xto_list(Ordered_hash hash) {
int len = hash.Count();
List_adp rv = List_adp_.New();
for (int i = 0; i < len; ++i) {
Wbase_claim_grp grp = (Wbase_claim_grp)hash.Get_at(i);
int grp_len = grp.Len();
for (int j = 0; j < grp_len; ++j)
rv.Add(grp.Get_at(j));
}
return rv;
}
}

View File

@@ -0,0 +1,24 @@
/*
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.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wbase_claim_grp_list {
private Ordered_hash hash = Ordered_hash_.New();
public void Add(Wbase_claim_grp itm) {hash.Add(itm.Id_ref(), itm);}
public int Len() {return hash.Count();}
public Wbase_claim_grp Get_at(int i) {return (Wbase_claim_grp)hash.Get_at(i);}
}

View File

@@ -0,0 +1,28 @@
/*
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.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.wbases.claims.itms.*;
public interface Wbase_claim_visitor {
void Visit_str (Wbase_claim_string itm);
void Visit_entity (Wbase_claim_entity itm);
void Visit_monolingualtext (Wbase_claim_monolingualtext itm);
void Visit_quantity (Wbase_claim_quantity itm);
void Visit_time (Wbase_claim_time itm);
void Visit_globecoordinate (Wbase_claim_globecoordinate itm);
void Visit_system (Wbase_claim_value itm);
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wbase_references_grp {
public Wbase_references_grp(Wbase_claim_grp_list references, int[] references_order) {this.references = references; this.references_order = references_order;}
public Wbase_claim_grp_list References() {return references;} private Wbase_claim_grp_list references;
public int[] References_order() {return references_order;} private int[] references_order;
}

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.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_entity_type_ {
public static final byte
Tid__item = 0
, Tid__property = 1
;
private static final int Ary__len = 2;
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
public static final Wbase_claim_enum
Itm__item = New(Tid__item , "item")
, Itm__property = New(Tid__property , "property")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
Ary[tid] = rv;
return rv;
}
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
public static byte To_tid_or_fail(byte[] bry) {return ((Wbase_claim_enum)hash_by_bry.Get_by_or_fail(bry)).Tid();}
}

View File

@@ -0,0 +1,28 @@
/*
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.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_enum {
public Wbase_claim_enum(byte tid, String key_str) {
this.tid = tid;
this.key_str = key_str;
this.key_bry = Bry_.new_u8(key_str);
}
public byte Tid() {return tid;} private final byte tid;
public String Key_str() {return key_str;} private final String key_str;
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
}

View File

@@ -0,0 +1,37 @@
/*
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.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_enum_ {
public static byte To_tid_or_invalid(Hash_adp hash, byte[] url, String key) {
Object rv_obj = hash.Get_by(key);
if (rv_obj == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown enum key for wikibase; url=~{0} key=~{1}", url, key);
return Tid__invalid;
}
return ((Wbase_claim_enum)rv_obj).Tid();
}
public static byte To_tid_or_invalid(Hash_adp_bry hash, byte[] url, byte[] key) {
Object rv_obj = hash.Get_by_bry(key);
if (rv_obj == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown enum key for wikibase; url=~{0} key=~{1}", url, key);
return Tid__invalid;
}
return ((Wbase_claim_enum)rv_obj).Tid();
}
public static final byte Tid__invalid = Byte_.Max_value_127;
}

View File

@@ -0,0 +1,46 @@
/*
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.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_rank_ {
public static final byte // SERIALIZED.MW
Tid__preferred = 2
, Tid__normal = 1
, Tid__deprecated = 0
, Tid__unknown = 3
;
private static final int Ary__len = 4;
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
public static final Wbase_claim_enum
Itm__preferred = New(Tid__preferred , "preferred")
, Itm__normal = New(Tid__normal , "normal")
, Itm__deprecated = New(Tid__deprecated , "deprecated")
, Itm__unknown = New(Tid__unknown , "unknown")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
Ary[tid] = rv;
return rv;
}
public static byte To_tid_or_unknown(byte[] src) {
Object obj = hash_by_bry.Get_by_bry(src);
return obj == null ? Tid__unknown : ((Wbase_claim_enum)obj).Tid();
}
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
}

View File

@@ -0,0 +1,30 @@
/*
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.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_type {
public Wbase_claim_type(byte tid, String key_str, String key_for_scrib) {
this.tid = tid;
this.key_str = key_str;
this.key_bry = Bry_.new_u8(key_str);
this.key_for_scrib = key_for_scrib;
}
public byte Tid() {return tid;} private final byte tid;
public String Key_str() {return key_str;} private final String key_str;
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
public String Key_for_scrib() {return key_for_scrib;} private final String key_for_scrib;
}

View File

@@ -0,0 +1,64 @@
/*
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.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_type_ {
public static final byte // NOT_SERIALIZED
Tid__unknown = 0
, Tid__value = 1
, Tid__bad = 1
, Tid__string = 2
, Tid__quantity = 3
, Tid__time = 4
, Tid__globecoordinate = 5
, Tid__monolingualtext = 6
, Tid__entity = 7
;
private static final int Ary__len = 13;
private static final Wbase_claim_type[] Ary = new Wbase_claim_type[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
private static final Hash_adp hash_by_str = Hash_adp_.New();
public static final Wbase_claim_type
Itm__unknown = New(Tid__unknown , "unknown")
, Itm__bad = New(Tid__bad , "bad") // NOTE: wikidata identifies several entries as "bad"; Q1615351|'s-Graveland, Q107538|Baco; DATE:2013-10-20
, Itm__string = New(Tid__string , "string") // EX:wd:Property:P1030
, Itm__quantity = New(Tid__quantity , "quantity")
, Itm__time = New(Tid__time , "time")
, Itm__globecoordinate = New(Tid__globecoordinate , "globecoordinate" , "globe-coordinate")
, Itm__monolingualtext = New(Tid__monolingualtext , "monolingualtext")
, Itm__entity = New(Tid__entity , "wikibase-entityid" , "wikibase-item")
;
private static Wbase_claim_type New(byte tid, String key) {return New(tid, key, key);}
private static Wbase_claim_type New(byte tid, String key, String scrib) {
Wbase_claim_type rv = new Wbase_claim_type(tid, key, scrib);
hash_by_bry.Add(rv.Key_bry(), rv);
hash_by_str.Add(rv.Key_str(), rv);
Ary[tid] = rv;
return rv;
}
public static String To_key_or_unknown(byte tid) {return tid < Ary__len ? Ary[tid].Key_str() : Itm__unknown.Key_str();}
public static String To_scrib_or_unknown(byte tid) {return tid < Ary__len ? Ary[tid].Key_for_scrib() : Itm__unknown.Key_str();}
public static byte To_tid_or_unknown(byte[] src) {return To_tid_or_unknown(src, 0, src.length);}
public static byte To_tid_or_unknown(byte[] src, int bgn, int end) {
Object obj = hash_by_bry.Get_by_mid(src, bgn, end);
return obj == null ? Tid__unknown : ((Wbase_claim_type)obj).Tid();
}
public static byte To_tid_or_unknown(String src) {
Object obj = hash_by_str.Get_by(src);
return obj == null ? Tid__unknown : ((Wbase_claim_type)obj).Tid();
}
}

View File

@@ -0,0 +1,43 @@
/*
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.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_value_type_ {
public static final byte // SERIALIZED.MW
Tid__novalue = 0
, Tid__value = 1
, Tid__somevalue = 2
;
private static final int Ary__len = 3;
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
public static final Wbase_claim_enum
Itm__novalue = New(Tid__novalue , "novalue")
, Itm__value = New(Tid__value , "value")
, Itm__somevalue = New(Tid__somevalue , "somevalue")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
Ary[tid] = rv;
return rv;
}
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
public static byte To_tid_or_fail(byte[] bry) {return ((Wbase_claim_enum)hash_by_bry.Get_by_or_fail(bry)).Tid();}
}

View File

@@ -0,0 +1,46 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public abstract class Wbase_claim_base implements CompareAble {
public Wbase_claim_base(int pid, byte snak_tid) {
this.pid = pid;
this.snak_tid = snak_tid;
}
public int Pid() {return pid;} private final int pid;
public byte Snak_tid() {return snak_tid;} private final byte snak_tid;
public byte Rank_tid() {return rank_tid;} private byte rank_tid = Wbase_claim_rank_.Tid__normal; // TEST: default to normal for tests
public String Prop_type() {return Prop_type_statement;} private static final String Prop_type_statement = "statement";
public byte[] Wguid() {return wguid;} private byte[] wguid;
public Wbase_claim_grp_list Qualifiers() {return qualifiers;} private Wbase_claim_grp_list qualifiers;
public int[] Qualifiers_order() {return qualifiers_order;} private int[] qualifiers_order;
public Wbase_references_grp[] References() {return references;} private Wbase_references_grp[] references;
public abstract byte Val_tid();
public abstract void Welcome(Wbase_claim_visitor visitor);
public void Rank_tid_(byte v) {this.rank_tid = v;}
public void Wguid_(byte[] v) {this.wguid = v;}
public Wbase_claim_base Qualifiers_(Wbase_claim_grp_list v) {qualifiers = v; return this;}
public void Qualifiers_order_(int[] v) {qualifiers_order = v;}
public void References_(Wbase_references_grp[] v) {references = v;}
public int compareTo(Object obj) {
Wbase_claim_base comp = (Wbase_claim_base)obj;
return Int_.Compare(pid, comp.pid);
}
}

View File

@@ -0,0 +1,50 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_entity extends Wbase_claim_base {
public Wbase_claim_entity(int pid, byte snak_tid, byte entity_tid, byte[] entity_id_bry) {super(pid, snak_tid);
this.entity_tid = entity_tid;
this.entity_id_bry = entity_id_bry;
this.entity_id = Bry_.To_int(entity_id_bry);
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__entity;}
public int Entity_id() {return entity_id;} private final int entity_id;
public byte[] Entity_id_bry() {return entity_id_bry;} private final byte[] entity_id_bry;
public byte Entity_tid() {return entity_tid;} private final byte entity_tid;
public boolean Entity_tid_is_qid() {return entity_tid == Wbase_claim_entity_type_.Tid__item;}
public String Entity_tid_str() {return Wbase_claim_entity_type_.To_str_or_fail(entity_tid);}
public byte[] Entity_tid_bry() {return Wbase_claim_entity_type_.To_bry_or_fail(entity_tid);}
public byte[] Page_ttl_db() {
return entity_tid == Wbase_claim_entity_type_.Tid__item
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_db, entity_id_bry)
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, entity_id_bry)
;
}
public byte[] Page_ttl_gui() {
return entity_tid == Wbase_claim_entity_type_.Tid__item
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_gui, entity_id_bry)
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, entity_id_bry)
;
}
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_entity(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), this.Entity_tid_str(), Int_.To_str(entity_id));
}
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_entity_ {
public static final byte
Tid__entity_type = 0
, Tid__numeric_id = 1
;
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
public static final Wbase_claim_enum
Itm__entity_type = New(Tid__entity_type , "entity-type")
, Itm__numeric_id = New(Tid__numeric_id , "numeric-id")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
return rv;
}
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
}

View File

@@ -0,0 +1,43 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_globecoordinate extends Wbase_claim_base {
public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {super(pid, snak_tid);
this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
public byte[] Lat() {return lat;} private final byte[] lat;
public byte[] Lng() {return lng;} private final byte[] lng;
public byte[] Alt() {return alt;} private final byte[] alt;
public byte[] Prc() {return prc;} private final byte[] prc;
public byte[] Glb() {return glb;} private final byte[] glb;
public byte[] Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
public void Glb_ttl_(byte[] v) {glb_ttl = v;}
public Decimal_adp Prc_as_num() {
if (prc_as_num == null)
prc_as_num = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
return prc_as_num;
} private Decimal_adp prc_as_num;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(lat), String_.new_u8(lng), String_.new_u8(alt), String_.new_u8(prc), String_.new_u8(glb));
}
}

View File

@@ -0,0 +1,58 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_globecoordinate_ {
public static final byte
Tid__latitude = 0
, Tid__longitude = 1
, Tid__altitude = 2
, Tid__precision = 3
, Tid__globe = 4
;
private static final int Ary__len = 5;
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
private static final Hash_adp hash_by_str = Hash_adp_.New();
public static final Wbase_claim_enum
Itm__latitude = New(Tid__latitude , "latitude")
, Itm__longitude = New(Tid__longitude , "longitude")
, Itm__altitude = New(Tid__altitude , "altitude")
, Itm__precision = New(Tid__precision , "precision")
, Itm__globe = New(Tid__globe , "globe")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
hash_by_str.Add(rv.Key_str(), rv);
Ary[tid] = rv;
return rv;
}
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
public static String
Val_globe_dflt_str = "http://www.wikidata.org/entity/Q2"
;
public static byte[]
Val_globe_dflt_bry = Bry_.new_a7(Val_globe_dflt_str)
;
}

View File

@@ -0,0 +1,32 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_monolingualtext extends Wbase_claim_base {
public Wbase_claim_monolingualtext(int pid, byte snak_tid, byte[] lang, byte[] text) {super(pid, snak_tid);
this.lang = lang; this.text = text;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__monolingualtext;}
public byte[] Lang() {return lang;} private final byte[] lang;
public byte[] Text() {return text;} private final byte[] text;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_monolingualtext(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(lang), String_.new_u8(text));
}
}

View File

@@ -0,0 +1,42 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_monolingualtext_ {
public static final byte
Tid__text = 0
, Tid__language = 1
;
private static final int Ary__len = 2;
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
public static final Wbase_claim_enum
Itm__text = New(Tid__text , "text")
, Itm__language = New(Tid__language , "language")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
Ary[tid] = rv;
return rv;
}
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
}

View File

@@ -0,0 +1,54 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_quantity extends Wbase_claim_base {
public Wbase_claim_quantity(int pid, byte snak_tid, byte[] amount, byte[] unit, byte[] ubound, byte[] lbound) {super(pid, snak_tid);
this.amount = amount; this.unit = unit; this.ubound = ubound; this.lbound = lbound;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__quantity;}
public byte[] Amount() {return amount;} private final byte[] amount;
public byte[] Ubound() {return ubound;} private final byte[] ubound;
public byte[] Lbound() {return lbound;} private final byte[] lbound;
public byte[] Unit() {return unit;} private final byte[] unit;
public Decimal_adp Amount_as_num() {
if (amount_as_num == null) amount_as_num = To_decimal("amount", amount);
return amount_as_num;
} private Decimal_adp amount_as_num;
public Decimal_adp Ubound_as_num() {
if (ubound_as_num == null) ubound_as_num = To_decimal("upper", ubound);
return ubound_as_num;
} private Decimal_adp ubound_as_num;
public Decimal_adp Lbound_as_num() {
if (lbound_as_num == null) lbound_as_num = To_decimal("lower", lbound);
return lbound_as_num;
} private Decimal_adp lbound_as_num;
private Decimal_adp To_decimal(String type, byte[] v) {
if (v == null) throw Err_.new_("wbase", "value is null", "type", type);
int len = v.length; if (len == 0) throw Err_.new_("wbase", "value is empty", "type", type);
if (v[0] == Byte_ascii.Plus) v = Bry_.Mid(v, 1);
return Decimal_adp_.parse(String_.new_a7(v));
}
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_quantity(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(amount), String_.new_u8(unit), String_.new_u8(ubound), String_.new_u8(lbound));
}
public static final byte[] Unit_1 = Bry_.new_a7("1");
}

View File

@@ -0,0 +1,49 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_quantity_ {
public static final byte
Tid__amount = 0
, Tid__unit = 1
, Tid__upperbound = 2
, Tid__lowerbound = 3
;
private static final int Ary__len = 4;
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
private static final Hash_adp hash_by_str = Hash_adp_.New();
public static final Wbase_claim_enum
Itm__amount = New(Tid__amount , "amount")
, Itm__unit = New(Tid__unit , "unit")
, Itm__upperbound = New(Tid__upperbound , "upperBound")
, Itm__lowerbound = New(Tid__lowerbound , "lowerBound")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
hash_by_str.Add(rv.Key_str(), rv);
Ary[tid] = rv;
return rv;
}
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_string extends Wbase_claim_base {
public Wbase_claim_string(int pid, byte snak_tid, byte[] val) {super(pid, snak_tid);
this.val = val;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__string;}
public byte[] Val_str() {return val;} private final byte[] val;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_str(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(val));
}
}

View File

@@ -0,0 +1,107 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.hwtrs.*;
public class Wbase_claim_time extends Wbase_claim_base {
public Wbase_claim_time(int pid, byte snak_tid, byte[] time, byte[] timezone, byte[] before, byte[] after, byte[] precision, byte[] calendar) {super(pid, snak_tid);
this.time = time; this.before = before; this.after = after; this.precision = precision; this.calendar = calendar;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__time;}
public byte[] Time() {return time;} private final byte[] time;
public byte[] Before() {return before;} private final byte[] before;
public byte[] After() {return after;} private final byte[] after;
public byte[] Precision() {return precision;} private final byte[] precision;
public byte[] Calendar() {return calendar;} private final byte[] calendar;
public byte[] Calendar_ttl() {return calendar_ttl;} private byte[] calendar_ttl;
public boolean Calendar_is_julian() {return Bry_.Eq(calendar, Calendar_julian);}
public void Calendar_ttl_(byte[] v) {calendar_ttl = v;}
public Wbase_date Time_as_date() {
if (time_as_date == null) time_as_date = Wbase_date.Parse(time, this.Precision_int(), this.Before_int(), this.After_int(), this.Calendar_is_julian());
return time_as_date;
} private Wbase_date time_as_date;
public int Precision_int() {
if (precision_int == Int_.Min_value) {
precision_int = Bry_.To_int_or(precision, -1);
if (precision_int == -1) {
precision_int = Wbase_date.Fmt_ymdhns;
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown precision: ~{0}", String_.new_u8(precision));
}
}
return precision_int;
} private int precision_int = Int_.Min_value;
public int Before_int() {
if (before_int == Int_.Min_value) {
before_int = Bry_.To_int_or(before, -1);
if (before_int == -1) {
before_int = 0;
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown before: ~{0}", String_.new_u8(before));
}
}
return before_int;
} private int before_int = Int_.Min_value;
public int After_int() {
if (after_int == Int_.Min_value) {
after_int = Bry_.To_int_or(after, -1);
if (after_int == -1) {
after_int = 0;
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown after: ~{0}", String_.new_u8(after));
}
}
return after_int;
} private int after_int = Int_.Min_value;
public void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs, byte[] ttl) {
try {
Wbase_date date = this.Time_as_date();
boolean calendar_is_julian = this.Calendar_is_julian();
byte[] calendar_display = null;
if (calendar_is_julian) {
date = Wbase_date.Xto_julian(date);
calendar_display = msgs.Time_julian();
}
Wbase_date.Xto_str(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
if (calendar_display != null)
bfr.Add_byte_space().Add(calendar_display);
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, this.Pid(), Err_.Message_gplx_log(e));
}
}
public static void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs
, byte[] ttl, byte[] pid, Wbase_date date, boolean calendar_is_julian) {
try {
byte[] calendar_display = null;
if (calendar_is_julian) {
date = Wbase_date.Xto_julian(date);
calendar_display = msgs.Time_julian();
}
Wbase_date.Xto_str(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
if (calendar_display != null)
bfr.Add_byte_space().Add(calendar_display);
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, pid, Err_.Message_gplx_log(e));
}
}
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_time(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(time), String_.new_u8(before), String_.new_u8(after), String_.new_u8(precision), String_.new_u8(calendar));
}
public static final byte[] Calendar_julian = Bry_.new_a7("http://www.wikidata.org/entity/Q1985786");
}

View File

@@ -0,0 +1,82 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*;
public class Wbase_claim_time_ {
public static final byte
Tid__time = 0
, Tid__timezone = 1
, Tid__before = 2
, Tid__after = 3
, Tid__precision = 4
, Tid__calendarmodel = 5
;
private static final int Ary__len = 6;
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
private static final Hash_adp hash_by_str = Hash_adp_.New();
public static final Wbase_claim_enum
Itm__time = New(Tid__time , "time")
, Itm__timezone = New(Tid__timezone , "timezone")
, Itm__before = New(Tid__before , "before")
, Itm__after = New(Tid__after , "after")
, Itm__precision = New(Tid__precision , "precision")
, Itm__calendarmodel = New(Tid__calendarmodel , "calendarmodel")
;
private static Wbase_claim_enum New(byte tid, String key) {
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
hash_by_bry.Add(rv.Key_bry(), rv);
hash_by_str.Add(rv.Key_str(), rv);
Ary[tid] = rv;
return rv;
}
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
public static final Wbase_data_itm
Dflt__precision = Wbase_data_itm.New_int(11)
, Dflt__before = Wbase_data_itm.New_int(0)
, Dflt__after = Wbase_data_itm.New_int(0)
, Dflt__timezone = Wbase_data_itm.New_int(0)
, Dflt__calendarmodel = Wbase_data_itm.New_str("http://www.wikidata.org/entity/Q1985727")
;
private static final byte[] Bry_year_prefix = Bry_.new_a7("+0000000");
public static byte[] To_bry(Bry_bfr bfr, String date) {return To_bry(bfr, DateAdp_.parse_fmt(date, "yyyy-MM-dd HH:mm:ss"));}
public static byte[] To_bry(Bry_bfr bfr, DateAdp date) {// +0000000yyyy-MM-ddTHH:mm:ssZ
bfr
.Add(Bry_year_prefix)
.Add_int_fixed(date.Year(), 4)
.Add_byte(Byte_ascii.Dash)
.Add_int_fixed(date.Month(), 2)
.Add_byte(Byte_ascii.Dash)
.Add_int_fixed(date.Day(), 2)
.Add_byte(Byte_ascii.Ltr_T)
.Add_int_fixed(date.Hour(), 2)
.Add_byte(Byte_ascii.Colon)
.Add_int_fixed(date.Minute(), 2)
.Add_byte(Byte_ascii.Colon)
.Add_int_fixed(date.Second(), 2)
.Add_byte(Byte_ascii.Ltr_Z)
;
return bfr.To_bry_and_clear();
}
}

View File

@@ -0,0 +1,33 @@
/*
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.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_value extends Wbase_claim_base {
public Wbase_claim_value(int pid, byte val_tid, byte snak_tid) {super(pid, snak_tid);
this.val_tid = val_tid;
}
@Override public byte Val_tid() {return val_tid;} private final byte val_tid;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_system(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()));
}
public static Wbase_claim_value New_novalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__novalue);}
public static Wbase_claim_value New_somevalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__somevalue);}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wbase_data_itm {
public Wbase_data_itm(int val_int, String val_str, byte[] val_bry) {
this.val_int = val_int;
this.val_str = val_str;
this.val_bry = val_bry;
}
public int Val_int() {return val_int;} private final int val_int;
public String Val_str() {return val_str;} private final String val_str;
public byte[] Val_bry() {return val_bry;} private final byte[] val_bry;
public static Wbase_data_itm New_int(int val) {return new Wbase_data_itm(val, Int_.To_str(val), Int_.To_bry(val));}
public static Wbase_data_itm New_str(String val) {return new Wbase_data_itm( -1, val, Bry_.new_u8(val));}
}

View File

@@ -0,0 +1,189 @@
/*
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.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.xtns.wbases.hwtrs.*;
public class Wbase_date {
public Wbase_date(long year, int month, int day, int hour, int minute, int second, int precision, int before, int after, boolean calendar_is_julian) {
this.year = year; this.month = month; this.day = day; this.hour = hour; this.minute = minute; this.second = second;
this.precision = precision; this.before = before; this.after = after; this.calendar_is_julian = calendar_is_julian;
}
public long Year() {return year;} private final long year;
public int Month() {return month;} private final int month;
public int Day() {return day;} private final int day;
public int Hour() {return hour;} private final int hour;
public int Minute() {return minute;} private final int minute;
public int Second() {return second;} private final int second;
public int Precision() {return precision;} private final int precision;
public int Before() {return before;} private final int before;
public int After() {return after;} private final int after;
public boolean Calendar_is_julian() {return calendar_is_julian;} private final boolean calendar_is_julian;
public static Wbase_date Parse(byte[] date, int precision, int before, int after, boolean calendar_is_julian) {// EX:+00000002001-02-03T04:05:06Z
int year_sign = 1;
switch (date[0]) {
case Byte_ascii.Plus: break;
case Byte_ascii.Dash: year_sign = -1; break;
default: throw Err_.new_unhandled(date[0]);
}
int year_end = Bry_find_.Find_fwd(date, Byte_ascii.Dash, 1);
long year = Long_.parse_or(String_.new_a7(date, 1, year_end), -1); if (year == -1) throw Err_.new_wo_type("parse failed", "raw", String_.new_a7(date));
int month = Bry_.To_int_or(date, year_end + 1, year_end + 3, -1);
int day = Bry_.To_int_or(date, year_end + 4, year_end + 6, -1);
int hour = Bry_.To_int_or(date, year_end + 7, year_end + 9, -1);
int minute = Bry_.To_int_or(date, year_end + 10, year_end + 12, -1);
int second = Bry_.To_int_or(date, year_end + 13, year_end + 15, -1);
return new Wbase_date(year * year_sign, month, day, hour, minute, second, precision, before, after, calendar_is_julian);
}
public static Wbase_date Xto_julian(Wbase_date date) {
int a = (int)Math_.Floor((14 - date.Month() / 12));
int y = (int)date.Year() + 4800 - a;
int m = date.Month() + 12 * a - 3;
int julian = date.Day() + (int)Math_.Floor((153 * m + 2) / 5) + 365 * y + (int)Math_.Floor(y / 4) - (int)Math_.Floor(y / 100) + (int)Math_.Floor(y / 400) - 32045;
int c = julian + 32082;
int d = (int)Math_.Floor((4 * c + 3) / 1461);
int e = c - (int)Math_.Floor((1461 * d) / 4);
int n = (int)Math_.Floor((5 * e + 2) / 153);
int new_y = d - 4800 + (int)Math_.Floor(n / 10);
int new_m = n + 3 - 12 * (int)Math_.Floor(n / 10);
int new_d = e - (int)Math_.Floor((153 * n + 2) / 5) + 1;
return new Wbase_date(new_y, new_m, new_d, date.Hour(), date.Minute(), date.Second(), date.precision, date.before, date.after, date.calendar_is_julian);
}
public static void Xto_str(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
boolean calendar_is_julian = date.calendar_is_julian;
if (calendar_is_julian)
date = Xto_julian(date);
long year = date.Year();
int months_bgn = msgs.Month_bgn_idx();
byte[][] months = msgs.Ary();
int precision = date.precision;
byte[] time_spr = msgs.Sym_time_spr();
switch (precision) {
case Wbase_date.Fmt_ym: // EX: "Feb 2001"
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(year);
break;
case Wbase_date.Fmt_ymd: // EX: "3 Feb 2001"
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
break;
case Wbase_date.Fmt_ymdh: // EX: "4:00 3 Feb 2011"
bfr.Add_int_variable(date.Hour());
bfr.Add(time_spr);
bfr.Add_int_fixed(0, 2);
bfr.Add_byte_space();
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
break;
case Wbase_date.Fmt_ymdhn: // EX: "4:05 3 Feb 2011"
bfr.Add_int_variable(date.Hour());
bfr.Add(time_spr);
bfr.Add_int_fixed(date.Minute(), 2);
bfr.Add_byte_space();
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
break;
default:
if (precision <= 9) // y, round to (9 - prec)
Xto_str_fmt_y(bfr, tmp_fmtr, tmp_bfr, msgs, date, precision);
else { // EX: "4:05:06 3 Feb 2011"
bfr.Add_int_variable(date.Hour());
bfr.Add(time_spr);
bfr.Add_int_fixed(date.Minute(), 2);
bfr.Add(time_spr);
bfr.Add_int_fixed(date.Second(), 2);
bfr.Add_byte_space();
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
}
break;
}
if (calendar_is_julian)
bfr.Add(msgs.Time_julian());
Xto_str_beforeafter(bfr, tmp_fmtr, tmp_bfr, msgs, date);
}
private static void Xto_str_beforeafter(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
byte[] bry = null;
int before = date.before;
int after = date.after;
if (before == 0) {
if (after != 0)
bry = tmp_bfr.Add(msgs.Sym_plus()).Add_int_variable(after).To_bry_and_clear();
}
else {
if (after == 0)
bry = tmp_bfr.Add(msgs.Sym_minus()).Add_int_variable(before).To_bry_and_clear();
else if (before == after)
bry = tmp_bfr.Add(msgs.Sym_plusminus()).Add_int_variable(before).To_bry_and_clear();
else
bry = tmp_bfr.Add(msgs.Sym_minus()).Add_int_variable(before).Add(msgs.Sym_list_comma()).Add(msgs.Sym_plus()).Add_int_variable(after).To_bry_and_clear();
}
if (bry != null) {
bry = tmp_fmtr.Fmt_(msgs.Sym_fmt_parentheses()).Bld_bry_many(tmp_bfr, bry);
bfr.Add_byte_space().Add(bry);
}
}
private static void Xto_str_fmt_y(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date, int precision) {
int year_pow = 9 - precision;
byte[] year_fmt = msgs.Ary()[msgs.Time_year_idx() + year_pow];
long year = date.Year();
byte[] repl_fmt = null;
if (year <= 0) { // negative
if (year_pow < 4) // negative years < 999 get "BC"
repl_fmt = msgs.Time_relative_bc();
else // negative years > 999 get "ago"
repl_fmt = msgs.Time_relative_ago();
}
else {
if (year_pow > 4) // positive years > 999 get "in time"
repl_fmt = msgs.Time_relative_in();
}
if (repl_fmt != null)
year_fmt = tmp_fmtr.Fmt_(repl_fmt).Bld_bry_many(tmp_bfr, year_fmt);
if (year <= 0)
year *= -1; // convert negative to positive; note that negative year will be reported with "BC" / "ago"
switch (year_pow) {
case 0: break; // noop
default:
year = (int)(year / Math_.Pow(10, year_pow));
break;
}
byte[] year_bry = tmp_fmtr.Fmt_(year_fmt).Bld_bry_many(tmp_bfr, year);
bfr.Add(year_bry);
}
public static final int
Fmt_y = 9
, Fmt_ym = 10
, Fmt_ymd = 11
, Fmt_ymdh = 12
, Fmt_ymdhn = 13
, Fmt_ymdhns = 14 // anything >13 ?
;
}

View File

@@ -0,0 +1,92 @@
/*
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.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
import org.junit.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.hwtrs.*;
public class Wbase_date_tst {
@Before public void init() {fxt.Clear();} private Wbase_date_fxt fxt = new Wbase_date_fxt();
@Test public void Parse() {
fxt.Test_parse("+00000002001-02-03T04:05:06Z", 2001, 2, 3, 4, 5, 6);
fxt.Test_parse("-98765432109-02-03T04:05:06Z", -98765432109L, 2, 3, 4, 5, 6);
}
@Test public void Julian() {
fxt.Test_julian(Int_.Ary(1600, 1, 2), Int_.Ary(1600, 1, 18));
}
@Test public void Xto_str() {
String date = "+00000002001-02-03T04:05:06Z";
fxt.Test_xto_str(date, Wbase_date.Fmt_ym , "Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymd , "3 Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdh , "4:00 3 Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhn , "4:05 3 Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhns , "4:05:06 3 Feb 2001");
}
@Test public void Xto_str_year() {
fxt.Test_xto_str("+00000001970-01-01T00:00:00Z", 9, "1970");
fxt.Test_xto_str("-00000001234-01-01T00:00:00Z", 9, "1234 BC");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 8, "1980s");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 7, "19. century");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 6, "1. millenium");
fxt.Test_xto_str("+00000012345-01-01T00:00:00Z", 5, "10,000 years");
fxt.Test_xto_str("+00000123456-01-01T00:00:00Z", 4, "in 100,000 years");
}
@Test public void Xto_str_julian() {
fxt.Init_calendar_is_julian_(Bool_.Y).Test_xto_str("+00000001600-01-02T00:00:00Z", Wbase_date.Fmt_ymd, "18 Jan 1600<sup>jul</sup>");
}
@Test public void Xto_str_before_after() {
String date = "+00000002001-02-03T04:05:06Z";
fxt.Clear().Init_before_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1)");
fxt.Clear().Init_after_ (1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (+1)");
fxt.Clear().Init_before_(1).Init_after_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (±1)");
fxt.Clear().Init_before_(1).Init_after_(2).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1,&#32;+2)");
}
}
class Wbase_date_fxt {
private Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(16);
private Wdata_hwtr_msgs msgs;
private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_(); private final Bry_bfr tmp_time_bfr = Bry_bfr_.New_w_size(32);
public Wbase_date_fxt Clear() {
init_before = init_after = 0;
init_calendar_is_julian = false;
return this;
}
public boolean Init_calendar_is_julian() {return init_calendar_is_julian;} public Wbase_date_fxt Init_calendar_is_julian_(boolean v) {init_calendar_is_julian = v; return this;} private boolean init_calendar_is_julian;
public int Init_before() {return init_before;} public Wbase_date_fxt Init_before_(int v) {init_before = v; return this;} private int init_before;
public int Init_after() {return init_after;} public Wbase_date_fxt Init_after_(int v) {init_after = v; return this;} private int init_after;
public void Test_parse(String raw, long expd_y, int expd_m, int expd_d, int expd_h, int expd_n, int expd_s) {
Wbase_date actl_date = Wbase_date.Parse(Bry_.new_a7(raw), Wbase_date.Fmt_ymdhns, init_before, init_after, init_calendar_is_julian);
Tfds.Eq(expd_y, actl_date.Year());
Tfds.Eq(expd_m, actl_date.Month());
Tfds.Eq(expd_d, actl_date.Day());
Tfds.Eq(expd_h, actl_date.Hour());
Tfds.Eq(expd_n, actl_date.Minute());
Tfds.Eq(expd_s, actl_date.Second());
}
public void Test_julian(int[] orig_ary, int[] expd) {
Wbase_date orig = new Wbase_date(orig_ary[0], orig_ary[1], orig_ary[2], 0, 0, 0, 0, 0, 0, init_calendar_is_julian);
Wbase_date actl = Wbase_date.Xto_julian(orig);
Tfds.Eq(expd[0], (int)actl.Year(), "y");
Tfds.Eq(expd[1], actl.Month(), "m");
Tfds.Eq(expd[2], actl.Day(), "d");
}
public void Test_xto_str(String raw, int precision, String expd) {
if (msgs == null) msgs = Wdata_hwtr_msgs.new_en_();
Wbase_date date = Wbase_date.Parse(Bry_.new_a7(raw), precision, init_before, init_after, init_calendar_is_julian);
Wbase_date.Xto_str(tmp_bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*;
public class Wdata_alias_itm implements Wdata_lang_sortable {
public Wdata_alias_itm(byte[] lang, byte[][] vals) {this.lang = lang; this.vals = vals;}
public byte[] Lang() {return lang;} private byte[] lang;
public byte[][] Vals() {return vals;} private byte[][] vals;
public byte[] Lang_code() {return lang;}
public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null;
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", String_.new_u8(lang), String_.Concat_with_str("~", String_.Ary(vals)));
}
}

View File

@@ -0,0 +1,56 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_dict_claim {
public static final byte
Tid_mainsnak = 0
, Tid_type = 1
, Tid_id = 2
, Tid_rank = 3
, Tid_references = 4
, Tid_qualifiers = 5
, Tid_qualifiers_order = 6
;
public static String
Str_mainsnak = "mainsnak"
, Str_type = "type"
, Str_id = "id"
, Str_rank = "rank"
, Str_references = "references"
, Str_qualifiers = "qualifiers"
, Str_qualifiers_order = "qualifiers-order"
;
public static byte[]
Bry_mainsnak = Bry_.new_a7(Str_mainsnak)
, Bry_type = Bry_.new_a7(Str_type)
, Bry_id = Bry_.new_a7(Str_id)
, Bry_rank = Bry_.new_a7(Str_rank)
, Bry_references = Bry_.new_a7(Str_references)
, Bry_qualifiers = Bry_.new_a7(Str_qualifiers)
, Bry_qualifiers_order = Bry_.new_a7(Str_qualifiers_order)
;
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
.Add_bry_byte(Bry_mainsnak , Tid_mainsnak)
.Add_bry_byte(Bry_type , Tid_type)
.Add_bry_byte(Bry_id , Tid_id)
.Add_bry_byte(Bry_rank , Tid_rank)
.Add_bry_byte(Bry_references , Tid_references)
.Add_bry_byte(Bry_qualifiers , Tid_qualifiers)
.Add_bry_byte(Bry_qualifiers_order , Tid_qualifiers_order)
;
}

View File

@@ -0,0 +1,34 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_dict_claim_v1 {
public static final String
Str_m = "m"
, Str_q = "q"
, Str_g = "g"
, Str_rank = "rank"
, Str_refs = "refs"
;
public static final byte[]
Bry_m = Bry_.new_a7(Str_m)
, Bry_q = Bry_.new_a7(Str_q)
, Bry_g = Bry_.new_a7(Str_g)
, Bry_rank = Bry_.new_a7(Str_rank)
, Bry_refs = Bry_.new_a7(Str_refs)
;
}

View File

@@ -0,0 +1,40 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_dict_datavalue {
public static final byte
Tid_value = 0
, Tid_type = 1
, Tid_error = 2
;
public static final String
Str_value = "value"
, Str_type = "type"
, Str_error = "error"
;
public static byte[]
Bry_value = Bry_.new_a7(Str_value)
, Bry_type = Bry_.new_a7(Str_type)
, Bry_error = Bry_.new_a7(Str_error)
;
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
.Add_bry_byte(Bry_value , Tid_value)
.Add_bry_byte(Bry_type , Tid_type)
.Add_bry_byte(Bry_error , Tid_error)
;
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_dict_langtext {
public static final byte
Tid_language = 0
, Tid_value = 1
;
public static final String
Str_language = "language"
, Str_value = "value"
;
public static byte[]
Bry_language = Bry_.new_a7(Str_language)
, Bry_value = Bry_.new_a7(Str_value)
;
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
.Add_bry_byte(Bry_language , Tid_language)
.Add_bry_byte(Bry_value , Tid_value)
;
}

View File

@@ -0,0 +1,46 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_dict_mainsnak {
public static final byte
Tid_snaktype = 0
, Tid_property = 1
, Tid_hash = 2
, Tid_datavalue = 3
, Tid_type = 4
, Tid_datatype = 5
;
public static final String
Str_datavalue = "datavalue";
public static byte[]
Bry_snaktype = Bry_.new_a7("snaktype")
, Bry_property = Bry_.new_a7("property")
, Bry_hash = Bry_.new_a7("hash")
, Bry_datavalue = Bry_.new_a7(Str_datavalue)
, Bry_type = Bry_.new_a7("type")
, Bry_datatype = Bry_.new_a7("datatype")
;
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
.Add_bry_byte(Bry_snaktype , Tid_snaktype)
.Add_bry_byte(Bry_property , Tid_property)
.Add_bry_byte(Bry_hash , Tid_hash)
.Add_bry_byte(Bry_datavalue , Tid_datavalue)
.Add_bry_byte(Bry_type , Tid_type)
.Add_bry_byte(Bry_datatype , Tid_datatype)
;
}

View File

@@ -0,0 +1,56 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_dict_reference {
public static final byte
Tid_hash = 0
, Tid_snaks = 1
, Tid_snaks_order = 2
;
public static final String
Str_hash = "hash"
, Str_snaks = "snaks"
, Str_snaks_order = "snaks-order"
;
public static final byte[]
Bry_hash = Bry_.new_a7(Str_hash)
, Bry_snaks = Bry_.new_a7(Str_snaks)
, Bry_snaks_order = Bry_.new_a7(Str_snaks_order)
;
public static Hash_adp_bry Dict = Hash_adp_bry.cs()
.Add_bry_byte(Bry_hash , Tid_hash)
.Add_bry_byte(Bry_snaks , Tid_snaks)
.Add_bry_byte(Bry_snaks_order , Tid_snaks_order)
;
public static String Xto_str(byte v) {
switch (v) {
case Tid_hash: return Str_hash;
case Tid_snaks: return Str_snaks;
case Tid_snaks_order: return Str_snaks_order;
default: throw Err_.new_unhandled(v);
}
}
public static byte[] Xto_bry(byte v) {
switch (v) {
case Tid_hash: return Bry_hash;
case Tid_snaks: return Bry_snaks;
case Tid_snaks_order: return Bry_snaks_order;
default: throw Err_.new_unhandled(v);
}
}
}

View File

@@ -0,0 +1,40 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_dict_sitelink {
public static final byte
Tid_site = 0
, Tid_title = 1
, Tid_badges = 2
;
public static final String
Str_site = "site"
, Str_title = "title"
, Str_badges = "badges"
;
public static byte[]
Bry_site = Bry_.new_a7(Str_site)
, Bry_title = Bry_.new_a7(Str_title)
, Bry_badges = Bry_.new_a7(Str_badges)
;
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
.Add_bry_byte(Bry_site , Tid_site)
.Add_bry_byte(Bry_title , Tid_title)
.Add_bry_byte(Bry_badges , Tid_badges)
;
}

View File

@@ -0,0 +1,30 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.primitives.*;
public class Wdata_dict_utl {
public static byte Get_tid_or_invalid(byte[] qid, Hash_adp_bry dict, byte[] key) {
Object rv_obj = dict.Get_by_bry(key);
if (rv_obj == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown wikidata key; qid=~{0} key=~{1}", String_.new_u8(qid), String_.new_u8(key));
return Tid_invalid;
}
return ((Byte_obj_val)rv_obj).Val();
}
public static final byte Tid_invalid = Byte_.Max_value_127;
}

View File

@@ -0,0 +1,22 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public interface Wdata_lang_sortable {
byte[] Lang_code();
int Lang_sort(); void Lang_sort_(int v);
}

View File

@@ -0,0 +1,83 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.apps.apis.xowa.xtns.*;
public class Wdata_lang_sorter implements Gfo_evt_itm, gplx.core.lists.ComparerAble {
private Hash_adp_bry hash = Hash_adp_bry.cs();
public Wdata_lang_sorter() {evt_mgr = new Gfo_evt_mgr(this);}
public Gfo_evt_mgr Evt_mgr() {return evt_mgr;} private Gfo_evt_mgr evt_mgr;
public byte[][] Langs() {return langs;} private byte[][] langs;
public void Langs_(byte[][] langs) {
this.langs = langs;
hash.Clear();
int len = langs.length;
for (int i = 0; i < len; ++i) {
byte[] lang = langs[i];
Wdata_lang_sorter_itm itm = new Wdata_lang_sorter_itm(i, lang);
hash.Add_if_dupe_use_1st(lang, itm);
}
}
public int compare(Object lhsObj, Object rhsObj) {
Wdata_lang_sortable lhs = (Wdata_lang_sortable)lhsObj;
Wdata_lang_sortable rhs = (Wdata_lang_sortable)rhsObj;
int lhs_lang_sort = lhs.Lang_sort(), rhs_lang_sort = rhs.Lang_sort();
if (lhs_lang_sort != Sort_none || rhs_lang_sort != Sort_none) // one of the items has a lang order
return Int_.Compare(lhs_lang_sort, rhs_lang_sort); // sort by defined lang order
else
return Bry_.Compare(lhs.Lang_code(), rhs.Lang_code()); // sort by alphabetical
}
public void Init_by_wdoc(Wdata_doc wdoc) {
if ((Bry_.Ary_eq(wdoc.Sort_langs(), langs))) return;
wdoc.Sort_langs_(langs);
Sort_wdoc_list(Bool_.Y, wdoc.Slink_list());
Sort_wdoc_list(Bool_.N, wdoc.Label_list());
Sort_wdoc_list(Bool_.N, wdoc.Descr_list());
Sort_wdoc_list(Bool_.N, wdoc.Alias_list());
}
private void Sort_wdoc_list(boolean is_slink, Ordered_hash list) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Wdata_lang_sortable itm = (Wdata_lang_sortable)list.Get_at(i);
if (is_slink) {
Wdata_sitelink_itm slink = (Wdata_sitelink_itm)itm;
byte[] lang_val = slink.Domain_info().Lang_orig_key(); // use orig, not cur; EX: simplewiki has orig of "simple" but lang of "en"
if (Bry_.Len_eq_0(lang_val)) lang_val = slink.Site(); // unknown lang; EX: "xyzwiki" -> ""; make site = lang, else "" lang will sort towards top of list; PAGE:wd.q:20 DATE:2014-10-03
slink.Lang_(lang_val);
}
itm.Lang_sort_(Sort_calc(itm));
}
}
private int Sort_calc(Wdata_lang_sortable data_itm) {
Wdata_lang_sorter_itm sort_itm = (Wdata_lang_sorter_itm)hash.Get_by(data_itm.Lang_code());
int new_sort = sort_itm == null ? Sort_none : sort_itm.Sort();
data_itm.Lang_sort_(new_sort);
return new_sort;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Xoapi_wikibase.Evt_sort_langs_changed)) Langs_((byte[][])m.ReadObj("v", null));
else return Gfo_invk_.Rv_unhandled;
return this;
}
public static final int Sort_null = Int_.Min_value;
private static final int Sort_none = Int_.Max_value;
}
class Wdata_lang_sorter_itm {
public Wdata_lang_sorter_itm(int sort, byte[] lang) {this.sort = sort; this.lang = lang;}
public int Sort() {return sort;} private final int sort;
public byte[] Lang() {return lang;} private final byte[] lang;
}

View File

@@ -0,0 +1,42 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*;
public class Wdata_langtext_itm implements Wdata_lang_sortable {
public Wdata_langtext_itm(byte[] lang, byte[] text) {this.lang = lang; this.text = text;}
public byte[] Lang() {return lang;} private final byte[] lang;
public byte[] Text() {return text;} private final byte[] text;
public byte[] Lang_code() {return lang;}
public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null;
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", String_.new_u8(lang), String_.new_u8(text));
}
public static byte[] Get_text_or_empty(Ordered_hash list, byte[][] langs) {
Wdata_langtext_itm itm = Get_itm_or_null(list, langs);
return itm == null ? Bry_.Empty : itm.Text();
}
public static Wdata_langtext_itm Get_itm_or_null(Ordered_hash list, byte[][] langs) {
if (list == null) return null;
int langs_len = langs.length;
for (int i = 0; i < langs_len; ++i) {
Object itm_obj = list.Get_by(langs[i]);
if (itm_obj != null) return (Wdata_langtext_itm)itm_obj;
}
return null;
}
}

View File

@@ -0,0 +1,34 @@
/*
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.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*;
import gplx.xowa.wikis.domains.*;
public class Wdata_sitelink_itm implements Wdata_lang_sortable {
public Wdata_sitelink_itm(byte[] site, byte[] name, byte[][] badges) {this.site = site; this.name = name; this.badges = badges;}
public byte[] Site() {return site;} private final byte[] site;
public byte[] Name() {return name;} private final byte[] name;
public byte[][] Badges() {return badges;} private final byte[][] badges;
public byte[] Lang() {return lang;} public void Lang_(byte[] v) {lang = v;} private byte[] lang = Bry_.Empty;
public byte[] Lang_code() {return lang;}
public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null;
public Xow_domain_itm Domain_info() {if (domain_info == null) domain_info = Xow_abrv_wm_.Parse_to_domain_itm(site); return domain_info;} private Xow_domain_itm domain_info;
public Xoa_ttl Page_ttl() {return page_ttl;} public Wdata_sitelink_itm Page_ttl_(Xoa_ttl v) {page_ttl = v; return this;} private Xoa_ttl page_ttl; // PERF: cache title to avoid creating new Object for "In Other langs"; DATE:2014-10-20
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", String_.new_u8(site), String_.new_u8(name), String_.Concat_with_str(",", String_.Ary(badges)));
}
}

View File

@@ -0,0 +1,287 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
import gplx.xowa.apps.apis.xowa.html.*;
class Wdata_fmtr__claim_grp implements gplx.core.brys.Bfr_arg {
private Wdata_fmtr__claim_tbl fmtr_tbl = new Wdata_fmtr__claim_tbl(); private boolean is_empty;
private Xoapi_toggle_itm toggle_itm;
private Wdata_toc_data toc_data;
public void Init_by_ctor(Wdata_toc_data toc_data, Xoapi_toggle_mgr toggle_mgr, Wdata_lbl_mgr lbl_mgr) {this.toc_data = toc_data; this.toggle_itm = toggle_mgr.Get_or_new("wikidatawiki-claim"); fmtr_tbl.Init_by_ctor(lbl_mgr);}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
toc_data.Orig_(msgs.Claim_tbl_hdr());
toggle_itm.Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n());
fmtr_tbl.Init_by_lang(msgs);
}
public void Init_by_wdoc(byte[] ttl, Ordered_hash list) {
int list_count = list.Count();
this.is_empty = list.Count() == 0; if (is_empty) return;
toc_data.Make(list_count);
fmtr_tbl.Init_by_wdoc(ttl, list);
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (is_empty) return;
fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), fmtr_tbl);
}
private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <h2 class='wb-section-heading' dir='auto' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
, " <div class='wb-claimlistview'~{toggle_hdr}>"
, " <div class='wikibase-statementgrouplistview'>"
, " <div class='wikibase-listview'>~{tbls}"
, " </div>"
, " </div>"
, " </div>"
), "hdr_href", "hdr_text", "toggle_btn", "toggle_hdr", "tbls");
}
class Wdata_fmtr__claim_tbl implements gplx.core.brys.Bfr_arg {
private Wdata_fmtr__claim_row fmtr_row = new Wdata_fmtr__claim_row(); private Wdata_lbl_mgr lbl_mgr;
private Ordered_hash list; private byte[] ttl;
public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr; fmtr_row.Init_by_ctor(lbl_mgr);}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
fmtr_row.Init_by_lang(msgs);
}
public void Init_by_wdoc(byte[] ttl, Ordered_hash list) {
this.list = list;
this.ttl = ttl;
}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Wbase_claim_grp grp = (Wbase_claim_grp)list.Get_at(i);
if (grp.Len() == 0) continue; // NOTE: group will be empty when claims are empty; EX: "claims": []; PAGE:wd.p:585; DATE:2014-10-03
int pid = grp.Id();
byte[] pid_lbl = lbl_mgr.Get_text__pid(pid);
fmtr_row.Init_by_grp(ttl, grp);
fmtr.Bld_bfr_many(bfr, pid, pid_lbl, fmtr_row);
}
}
private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div id='P~{pid}' class='wikibase-statementgroupview'>"
, " <div class='wikibase-statementgroupview-property'>"
, " <div class='wikibase-statementgroupview-property-label' dir='auto'>"
, " P~{pid}&nbsp;-&nbsp;<a href='/wiki/Property:P~{pid}' title='Property:P~{pid}'>~{pid_lbl}</a>"
, " </div>"
, " </div>~{itms}"
, " </div>"
), "pid", "pid_lbl", "itms");
}
class Wdata_fmtr__claim_row implements gplx.core.brys.Bfr_arg {
private byte[] ttl;
private Wdata_visitor__html_wtr claim_html_wtr = new Wdata_visitor__html_wtr();
private Wdata_fmtr__qual_tbl fmtr_qual = new Wdata_fmtr__qual_tbl();
private Wdata_fmtr__ref_tbl fmtr_ref = new Wdata_fmtr__ref_tbl();
private Wdata_lbl_mgr lbl_mgr; private Wdata_hwtr_msgs msgs;
private Wbase_claim_grp claim_grp; private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {
this.lbl_mgr = lbl_mgr;
fmtr_qual.Init_by_ctor(lbl_mgr);
fmtr_ref.Init_by_ctor(lbl_mgr);
}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
this.msgs = msgs;
fmtr_qual.Init_by_lang(msgs);
fmtr_ref.Init_by_lang(msgs);
}
public void Init_by_grp(byte[] ttl, Wbase_claim_grp claim_grp) {
this.ttl = ttl; this.claim_grp = claim_grp;
}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = claim_grp.Len();
claim_html_wtr.Init(ttl, tmp_bfr, msgs, lbl_mgr);
for (int i = 0; i < len; ++i) {
Wbase_claim_base itm = claim_grp.Get_at(i);
itm.Welcome(claim_html_wtr);
byte[] val = tmp_bfr.To_bry_and_clear();
fmtr_qual.Init_by_claim(ttl, itm);
fmtr_ref.Init_by_claim(ttl, itm);
row_fmtr.Bld_bfr_many(bfr, Wbase_claim_rank_.To_str_or_fail(itm.Rank_tid()), val, fmtr_qual, fmtr_ref);
}
}
private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-statementlistview'>"
, " <div class='wikibase-statementlistview-listview'>"
, " <div class='wikibase-statementview wikibase-statement'>"
, " <div class='wikibase-statementview-rankselector'>"
, " <div class='wikibase-rankselector ui-state-disabled'>"
, " <span class='ui-icon ui-icon-rankselector wikibase-rankselector-~{rank_name}' title='~{rank_name} rank'/>"
, " </div>"
, " </div>"
, " <div class='wikibase-statementview-mainsnak-container'>" // omit -Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e
, " <div class='wikibase-statementview-mainsnak' dir='auto'>"
, " <div class='wikibase-snakview'>"
, " <div class='wikibase-snakview-property-container'>"
, " <div class='wikibase-snakview-property' dir='auto'></div>"
, " </div>"
, " <div class='wikibase-snakview-value-container' dir='auto'>"
, " <div class='wikibase-snakview-typeselector'></div>"
, " <div class='wikibase-snakview-value wikibase-snakview-variation-valuesnak'>~{value}"
, " </div>"
, " </div>"
, " </div>"
, " </div>~{qualifiers}"
, " </div>~{references}"
, " </div>"
, " </div>"
, " </div>"
), "rank_name", "value", "qualifiers", "references"
);
}
class Wdata_fmtr__qual_tbl implements gplx.core.brys.Bfr_arg {
private Wdata_fmtr__qual_row fmtr_row = new Wdata_fmtr__qual_row(); private Wbase_claim_base claim;
public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {fmtr_row.Init_by_ctor(lbl_mgr);}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
fmtr_row.Init_by_lang(msgs);
}
public void Init_by_claim(byte[] ttl, Wbase_claim_base claim) {
this.claim = claim;
fmtr_row.Init_by_grp(ttl, claim.Qualifiers());
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (claim.Qualifiers() == null || claim.Qualifiers().Len() == 0) return;
fmtr.Bld_bfr_many(bfr, fmtr_row);
}
private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-statementview-qualifiers'>"
, " <div class='wikibase-listview'>~{itms}"
, " </div>"
, " </div>"
), "itms");
}
class Wdata_fmtr__qual_row implements gplx.core.brys.Bfr_arg {
private byte[] ttl; private Wdata_visitor__html_wtr claim_html_wtr = new Wdata_visitor__html_wtr();
private Wdata_lbl_mgr lbl_mgr; private Wdata_hwtr_msgs msgs;
private Wbase_claim_grp_list quals; private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr;}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.msgs = msgs;}
public void Init_by_grp(byte[] ttl, Wbase_claim_grp_list quals) {this.ttl = ttl; this.quals = quals;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = quals.Len();
claim_html_wtr.Init(ttl, tmp_bfr, msgs, lbl_mgr);
for (int i = 0; i < len; ++i) {
Wbase_claim_grp grp = quals.Get_at(i);
int grp_len = grp.Len();
for (int j = 0; j < grp_len; ++j) {
Wbase_claim_base itm = grp.Get_at(j);
itm.Welcome(claim_html_wtr);
byte[] val = tmp_bfr.To_bry_and_clear();
row_fmtr.Bld_bfr_many(bfr, grp.Id(), lbl_mgr.Get_text__pid(grp.Id()), val);
}
}
}
private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-snaklistview'>"
, " <div class='wikibase-snaklistview-listview'>"
, " <div class='wikibase-snakview'>"
, " <div class='wikibase-snakview-property-container'>"
, " <div class='wikibase-snakview-property' dir='auto'>"
, " <a href='/wiki/Property:P~{pid}' title='Property:P~{pid}'>~{pid_lbl}</a>"
, " </div>"
, " </div>"
, " <div class='wikibase-snakview-value-container' dir='auto'>"
, " <div class='wikibase-snakview-typeselector'></div>"
, " <div class='wikibase-snakview-value wikibase-snakview-variation-valuesnak'>~{value}"
, " </div>"
, " </div>"
, " </div>"
, " </div>"
, " </div>"
), "pid", "pid_lbl", "value"
);
}
class Wdata_fmtr__ref_tbl implements gplx.core.brys.Bfr_arg {
private Wdata_fmtr__ref_row fmtr_row = new Wdata_fmtr__ref_row(); private Wbase_claim_base claim;
public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {fmtr_row.Init_by_ctor(lbl_mgr);}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
fmtr_row.Init_by_lang(msgs);
}
public void Init_by_claim(byte[] ttl, Wbase_claim_base claim) {
this.claim = claim;
fmtr_row.Init_by_grp(ttl, claim.References());
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (claim.References() == null) return;
fmtr.Bld_bfr_many(bfr, fmtr_row);
}
private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
// , " <div class='wb-statement-references-heading'>1 reference</div>"
, " <div class='wikibase-statementview-references'>"
, " <div class='wikibase-listview'>"
, " <div class='wikibase-referenceview'>" // OMIT: wb-referenceview-8e7d51e38606193465d2a1e9d41ba490e06682a6
, " <div class='wikibase-referenceview-heading'></div>"
, " <div class='wikibase-referenceview-listview'>"
, " <div class='wikibase-snaklistview'>"
, " <div class='wikibase-snaklistview-listview'>~{itms}"
, " </div>"
, " </div>"
, " </div>"
, " </div>"
, " </div>"
, " </div>"
), "itms");
}
class Wdata_fmtr__ref_row implements gplx.core.brys.Bfr_arg {
private byte[] ttl; private Wdata_visitor__html_wtr claim_html_wtr = new Wdata_visitor__html_wtr();
private Wdata_lbl_mgr lbl_mgr; private Wdata_hwtr_msgs msgs;
private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
private Wbase_references_grp[] ref_grps;
public void Init_by_ctor(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr;}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.msgs = msgs;}
public void Init_by_grp(byte[] ttl, Wbase_references_grp[] ref_grps) {this.ttl = ttl; this.ref_grps = ref_grps;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = ref_grps.length;
claim_html_wtr.Init(ttl, tmp_bfr, msgs, lbl_mgr);
for (int i = 0; i < len; ++i) {
Wbase_references_grp grp_itm = ref_grps[i];
Wbase_claim_grp_list grp = grp_itm.References();
int grp_len = grp.Len();
for (int j = 0; j < grp_len; ++j) {
Wbase_claim_grp grp2 = grp.Get_at(j);
int grp2_len = grp2.Len();
for (int k = 0; k < grp2_len; ++k) {
Wbase_claim_base itm = grp2.Get_at(k);
itm.Welcome(claim_html_wtr);
byte[] val = tmp_bfr.To_bry_and_clear();
row_fmtr.Bld_bfr_many(bfr, grp2.Id(), lbl_mgr.Get_text__pid(grp2.Id()), val);
}
}
}
}
private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-snakview'>"
, " <div class='wikibase-snakview-property-container'>"
, " <div class='wikibase-snakview-property' dir='auto'>"
, " <a href='/wiki/Property:~{pid}' title='Property:~{pid}'>~{pid_lbl}</a>"
, " </div>"
, " </div>"
, " <div class='wikibase-snakview-value-container' dir='auto'>"
, " <div class='wikibase-snakview-typeselector'></div>"
, " <div class='wikibase-snakview-value wikibase-snakview-variation-valuesnak'>~{value}"
, " </div>"
, " </div>"
, " </div>"
), "pid", "pid_lbl", "value"
);
}

View File

@@ -0,0 +1,49 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.jsons.*; import gplx.xowa.htmls.*; import gplx.xowa.apps.apis.xowa.html.*;
class Wdata_fmtr__json implements gplx.core.brys.Bfr_arg {
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
private Xoapi_toggle_itm toggle_itm; private Wdata_toc_data toc_data; private Json_doc jdoc;
public void Init_by_ctor(Wdata_toc_data toc_data, Xoapi_toggle_mgr toggle_mgr) {
this.toc_data = toc_data.Itms_len_enable_n_();
this.toggle_itm = toggle_mgr.Get_or_new("wikidatawiki-json").Html_toggle_hdr_cls_(Bry_.new_a7("overflow:auto;"));
}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
toc_data.Orig_(msgs.Json_div_hdr());
toggle_itm.Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n());
}
public void Init_by_wdoc(Json_doc jdoc) {
this.jdoc = jdoc;
toc_data.Make(0);
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (jdoc == null) return; // TEST: wdoc doesn't have jdoc
jdoc.Root_nde().Print_as_json(tmp_bfr, 0);
fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), tmp_bfr.To_bry_and_clear());
}
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <h2 class='wb-section-heading' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
, " <div class='visualClear'></div>"
, " <pre~{toggle_hdr}>~{json}"
, " </pre>"
, " </div>"
), "hdr_href", "hdr_text", "toggle_btn", "toggle_hdr", "json");
}

View File

@@ -0,0 +1,129 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*;
import gplx.xowa.langs.*; import gplx.xowa.wikis.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.apps.apis.xowa.html.*;
class Wdata_fmtr__langtext_tbl implements gplx.core.brys.Bfr_arg {
private Wdata_toc_data toc_data; private Wdata_lang_sorter lang_sorter; private Xoapi_toggle_itm toggle_itm; private Wdata_fmtr__langtext_row fmtr_row;
private byte[] col_hdr_lang_name, col_hdr_lang_code, col_hdr_text; private int list_len;
public void Init_by_ctor(Wdata_toc_data toc_data, Wdata_lang_sorter lang_sorter, Xoapi_toggle_mgr toggle_mgr, String toggle_itm_key, Wdata_fmtr__langtext_row fmtr_row) {
this.toc_data = toc_data; this.lang_sorter = lang_sorter; this.fmtr_row = fmtr_row;
this.toggle_itm = toggle_mgr.Get_or_new(toggle_itm_key);
}
public void Init_by_lang(Wdata_hwtr_msgs msgs, byte[] tbl_hdr, byte[] col_hdr_text) {
this.col_hdr_lang_name = msgs.Langtext_col_lang_name(); this.col_hdr_lang_code = msgs.Langtext_col_lang_code(); this.col_hdr_text = col_hdr_text;
toc_data.Orig_(tbl_hdr);
toggle_itm.Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n());
}
public void Init_by_wdoc(Ordered_hash list) {
this.list_len = list.Count(); if (list_len == 0) return;
toc_data.Make(list_len);
list.Sort_by(lang_sorter);
fmtr_row.Init_by_page(list);
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (list_len == 0) return;
fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), col_hdr_lang_name, col_hdr_lang_code, col_hdr_text, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), fmtr_row);
}
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-sitelinkgroupview'>"
, " <div class='wikibase-sitelinkgroupview-heading-container'>"
, " <h2 class='wb-section-heading wikibase-sitelinkgroupview-heading' dir='auto' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
, " </div>"
, " <div class='wikibase-sitelinklistview'~{toggle_hdr}>"
, " <ul class='wikibase-sitelinklistview-listview'>~{rows}"
, " </ul>"
, " </div>"
, " </div>"
), "hdr_href", "hdr_text", "hdr_lang_name", "hdr_lang_code", "hdr_page", "toggle_btn", "toggle_hdr", "rows"
);
}
interface Wdata_fmtr__langtext_row extends gplx.core.brys.Bfr_arg {
void Init_by_page(Ordered_hash list);
}
class Wdata_fmtr__langtext_row_base implements gplx.core.brys.Bfr_arg, Wdata_fmtr__langtext_row {
private Ordered_hash list;
public void Init_by_page(Ordered_hash list) {this.list = list;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Wdata_langtext_itm itm = (Wdata_langtext_itm)list.Get_at(i);
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_intl(itm.Lang());
row_fmtr.Bld_bfr_many(bfr, itm.Lang(), Gfh_utl.Escape_html_as_bry(lang_itm.Canonical_name()), Gfh_utl.Escape_html_as_bry(itm.Text()));
}
}
private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li class='wikibase-sitelinkview'>"
, " <span class='wikibase-sitelinkview-siteid-container'>"
, " <span class='wikibase-sitelinkview-siteid'>~{lang_code}</span>"
, " </span>"
, " <span class='wikibase-sitelinkview-link' lang='~{lang_code}' dir='auto'>~{text}</span>"
, " </li>"
), "lang_code", "lang_name", "text"
);
// , " <li class='wikibase-sitelinkview'>" // wikibase-sitelinkview-~{wmf_key} data-wb-siteid='~{wmf_key}'
// , " <span class='wikibase-sitelinkview-siteid-container'>"
// , " <span class='wikibase-sitelinkview-siteid'>~{wmf_key}"
// , " </span>"
// , " </span>"
// , " <span class='wikibase-sitelinkview-link' lang='~{lang_code}' dir='auto'>" // wikibase-sitelinkview-link-~{wmf_key}
// , " <span class='wikibase-sitelinkview-page'>"
// , " <a href='~{href_site}~{href_domain}/wiki/~{href_page}' hreflang='~{lang_code}' dir='auto'>~{page_name}</a>"
// , " </span>"
// , " <span class='wikibase-badgeselector wikibase-sitelinkview-badges'>~{badges}"
// , " </span>"
// , " </span>"
// , " </li>"
}
class Wdata_fmtr__alias_row implements gplx.core.brys.Bfr_arg, Wdata_fmtr__langtext_row {
private Ordered_hash list;
public void Init_by_page(Ordered_hash list) {this.list = list;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Wdata_alias_itm itm = (Wdata_alias_itm)list.Get_at(i);
byte[][] vals_ary = itm.Vals();
int vals_len = vals_ary.length;
for (int j = 0; j < vals_len; ++j) {
byte[] val = vals_ary[j];
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_intl(itm.Lang());
byte[] lang_code = Byte_ascii.Dash_bry;
byte[] lang_code_style = lang_code_style_n;
if (j == 0) {
lang_code = lang_itm.Key();
lang_code_style = Bry_.Empty;
}
row_fmtr.Bld_bfr_many(bfr, lang_code, lang_code_style, Gfh_utl.Escape_html_as_bry(val));
}
}
}
private static final byte[] lang_code_style_n = Bry_.new_a7("border:1px solid white;background:none;");
private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li class='wikibase-sitelinkview'>"
, " <span class='wikibase-sitelinkview-siteid-container' style='~{lang_code_style}>"
, " <span class='wikibase-sitelinkview-siteid''>~{lang_code}</span>"
, " </span>"
, " <span class='wikibase-sitelinkview-link' lang='~{lang_code}' dir='auto'>~{text}</span>"
, " </li>"
), "lang_code", "lang_code_style", "text"
);
}

View File

@@ -0,0 +1,94 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.apps.apis.xowa.xtns.*;
class Wdata_fmtr__oview_tbl implements gplx.core.brys.Bfr_arg {
private Xoapi_wikibase wikibase_api; private Gfo_url_encoder href_encoder;
private Wdata_fmtr__oview_alias_itm fmtr_aliases = new Wdata_fmtr__oview_alias_itm();
private Bry_fmtr slink_fmtr = Bry_fmtr.new_("<a href='/site/~{domain_bry}/wiki/~{page_href}'>~{page_text}</a>", "domain_bry", "page_href", "page_text");
private Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(255);
private Wdata_doc wdoc;
private byte[] hdr_alias_y, hdr_alias_n;
public void Init_by_ctor(Xoapi_wikibase wikibase_api, Gfo_url_encoder href_encoder) {this.wikibase_api = wikibase_api; this.href_encoder = href_encoder;}
public void Init_by_lang(byte[] lang_0, Wdata_hwtr_msgs msgs) {
this.hdr_alias_y = msgs.Oview_alias_y();
this.hdr_alias_n = msgs.Oview_alias_n();
}
public void Init_by_wdoc(Wdata_doc wdoc) {
this.wdoc = wdoc;
}
public void Bfr_arg__add(Bry_bfr bfr) {
byte[][] core_langs = wikibase_api.Core_langs();
byte[] oview_label = Wdata_langtext_itm.Get_text_or_empty(wdoc.Label_list(), core_langs);
byte[] oview_descr = Wdata_langtext_itm.Get_text_or_empty(wdoc.Descr_list(), core_langs);
byte[][] oview_alias = Alias_get_or_empty(wdoc.Alias_list(), core_langs);
byte[] aliases_hdr = oview_alias == Bry_.Ary_empty ? hdr_alias_n : hdr_alias_y;
fmtr_aliases.Init_by_itm(oview_alias);
Wdata_sitelink_itm slink = (Wdata_sitelink_itm)wdoc.Slink_list().Get_by(wikibase_api.Link_wikis());
if (slink != null) {
oview_label = slink_fmtr.Bld_bry_many(tmp_bfr, slink.Domain_info().Domain_bry(), href_encoder.Encode(slink.Name()), oview_label);
}
row_fmtr.Bld_bfr_many(bfr, wdoc.Qid(), oview_label, oview_descr, aliases_hdr, fmtr_aliases);
}
private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-entitytermsview'>"
, " <div class='wikibase-entitytermsview-heading'>"
, " <h1 class='wikibase-entitytermsview-heading-label'>~{ttl_label}"
, " <span class='wikibase-entitytermsview-heading-label-id'>(~{ttl})</span>"
, " </h1>"
, " <div class='wikibase-entitytermsview-heading-description '>~{ttl_descr}"
, " </div>"
, " <div class='wikibase-entitytermsview-heading-aliases'>"
, " <ul class='wikibase-entitytermsview-aliases'>~{ttl_aliases}"
, " </ul>"
, " </div>"
, " </div>"
, " </div>"
), "ttl", "ttl_label", "ttl_descr", "hdr_aliases", "ttl_aliases"
);
private static byte[][] Alias_get_or_empty(Ordered_hash list, byte[][] langs) {
if (list == null) return Bry_.Ary_empty;
int langs_len = langs.length;
for (int i = 0; i < langs_len; ++i) {
Object itm_obj = list.Get_by(langs[i]);
if (itm_obj != null) {
Wdata_alias_itm itm = (Wdata_alias_itm)itm_obj;
return itm.Vals();
}
}
return Bry_.Ary_empty;
}
}
class Wdata_fmtr__oview_alias_itm implements gplx.core.brys.Bfr_arg {
private byte[][] ary;
public void Init_by_itm(byte[][] ary) {this.ary = ary;}
public void Bfr_arg__add(Bry_bfr bfr) {
if (ary == null) return;
int len = ary.length;
for (int i = 0; i < len; ++i)
row_fmtr.Bld_bfr_many(bfr, ary[i]);
}
private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li class='wikibase-entitytermsview-aliases-alias'>~{itm}</li>"
), "itm"
);
}

View File

@@ -0,0 +1,166 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.encoders.*; import gplx.langs.htmls.*;
import gplx.xowa.langs.*; import gplx.xowa.xtns.wbases.core.*;
import gplx.xowa.wikis.domains.*; import gplx.xowa.apps.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*;
class Wdata_fmtr__slink_grp implements gplx.core.brys.Bfr_arg {
private final Wdata_fmtr__slink_tbl fmtr_tbl = new Wdata_fmtr__slink_tbl(); private boolean is_empty;
public void Init_by_ctor(Wdata_lang_sorter lang_sorter, Xoapi_toggle_mgr toggle_mgr, Wdata_lbl_mgr lbl_regy, Gfo_url_encoder href_encoder, Wdata_fmtr__toc_div fmtr_toc, Xow_xwiki_mgr xwiki_mgr) {
fmtr_tbl.Init_by_ctor(lang_sorter, toggle_mgr, lbl_regy, href_encoder, fmtr_toc, xwiki_mgr);
}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {fmtr_tbl.Init_by_lang(msgs);}
public void Init_by_wdoc(Ordered_hash list) {
this.is_empty = list.Count() == 0; if (is_empty) return;
fmtr_tbl.Init_by_wdoc(list);
}
public void Bfr_arg__add(Bry_bfr bfr) {
if (is_empty) return;
fmtr.Bld_bfr_many(bfr, fmtr_tbl);
}
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-sitelinkgrouplistview'>"
, " <div class='wb-listview'>~{grps}"
, " </div>"
, " </div>"
), "grps"
);
}
class Wdata_fmtr__slink_tbl implements gplx.core.brys.Bfr_arg {
private final Wdata_fmtr__slink_row fmtr_row = new Wdata_fmtr__slink_row();
private final Wdata_slink_grp[] grps = new Wdata_slink_grp[Wdata_slink_grp.Idx__len];
private Wdata_lang_sorter lang_sorter; private Wdata_hwtr_msgs msgs;
public void Init_by_ctor(Wdata_lang_sorter lang_sorter, Xoapi_toggle_mgr toggle_mgr, Wdata_lbl_mgr lbl_regy, Gfo_url_encoder href_encoder, Wdata_fmtr__toc_div fmtr_toc, Xow_xwiki_mgr xwiki_mgr) {
this.lang_sorter = lang_sorter;
fmtr_row.Init_by_ctor(lbl_regy, href_encoder, xwiki_mgr);
for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) {
byte[] wiki_name = Wdata_slink_grp.Name_by_tid(i);
String toggle_itm_key = "wikidatawiki-slink-" + String_.new_a7(wiki_name);
Xoapi_toggle_itm toggle_itm = toggle_mgr.Get_or_new(toggle_itm_key);
Wdata_toc_data toc_data = new Wdata_toc_data(fmtr_toc, href_encoder);
grps[i] = new Wdata_slink_grp(i, wiki_name, toggle_itm, toc_data);
}
}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
this.msgs = msgs;
for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) {
Wdata_slink_grp grp = grps[i];
grp.Toc_data().Orig_(Wdata_slink_grp.Msg_by_tid(msgs, i));
grp.Toggle_itm().Init_msgs(msgs.Toggle_title_y(), msgs.Toggle_title_n());
}
}
public void Init_by_wdoc(Ordered_hash list) {
Wdata_slink_grp.Sift(grps, list);
for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) {
Wdata_slink_grp grp = grps[i];
int itms_count = grp.Rows().Count();
if (itms_count == 0) continue;
grp.Toc_data().Make(itms_count);
grp.Rows().Sort_by(lang_sorter);
}
}
public void Bfr_arg__add(Bry_bfr bfr) {
for (int i = 0; i < Wdata_slink_grp.Idx__len; ++i) {
Wdata_slink_grp grp = grps[i];
if (grp.Rows().Count() == 0) continue;
fmtr_row.Init_by_page(grp.Rows());
Xoapi_toggle_itm toggle_itm = grp.Toggle_itm();
fmtr.Bld_bfr_many(bfr, grp.Toc_data().Href(), grp.Toc_data().Text(), msgs.Langtext_col_lang_name(), msgs.Langtext_col_lang_code(), msgs.Slink_col_hdr_text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), fmtr_row);
}
}
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-sitelinkgroupview' data-wb-sitelinks-group='wikipedia'>"
, " <div class='wikibase-sitelinkgroupview-heading-container'>"
, " <h2 class='wb-section-heading wikibase-sitelinkgroupview-heading' dir='auto' id='~{hdr_href}'>~{hdr_text}~{toggle_btn}</h2>"
, " </div>"
, " <div class='wikibase-sitelinklistview'~{toggle_hdr}>"
, " <ul class='wikibase-sitelinklistview-listview'>~{rows}"
, " </ul>"
, " </div>"
, " </div>"
), "hdr_href", "hdr_text", "hdr_lang", "hdr_wiki", "hdr_page", "toggle_btn", "toggle_hdr", "rows"
);
}
class Wdata_fmtr__slink_row implements gplx.core.brys.Bfr_arg {
private final Wdata_fmtr__slink_badges fmtr_badges = new Wdata_fmtr__slink_badges(); private Xow_xwiki_mgr xwiki_mgr;
private Gfo_url_encoder href_encoder; private Ordered_hash list;
public void Init_by_ctor(Wdata_lbl_mgr lbl_regy, Gfo_url_encoder href_encoder, Xow_xwiki_mgr xwiki_mgr) {
this.href_encoder = href_encoder; this.xwiki_mgr = xwiki_mgr;
fmtr_badges.Init_by_ctor(lbl_regy);
}
public void Init_by_page(Ordered_hash list) {this.list = list;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.Get_at(i);
Xow_domain_itm domain_info = itm.Domain_info();
byte[] wmf_key = domain_info.Abrv_wm();
Xol_lang_stub lang_itm = domain_info.Lang_actl_itm();
byte[] lang_key = lang_itm.Key();
byte[] lang_name = lang_itm.Canonical_name();
byte[] domain_bry = domain_info.Domain_bry();
byte[] page_name = itm.Name();
fmtr_badges.Init_by_itm(itm.Badges());
byte[] href_site = xwiki_mgr.Get_by_key(domain_bry) == null ? Href_site_http : Href_site_xowa;
fmtr_row.Bld_bfr_many(bfr, lang_name, lang_key, wmf_key, href_site, domain_bry, href_encoder.Encode(page_name), Gfh_utl.Escape_html_as_bry(itm.Name()), fmtr_badges);
}
}
private static final byte[] Href_site_xowa = Bry_.new_a7("/site/"), Href_site_http = Bry_.new_a7("https://");
private final Bry_fmtr fmtr_row = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li class='wikibase-sitelinkview'>" // wikibase-sitelinkview-~{wmf_key} data-wb-siteid='~{wmf_key}'
, " <span class='wikibase-sitelinkview-siteid-container'>"
, " <span class='wikibase-sitelinkview-siteid'>~{lang_code}"
, " </span>"
, " </span>"
, " <span class='wikibase-sitelinkview-link' lang='~{lang_code}' dir='auto'>" // wikibase-sitelinkview-link-~{wmf_key}
, " <span class='wikibase-sitelinkview-page'>"
, " <a href='~{href_site}~{href_domain}/wiki/~{href_page}' hreflang='~{lang_code}' dir='auto'>~{page_name}</a>"
, " </span>"
, " <span class='wikibase-badgeselector wikibase-sitelinkview-badges'>~{badges}"
, " </span>"
, " </span>"
, " </li>"
), "lang_name", "lang_code", "wmf_key", "href_site", "href_domain", "href_page", "page_name", "badges"
);
}
class Wdata_fmtr__slink_badges implements gplx.core.brys.Bfr_arg {
private Wdata_lbl_mgr lbl_regy; private byte[][] badges;
public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {this.lbl_regy = lbl_regy;}
public void Init_by_itm(byte[][] badges) {this.badges = badges;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = badges.length;
for (int i = 0; i < len; ++i) {
byte[] ttl = badges[i];
Wdata_lbl_itm lbl = lbl_regy.Get_itm__ttl(ttl);
byte[] name = Bry_.Empty, cls = Bry_.Empty;
if (lbl != null) {
name = lbl.Text();
cls = Bry_.Replace(lbl.Text_en(), Byte_ascii.Space_bry, Bry_.Empty); // NOTE: use Text_en; "featured article" -> "featuredarticle"; same for "good article" -> "goodarticle"
}
fmtr_row.Bld_bfr_many(bfr, ttl, cls, name);
}
}
private final Bry_fmtr fmtr_row = Bry_fmtr.new_
( "\n <span class='wb-badge wb-badge-~{ttl} wb-badge-~{cls}' title='~{name}'></span>"
, "ttl", "cls", "name"
);
}

View File

@@ -0,0 +1,63 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.wikis.pages.wtxts.*;
class Wdata_fmtr__toc_div implements gplx.core.brys.Bfr_arg {
private final List_adp itms = List_adp_.New(); private final Wdata_fmtr__toc_itm fmtr_itm = new Wdata_fmtr__toc_itm();
private byte[] tbl_hdr;
public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.tbl_hdr = msgs.Toc_tbl_hdr();}
public void Init_by_wdoc(Wdata_doc wdoc) {itms.Clear();}
public void Add(Wdata_toc_data toc_data) {itms.Add(toc_data);}
public void Bfr_arg__add(Bry_bfr bfr) {
int itms_len = itms.Count();
if (itms_len <= Xopg_toc_mgr.Hdrs_min) return;
fmtr_itm.Init_by_itm((Wdata_toc_data[])itms.To_ary_and_clear(Wdata_toc_data.class));
fmtr.Bld_bfr_many(bfr, tbl_hdr, fmtr_itm);
}
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div id='toc' class='toc wb-toc'>"
, " <div id='toctitle'>"
, " <h2>~{hdr}</h2>"
, " </div>"
, " <ul>~{itms}"
, " </ul>"
, " </div>"
), "hdr", "itms");
}
class Wdata_fmtr__toc_itm implements gplx.core.brys.Bfr_arg {
private Wdata_toc_data[] ary;
public void Init_by_itm(Wdata_toc_data[] v) {this.ary = v;}
public void Bfr_arg__add(Bry_bfr bfr) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Wdata_toc_data itm = ary[i];
fmtr.Bld_bfr_many(bfr, i + List_adp_.Base1, itm.Href(), itm.Text());
}
}
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li class='toclevel-1 tocsection-~{idx}'>"
, " <a href='#~{href}'>"
, " <span class='toctext'>~{text}</span>"
, " </a>"
, " </li>"
), "idx", "href", "text");
}

View File

@@ -0,0 +1,95 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.apps.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apps.apis.xowa.xtns.*;
public class Wdata_hwtr_mgr {
private final Bry_bfr bfr = Bry_bfr_.Reset(Io_mgr.Len_mb);
@gplx.Internal protected Wdata_fmtr__toc_div Fmtr_toc() {return fmtr_toc;} private final Wdata_fmtr__toc_div fmtr_toc = new Wdata_fmtr__toc_div();
@gplx.Internal protected Wdata_fmtr__json Fmtr_json() {return fmtr_json;} private final Wdata_fmtr__json fmtr_json = new Wdata_fmtr__json();
@gplx.Internal protected Wdata_fmtr__claim_grp Fmtr_claim() {return fmtr_claim;} private final Wdata_fmtr__claim_grp fmtr_claim = new Wdata_fmtr__claim_grp();
private final Wdata_fmtr__langtext_tbl fmtr_label = new Wdata_fmtr__langtext_tbl();
private final Wdata_fmtr__langtext_tbl fmtr_descr = new Wdata_fmtr__langtext_tbl();
private final Wdata_fmtr__langtext_tbl fmtr_alias = new Wdata_fmtr__langtext_tbl();
private final Wdata_fmtr__slink_grp fmtr_slink = new Wdata_fmtr__slink_grp();
private final Wdata_fmtr__oview_tbl fmtr_oview = new Wdata_fmtr__oview_tbl();
private Wdata_lang_sorter lang_sorter = new Wdata_lang_sorter();
public Bry_fmtr Fmtr_main() {return fmtr_main;} private final Bry_fmtr fmtr_main = Bry_fmtr.new_("~{oview}~{toc}~{claims}~{links}~{labels}~{descriptions}~{aliases}~{json}", "oview", "toc", "claims", "links", "labels", "descriptions", "aliases", "json");
public Wdata_hwtr_msgs Msgs() {return msgs;} private Wdata_hwtr_msgs msgs;
@gplx.Internal protected Wdata_lbl_mgr Lbl_mgr() {return lbl_mgr;} private final Wdata_lbl_mgr lbl_mgr = new Wdata_lbl_mgr();
public void Init_by_ctor(Xoapi_wikibase wikibase_api, Wdata_lbl_wkr lbl_wkr, Gfo_url_encoder href_encoder, Xoapi_toggle_mgr toggle_mgr, Xow_xwiki_mgr xwiki_mgr) {
lbl_mgr.Wkr_(lbl_wkr);
fmtr_oview.Init_by_ctor(wikibase_api, href_encoder);
fmtr_claim.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), toggle_mgr, lbl_mgr);
fmtr_slink.Init_by_ctor(lang_sorter, toggle_mgr, lbl_mgr, href_encoder, fmtr_toc, xwiki_mgr);
fmtr_label.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), lang_sorter, toggle_mgr, "wikidatawiki-label", new Wdata_fmtr__langtext_row_base());
fmtr_descr.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), lang_sorter, toggle_mgr, "wikidatawiki-descr", new Wdata_fmtr__langtext_row_base());
fmtr_alias.Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), lang_sorter, toggle_mgr, "wikidatawiki-alias", new Wdata_fmtr__alias_row());
fmtr_json .Init_by_ctor(new Wdata_toc_data(fmtr_toc, href_encoder), toggle_mgr);
lang_sorter.Langs_(wikibase_api.Sort_langs());
Gfo_evt_mgr_.Sub_same_many(wikibase_api, lang_sorter, Xoapi_wikibase.Evt_sort_langs_changed);
}
public void Init_by_lang(Wdata_hwtr_msgs msgs) {
this.msgs = msgs;
fmtr_toc.Init_by_lang(msgs);
fmtr_oview.Init_by_lang(lang_sorter.Langs()[0], msgs);
fmtr_claim.Init_by_lang(msgs);
fmtr_slink.Init_by_lang(msgs);
fmtr_label.Init_by_lang(msgs, msgs.Label_tbl_hdr(), msgs.Label_col_hdr());
fmtr_descr.Init_by_lang(msgs, msgs.Descr_tbl_hdr(), msgs.Descr_col_hdr());
fmtr_alias.Init_by_lang(msgs, msgs.Alias_tbl_hdr(), msgs.Alias_col_hdr());
fmtr_json.Init_by_lang(msgs);
}
public void Init_by_wdoc(Wdata_doc wdoc) {
lang_sorter.Init_by_wdoc(wdoc);
fmtr_toc .Init_by_wdoc(wdoc);
fmtr_oview.Init_by_wdoc(wdoc);
fmtr_claim.Init_by_wdoc(wdoc.Qid(), wdoc.Claim_list());
fmtr_slink.Init_by_wdoc(wdoc.Slink_list());
fmtr_label.Init_by_wdoc(wdoc.Label_list());
fmtr_descr.Init_by_wdoc(wdoc.Descr_list());
fmtr_alias.Init_by_wdoc(wdoc.Alias_list());
fmtr_json.Init_by_wdoc (wdoc.Jdoc());
lbl_mgr.Gather_labels(wdoc, lang_sorter);
}
public byte[] Popup(Wdata_doc wdoc) {
fmtr_oview .Init_by_wdoc(wdoc);
fmtr_label.Init_by_wdoc(wdoc.Label_list());
fmtr_descr.Init_by_wdoc(wdoc.Descr_list());
fmtr_alias.Init_by_wdoc(wdoc.Alias_list());
bfr.Add_str_a7("<div id='wb-item' class='wikibase-entityview wb-item' lang='en' dir='ltr'>");
bfr.Add_str_a7("<div class='wikibase-entityview-main'>");
fmtr_main.Bld_bfr_many(bfr, fmtr_oview, "", "", "", "", "", "", "");
bfr.Add_str_a7("</div>");
bfr.Add_str_a7("</div>");
return bfr.To_bry_and_clear();
}
public byte[] Write(Wdata_doc wdoc) {
bfr.Add_str_a7("<div id='wb-item' class='wikibase-entityview wb-item' lang='en' dir='ltr'>");
bfr.Add_str_a7("<div class='wikibase-entityview-main'>");
fmtr_main.Bld_bfr_many(bfr, fmtr_oview, fmtr_toc, fmtr_claim, fmtr_slink, fmtr_label, fmtr_descr, fmtr_alias, fmtr_json);
bfr.Add_str_a7("</div>");
bfr.Add_str_a7("</div>");
return bfr.To_bry_and_clear();
}
public static void Write_link_wikidata(Bry_bfr bfr, byte[] href, byte[] text) {
text = gplx.langs.htmls.Gfh_utl.Escape_html_as_bry(text);
fmtr_link_wikidata.Bld_bfr_many(bfr, href, text);
} private static final Bry_fmtr fmtr_link_wikidata = Bry_fmtr.new_("<a href='/wiki/~{href}'>~{text}</a>", "href", "text");
}

View File

@@ -0,0 +1,328 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.apps.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apps.apis.xowa.xtns.*;
public class Wdata_hwtr_mgr_tst {
@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
@Test public void Stub() {}
// @Test public void Write_label() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_label("en", "en_label")
// .Add_label("de", "de_label").Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Labels</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Language</th>"
// , " <th>Label</th>"
// , " </tr>"
// , " <tr>"
// , " <td><code>en</code></td>"
// , " <td>en_label</td>"
// , " </tr>"
// , " <tr>"
// , " <td><code>de</code></td>"
// , " <td>de_label</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_descr() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_description("en", "en_descr")
// .Add_description("de", "de_descr").Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Descriptions</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Language</th>"
// , " <th>Description</th>"
// , " </tr>"
// , " <tr>"
// , " <td><code>en</code></td>"
// , " <td>en_descr</td>"
// , " </tr>"
// , " <tr>"
// , " <td><code>de</code></td>"
// , " <td>de_descr</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_alias() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_alias("en", "en_1", "en_2")
// .Add_alias("de", "de_1").Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Aliases</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Language</th>"
// , " <th>Alias</th>"
// , " </tr>"
// , " <tr>"
// , " <td><code>en</code></td>"
// , " <td>en_1<br/>en_2</td>"
// , " </tr>"
// , " <tr>"
// , " <td><code>de</code></td>"
// , " <td>de_1</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_slink_tbl_one() {
// fxt
// .Init_resolved_qid(1, "featured article").Init_resolved_qid(2, "good article")
// .Test_doc(fxt.Wdoc_bldr()
// .Add_sitelink("enwiki", "Earth", "Q1", "Q2")
// .Add_sitelink("dewiki", "Erde")
// .Add_sitelink("frwiki", "Terre")
// .Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , " <div class='wikibase-sitelinkgrouplistview'>"
// , " <div class='wb-listview'>"
// , " <div class='wikibase-sitelinkgroupview' data-wb-sitelinks-group='wikipedia'>"
// , " <div class='wikibase-sitelinkgroupview-heading-container'>"
// , " <h2 class='wb-section-heading wikibase-sitelinkgroupview-heading' dir='auto' id='sitelinks-wikipedia'>Links (Wikipedia)</h2>"
// , " </div>"
// , " <table class='wikibase-sitelinklistview'>"
// , " <colgroup>"
// , " <col class='wikibase-sitelinklistview-sitename' />"
// , " <col class='wikibase-sitelinklistview-siteid' />"
// , " <col class='wikibase-sitelinklistview-link' />"
// , " </colgroup>"
// , " <thead>"
// , " <tr class='wikibase-sitelinklistview-columnheaders'>"
// , " <th class='wikibase-sitelinkview-sitename'>Language</th>"
// , " <th class='wikibase-sitelinkview-siteid'>Code</th>"
// , " <th class='wikibase-sitelinkview-link'>Linked page</th>"
// , " </tr>"
// , " </thead>"
// , " <tbody>"
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-enwiki' data-wb-siteid='enwiki'>"
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-enwiki' lang='en' dir='auto'>English</td>"
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-enwiki'>enwiki</td>"
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-enwiki' lang='en' dir='auto'>"
// , " <span class='wikibase-sitelinkview-badges'>"
// , " <span class='wb-badge wb-badge-Q1 wb-badge-featuredarticle' title='featured article'></span>"
// , " <span class='wb-badge wb-badge-Q2 wb-badge-goodarticle' title='good article'></span>"
// , " </span>"
// , " <span class='wikibase-sitelinkview-page'>"
// , " <a href='https://en.wikipedia.org/wiki/Earth' hreflang='en' dir='auto'>Earth</a>"
// , " </span>"
// , " </td>"
// , " </tr>"
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-dewiki' data-wb-siteid='dewiki'>"
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-dewiki' lang='de' dir='auto'>Deutsch</td>"
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-dewiki'>dewiki</td>"
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-dewiki' lang='de' dir='auto'>"
// , " <span class='wikibase-sitelinkview-badges'>"
// , " </span>"
// , " <span class='wikibase-sitelinkview-page'>"
// , " <a href='https://de.wikipedia.org/wiki/Erde' hreflang='de' dir='auto'>Erde</a>"
// , " </span>"
// , " </td>"
// , " </tr>"
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-frwiki' data-wb-siteid='frwiki'>"
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-frwiki' lang='fr' dir='auto'>Français</td>"
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-frwiki'>frwiki</td>"
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-frwiki' lang='fr' dir='auto'>"
// , " <span class='wikibase-sitelinkview-badges'>"
// , " </span>"
// , " <span class='wikibase-sitelinkview-page'>"
// , " <a href='https://fr.wikipedia.org/wiki/Terre' hreflang='fr' dir='auto'>Terre</a>"
// , " </span>"
// , " </td>"
// , " </tr>"
// , " </tbody>"
// , " </table>"
// , " </div>"
// , " </div>"
// , " </div>"
// ));
// }
// @Test public void Write_slink_tbl_many() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_sitelink("enwiki" , "Earth")
// .Add_sitelink("enwiktionary", "Earth")
// .Add_sitelink("enwikiquote" , "Earth")
// .Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<p>"
// , " <div id='toc' class='toc'>"
// , " <div id='toctitle'><h2>Contents</h2></div>"
// , " <ul>"
// , " <li class='toclevel-1 tocsection-1'><a href='#Links_(Wikipedia)'><span class='tocnumber'>1</span> <span class='toctext'>Links (Wikipedia)</span></a></li>"
// , " <li class='toclevel-1 tocsection-2'><a href='#Links_(Wiktionary)'><span class='tocnumber'>2</span> <span class='toctext'>Links (Wiktionary)</span></a></li>"
// , " <li class='toclevel-1 tocsection-3'><a href='#Links_(Wikiquote)'><span class='tocnumber'>3</span> <span class='toctext'>Links (Wikiquote)</span></a></li>"
// , " <li class='toclevel-1 tocsection-4'><a href='#JSON'><span class='tocnumber'>4</span> <span class='toctext'>JSON</span></a></li>"
// , " </ul>"
// , " </div>"
// , "</p>"
// , ""
// , "<h2>Links (Wikipedia)</h2>"
// , ""
// , "<p>"
// , " <table class='wikitable'>"
// , " <tr>"
// , " <th>Site</th>"
// , " <th>Link</th>"
// , " <th>Badges</th>"
// , " </tr>"
// , " <tr>"
// , " <td><a href='/site/en.wikipedia.org/wiki/'><code>enwiki</code></a></td>"
// , " <td><a href='/site/en.wikipedia.org/wiki/Earth'>Earth</a></td>"
// , " <td></td>"
// , " </tr>"
// , " </table>"
// , "</p>"
// , ""
// , "<h2>Links (Wiktionary)</h2>"
// , ""
// , "<p>"
// , " <table class='wikitable'>"
// , " <tr>"
// , " <th>Site</th>"
// , " <th>Link</th>"
// , " <th>Badges</th>"
// , " </tr>"
// , " <tr>"
// , " <td><a href='/site/en.wiktionary.org/wiki/'><code>enwiktionary</code></a></td>"
// , " <td><a href='/site/en.wiktionary.org/wiki/Earth'>Earth</a></td>"
// , " <td></td>"
// , " </tr>"
// , " </table>"
// , "</p>"
// , ""
// , "<h2>Links (Wikiquote)</h2>"
// , ""
// , "<p>"
// , " <table class='wikitable'>"
// , " <tr>"
// , " <th>Site</th>"
// , " <th>Link</th>"
// , " <th>Badges</th>"
// , " </tr>"
// , " <tr>"
// , " <td><a href='/site/en.wikiquote.org/wiki/'><code>enwikiquote</code></a></td>"
// , " <td><a href='/site/en.wikiquote.org/wiki/Earth'>Earth</a></td>"
// , " <td></td>"
// , " </tr>"
// , " </table>"
// , "</p>"
// ));
// }
// @Test public void Write_claim() {
// Wdata_wiki_mgr_fxt mkr = fxt.Wdata_fxt();
// fxt
// .Init_resolved_pid(1, "prop_1")
// .Test_doc(fxt.Wdoc_bldr()
// .Add_claims
// ( mkr.Make_claim_string(1, "abc").Qualifiers_(mkr.Make_qualifiers(mkr.Make_qualifiers_grp(2, mkr.Make_claim_string(2, "qual_2"))))
// ).Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Claims</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Id</th>"
// , " <th>Name</th>"
// , " <th>Value</th>"
// , " <th>References</th>"
// , " <th>Qualifiers</th>"
// , " <th>Rank</th>"
// , " </tr>"
// , " <tr>"
// , " <td>1</td>"
// , " <td>prop_1</td>"
// , " <td>abc</td>"
// , " <td></td>"
// , " <td></td>"
// , " <td>normal</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_json() {
// Json_doc jdoc = Json_doc.new_apos_("{ 'node':['val_0', 'val_1'] }");
// Wdata_doc wdoc = new Wdata_doc(Bry_.Empty, null, jdoc);
// fxt.Test_json(wdoc, String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>JSON</h2>"
// , ""
// , "<pre style=\"overflow:auto\">"
// , "{ \"node\":"
// , " [ \"val_0\""
// , " , \"val_1\""
// , " ]"
// , "}"
// , "</pre>"
// ));
// }
}
class Wdata_hwtr_mgr_fxt {
private Wdata_hwtr_mgr doc_hwtr; private Ordered_hash resolved_ttls = Ordered_hash_.New_bry();
public Wdata_wiki_mgr_fxt Wdata_fxt() {return wdata_fxt;} private Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
public void init() {
if (doc_hwtr == null) {
doc_hwtr = new Wdata_hwtr_mgr();
Wdata_hwtr_msgs msgs = Wdata_hwtr_msgs.new_en_();
Xoapi_toggle_mgr toggle_mgr = new Xoapi_toggle_mgr();
wdata_fxt.Init();
toggle_mgr.Ctor_by_app(wdata_fxt.App()); // must init, else null error
doc_hwtr.Init_by_ctor(new Xoapi_wikibase(), new Wdata_lbl_wkr__test(resolved_ttls), Gfo_url_encoder_.Href, toggle_mgr, new Xow_xwiki_mgr(wdata_fxt.Wiki()));
doc_hwtr.Init_by_lang(msgs);
}
resolved_ttls.Clear();
doc_hwtr.Lbl_mgr().Clear();
}
public Wdata_doc_bldr Wdoc_bldr() {return wdoc_bldr;} private Wdata_doc_bldr wdoc_bldr = new Wdata_doc_bldr();
public Wdata_hwtr_mgr_fxt Init_resolved_pid(int pid, String lbl) {resolved_ttls.Add(Wdata_lbl_itm.Make_ttl(Bool_.Y, pid), new Wdata_langtext_itm(Bry_.new_a7("en"), Bry_.new_a7(lbl))); return this;}
public Wdata_hwtr_mgr_fxt Init_resolved_qid(int qid, String lbl) {resolved_ttls.Add(Wdata_lbl_itm.Make_ttl(Bool_.N, qid), new Wdata_langtext_itm(Bry_.new_a7("en"), Bry_.new_a7(lbl))); return this;}
public void Test_doc(Wdata_doc wdoc, String expd) {
doc_hwtr.Init_by_wdoc(wdoc);
byte[] actl = doc_hwtr.Write(wdoc);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public void Test_claim_val(Wbase_claim_base claim, String expd) {
doc_hwtr.Init_by_wdoc(wdoc_bldr.Add_claims(claim).Xto_wdoc());
Bry_bfr tmp_bfr = Bry_bfr_.New();
Wdata_visitor__html_wtr html_wtr = new Wdata_visitor__html_wtr().Init(Bry_.Empty, tmp_bfr, doc_hwtr.Msgs(), doc_hwtr.Lbl_mgr());
claim.Welcome(html_wtr);
byte[] actl = tmp_bfr.To_bry_and_clear();
Tfds.Eq(expd, String_.new_u8(actl));
}
public void Test_json(Wdata_doc wdoc, String expd) {
Wdata_fmtr__json fmtr_json = doc_hwtr.Fmtr_json();
fmtr_json.Init_by_wdoc(wdoc.Jdoc());
Bry_bfr tmp_bfr = Bry_bfr_.New();
fmtr_json.Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}
class Wdata_lbl_wkr__test implements Wdata_lbl_wkr {
private Ordered_hash found;
public Wdata_lbl_wkr__test(Ordered_hash found) {this.found = found;}
public void Resolve(Wdata_lbl_mgr lbl_mgr, Wdata_lang_sorter sorter) {lbl_mgr.Resolve(found);}
}

View File

@@ -0,0 +1,229 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.langs.msgs.*;
import gplx.xowa.wikis.domains.*;
public class Wdata_hwtr_msgs {
public Wdata_hwtr_msgs(byte[][] brys) { int offset = 0; // String[] strs = String_.Ary(brys); // TEST
this.ary = brys;
toggle_title_n = brys[offset + 0];
toggle_title_y = brys[offset + 1];
toc_tbl_hdr = brys[offset + 2];
oview_alias_y = brys[offset + 3];
oview_alias_n = brys[offset + 4]; offset += 5;
langtext_col_lang_name = brys[offset + 0];
langtext_col_lang_code = brys[offset + 1];
slink_tbl_hdr_fmt = brys[offset + 2];
slink_tbl_hdr_fmt_other = brys[offset + 3];
slink_col_hdr_text = brys[offset + 4]; offset += 5;
label_tbl_hdr = brys[offset + 0];
label_col_hdr = brys[offset + 1];
alias_tbl_hdr = brys[offset + 2];
alias_col_hdr = brys[offset + 3];
descr_tbl_hdr = brys[offset + 4];
descr_col_hdr = brys[offset + 5];
claim_tbl_hdr = brys[offset + 6];
json_div_hdr = brys[offset + 7]; offset += 8;
sym_list_comma = brys[offset + 0];
sym_list_word = brys[offset + 1];
sym_time_spr = brys[offset + 2];
sym_plus = brys[offset + 3];
sym_minus = brys[offset + 4];
sym_plusminus = brys[offset + 5];
sym_fmt_parentheses = brys[offset + 6]; offset += 7;
val_tid_novalue = brys[offset + 0];
val_tid_somevalue = brys[offset + 1]; offset += 2;
this.month_bgn_idx = offset;
time_month_01 = brys[offset + 0];
time_month_02 = brys[offset + 1];
time_month_03 = brys[offset + 2];
time_month_04 = brys[offset + 3];
time_month_05 = brys[offset + 4];
time_month_06 = brys[offset + 5];
time_month_07 = brys[offset + 6];
time_month_08 = brys[offset + 7];
time_month_09 = brys[offset + 8];
time_month_10 = brys[offset + 9];
time_month_11 = brys[offset + 10];
time_month_12 = brys[offset + 11]; offset += 12;
time_year_idx = offset;
time_year_1e10_00 = brys[offset + 0];
time_year_1e10_01 = brys[offset + 1];
time_year_1e10_02 = brys[offset + 2];
time_year_1e10_03 = brys[offset + 3];
time_year_1e10_04 = brys[offset + 4];
time_year_1e10_05 = brys[offset + 5];
time_year_1e10_06 = brys[offset + 6];
time_year_1e10_07 = brys[offset + 7];
time_year_1e10_08 = brys[offset + 8];
time_year_1e10_09 = brys[offset + 9]; offset += 10;
time_relative_bc = brys[offset + 0];
time_relative_ago = brys[offset + 1];
time_relative_in = brys[offset + 2];
time_julian = brys[offset + 3]; offset += 4;
geo_dir_n = brys[offset + 0];
geo_dir_s = brys[offset + 1];
geo_dir_e = brys[offset + 2];
geo_dir_w = brys[offset + 3];
geo_unit_degree = brys[offset + 4];
geo_unit_minute = brys[offset + 5];
geo_unit_second = brys[offset + 6];
geo_meters = brys[offset + 7];
Bry_fmtr fmtr = Bry_fmtr.new_( slink_tbl_hdr_fmt, "wiki_type");
Bry_bfr bfr = Bry_bfr_.New_w_size(64);
slink_tbl_hdr_w = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wikipedia));
slink_tbl_hdr_d = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wiktionary));
slink_tbl_hdr_s = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wikisource));
slink_tbl_hdr_v = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wikivoyage));
slink_tbl_hdr_q = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wikiquote));
slink_tbl_hdr_b = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wikibooks));
slink_tbl_hdr_u = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wikiversity));
slink_tbl_hdr_n = fmtr.Bld_bry_many(bfr, Name_(Xow_domain_tid_.Bry__wikinews));
slink_tbl_hdr_x = fmtr.Bld_bry_many(bfr, slink_tbl_hdr_fmt_other);
}
public byte[][] Ary() {return ary;} private final byte[][] ary;
public int Month_bgn_idx() {return month_bgn_idx;} private final int month_bgn_idx;
public byte[] Toggle_title_y() {return toggle_title_y;} private byte[] toggle_title_y;
public byte[] Toggle_title_n() {return toggle_title_n;} private byte[] toggle_title_n;
public byte[] Toc_tbl_hdr() {return toc_tbl_hdr;} private final byte[] toc_tbl_hdr;
public byte[] Oview_alias_y() {return oview_alias_y;} private final byte[] oview_alias_y;
public byte[] Oview_alias_n() {return oview_alias_n;} private final byte[] oview_alias_n;
public byte[] Langtext_col_lang_name() {return langtext_col_lang_name;} private final byte[] langtext_col_lang_name;
public byte[] Langtext_col_lang_code() {return langtext_col_lang_code;} private final byte[] langtext_col_lang_code;
public byte[] Label_tbl_hdr() {return label_tbl_hdr;} private final byte[] label_tbl_hdr;
public byte[] Label_col_hdr() {return label_col_hdr;} private final byte[] label_col_hdr;
public byte[] Alias_tbl_hdr() {return alias_tbl_hdr;} private final byte[] alias_tbl_hdr;
public byte[] Alias_col_hdr() {return alias_col_hdr;} private final byte[] alias_col_hdr;
public byte[] Descr_tbl_hdr() {return descr_tbl_hdr;} private final byte[] descr_tbl_hdr;
public byte[] Descr_col_hdr() {return descr_col_hdr;} private final byte[] descr_col_hdr;
public byte[] Slink_tbl_hdr_fmt() {return slink_tbl_hdr_fmt;} private final byte[] slink_tbl_hdr_fmt;
public byte[] Slink_tbl_hdr_fmt_other() {return slink_tbl_hdr_fmt_other;} private final byte[] slink_tbl_hdr_fmt_other;
public byte[] Slink_tbl_hdr_w() {return slink_tbl_hdr_w;} private final byte[] slink_tbl_hdr_w;
public byte[] Slink_tbl_hdr_d() {return slink_tbl_hdr_d;} private final byte[] slink_tbl_hdr_d;
public byte[] Slink_tbl_hdr_s() {return slink_tbl_hdr_s;} private final byte[] slink_tbl_hdr_s;
public byte[] Slink_tbl_hdr_v() {return slink_tbl_hdr_v;} private final byte[] slink_tbl_hdr_v;
public byte[] Slink_tbl_hdr_q() {return slink_tbl_hdr_q;} private final byte[] slink_tbl_hdr_q;
public byte[] Slink_tbl_hdr_b() {return slink_tbl_hdr_b;} private final byte[] slink_tbl_hdr_b;
public byte[] Slink_tbl_hdr_u() {return slink_tbl_hdr_u;} private final byte[] slink_tbl_hdr_u;
public byte[] Slink_tbl_hdr_n() {return slink_tbl_hdr_n;} private final byte[] slink_tbl_hdr_n;
public byte[] Slink_tbl_hdr_x() {return slink_tbl_hdr_x;} private final byte[] slink_tbl_hdr_x;
public byte[] Slink_col_hdr_text() {return slink_col_hdr_text;} private final byte[] slink_col_hdr_text;
public byte[] Claim_tbl_hdr() {return claim_tbl_hdr;} private final byte[] claim_tbl_hdr;
public byte[] Json_div_hdr() {return json_div_hdr;} private final byte[] json_div_hdr;
public byte[] Val_tid_novalue() {return val_tid_novalue;} private final byte[] val_tid_novalue;
public byte[] Val_tid_somevalue() {return val_tid_somevalue;} private final byte[] val_tid_somevalue;
public byte[] Sym_list_comma() {return sym_list_comma;} private final byte[] sym_list_comma;
public byte[] Sym_list_word() {return sym_list_word;} private final byte[] sym_list_word;
public byte[] Sym_time_spr() {return sym_time_spr;} private final byte[] sym_time_spr;
public byte[] Sym_plus() {return sym_plus;} private final byte[] sym_plus;
public byte[] Sym_minus() {return sym_minus;} private final byte[] sym_minus;
public byte[] Sym_plusminus() {return sym_plusminus;} private final byte[] sym_plusminus;
public byte[] Sym_fmt_parentheses() {return sym_fmt_parentheses;} private final byte[] sym_fmt_parentheses;
public byte[] Time_month_01() {return time_month_01;} private final byte[] time_month_01;
public byte[] Time_month_02() {return time_month_02;} private final byte[] time_month_02;
public byte[] Time_month_03() {return time_month_03;} private final byte[] time_month_03;
public byte[] Time_month_04() {return time_month_04;} private final byte[] time_month_04;
public byte[] Time_month_05() {return time_month_05;} private final byte[] time_month_05;
public byte[] Time_month_06() {return time_month_06;} private final byte[] time_month_06;
public byte[] Time_month_07() {return time_month_07;} private final byte[] time_month_07;
public byte[] Time_month_08() {return time_month_08;} private final byte[] time_month_08;
public byte[] Time_month_09() {return time_month_09;} private final byte[] time_month_09;
public byte[] Time_month_10() {return time_month_10;} private final byte[] time_month_10;
public byte[] Time_month_11() {return time_month_11;} private final byte[] time_month_11;
public byte[] Time_month_12() {return time_month_12;} private final byte[] time_month_12;
public int Time_year_idx() {return time_year_idx;} private final int time_year_idx;
public byte[] Time_year_1e10_00() {return time_year_1e10_00;} private final byte[] time_year_1e10_00;
public byte[] Time_year_1e10_01() {return time_year_1e10_01;} private final byte[] time_year_1e10_01;
public byte[] Time_year_1e10_02() {return time_year_1e10_02;} private final byte[] time_year_1e10_02;
public byte[] Time_year_1e10_03() {return time_year_1e10_03;} private final byte[] time_year_1e10_03;
public byte[] Time_year_1e10_04() {return time_year_1e10_04;} private final byte[] time_year_1e10_04;
public byte[] Time_year_1e10_05() {return time_year_1e10_05;} private final byte[] time_year_1e10_05;
public byte[] Time_year_1e10_06() {return time_year_1e10_06;} private final byte[] time_year_1e10_06;
public byte[] Time_year_1e10_07() {return time_year_1e10_07;} private final byte[] time_year_1e10_07;
public byte[] Time_year_1e10_08() {return time_year_1e10_08;} private final byte[] time_year_1e10_08;
public byte[] Time_year_1e10_09() {return time_year_1e10_09;} private final byte[] time_year_1e10_09;
public byte[] Time_relative_bc() {return time_relative_bc;} private final byte[] time_relative_bc;
public byte[] Time_relative_ago() {return time_relative_ago;} private final byte[] time_relative_ago;
public byte[] Time_relative_in() {return time_relative_in;} private final byte[] time_relative_in;
public byte[] Time_julian() {return time_julian;} private final byte[] time_julian;
public byte[] Geo_dir_n() {return geo_dir_n;} private final byte[] geo_dir_n;
public byte[] Geo_dir_s() {return geo_dir_s;} private final byte[] geo_dir_s;
public byte[] Geo_dir_e() {return geo_dir_e;} private final byte[] geo_dir_e;
public byte[] Geo_dir_w() {return geo_dir_w;} private final byte[] geo_dir_w;
public byte[] Geo_unit_degree() {return geo_unit_degree;} private final byte[] geo_unit_degree;
public byte[] Geo_unit_minute() {return geo_unit_minute;} private final byte[] geo_unit_minute;
public byte[] Geo_unit_second() {return geo_unit_second;} private final byte[] geo_unit_second;
public byte[] Geo_meters() {return geo_meters;} private final byte[] geo_meters;
public static Wdata_hwtr_msgs new_en_() {
byte[][] brys = Bry_.Ary
( "hide", "show", "Contents"
, "Also known as:", "No aliases defined."
, "Language", "Code"
, "Links (~{wiki_type})", "other sites", "Linked page"
, "Labels", "Label"
, "Aliases", "Alias"
, "Descriptions", "Description"
, "Statements"
, "JSON"
, ",&#32;", "&#32;", ":"
, "+", "-", "±", "(~{0})"
, "", "?"
, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
, "~{0}", "~{0}0s", "~{0}. century", "~{0}. millenium", "~{0}0,000 years", "~{0}00,000 years", "~{0} million years", "~{0}0 million years", "~{0}00 million years", "~{0} billion years"
, "~{0} BC", "~{0} ago", "in ~{0}", "<sup>jul</sup>"
, "N", "S", "E", "W"
, "°", "", ""
, "&nbsp;m"
);
return new Wdata_hwtr_msgs(brys);
}
public static Wdata_hwtr_msgs new_(Xow_msg_mgr msg_mgr) {
byte[][] brys = new_brys(msg_mgr
, "hide", "show", "toc"
, "wikibase-aliases-label" , "wikibase-aliases-empty"
, "wikibase-sitelinks-sitename-columnheading" , "wikibase-sitelinks-siteid-columnheading"
, "xowa-wikidata-sitelinks-hdr" , "xowa-wikidata-sitelinks-hdr-special", "wikibase-sitelinks-link-columnheading"
, "xowa-wikidata-labels-hdr" , "xowa-wikidata-labels-col"
, "xowa-wikidata-aliases-hdr" , "xowa-wikidata-aliases-col"
, "xowa-wikidata-descriptions-hdr" , "xowa-wikidata-descriptions-col"
, "wikibase-statements"
, "xowa-wikidata-json"
, "comma-separator", "word-separator", "xowa-wikidata-time-spr"
, "xowa-wikidata-plus", "xowa-wikidata-minus", "xowa-wikidata-plusminus"
, "parentheses"
, "xowa-wikidata-novalue", "xowa-wikidata-somevalue"
, "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"
, "xowa-wikidata-year", "xowa-wikidata-decade", "xowa-wikidata-century", "xowa-wikidata-millenium", "xowa-wikidata-years1e4", "xowa-wikidata-years1e5", "xowa-wikidata-years1e6", "xowa-wikidata-years1e7", "xowa-wikidata-years1e8", "xowa-wikidata-years1e9"
, "ago", "xowa-wikidata-bc", "xowa-wikidata-inTime"
, "xowa-wikidata-julian"
, "xowa-wikidata-north", "xowa-wikidata-south", "xowa-wikidata-east", "xowa-wikidata-west"
, "xowa-wikidata-degree", "xowa-wikidata-minute", "xowa-wikidata-second"
, "xowa-wikidata-meters"
);
return new Wdata_hwtr_msgs(brys);
}
private static byte[][] new_brys(Xow_msg_mgr msg_mgr, String... ids) {
int len = ids.length;
byte[][] rv = new byte[len][];
for (int i = 0; i < len; ++i)
rv[i] = gplx.langs.htmls.Gfh_utl.Escape_html_as_bry(msg_mgr.Val_by_key_obj(ids[i]));
return rv;
}
private static byte[] Name_(byte[] v) {return Bry_.Ucase__1st(Bry_.Copy(v));}
}

View File

@@ -0,0 +1,47 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.wbases.core.*;
public class Wdata_lbl_itm {
public Wdata_lbl_itm(boolean is_pid, int id, boolean text_en_enabled) {
this.is_pid = is_pid; this.id = id; this.text_en_enabled = text_en_enabled;
this.ttl = Make_ttl(is_pid, id);
}
public boolean Is_pid() {return is_pid;} private final boolean is_pid;
public int Id() {return id;} private final int id;
public byte[] Ttl() {return ttl;} private final byte[] ttl;
public byte[] Lang() {return lang;} private byte[] lang;
public byte[] Text() {return text;} private byte[] text;
public byte[] Text_en() {return text_en;} public void Text_en_(byte[] v) {text_en = v;} private byte[] text_en = Bry_.Empty;
public boolean Text_en_enabled() {return text_en_enabled;} private boolean text_en_enabled;
public void Load_vals(byte[] lang, byte[] text) {this.lang = lang; this.text = text;}
public static byte[] Make_ttl(boolean is_pid, int id) {
return is_pid
? Bry_.Add(Ttl_prefix_pid, Int_.To_bry(id))
: Bry_.Add(Ttl_prefix_qid, Int_.To_bry(id))
;
}
private static final byte[] Ttl_prefix_pid = Bry_.new_a7("Property:P"), Ttl_prefix_qid = Bry_.new_a7("Q");
private static final byte[] Extract_ttl_qid = Bry_.new_a7("http://www.wikidata.org/entity/");
public static byte[] Extract_ttl(byte[] href) {
if (Bry_.Has_at_bgn(href, Extract_ttl_qid)) // qid
return Bry_.Mid(href, Extract_ttl_qid.length, href.length);
else // possibly support pid in future, but so far, nothing referencing just "Property:P##"
return null;
}
}

View File

@@ -0,0 +1,139 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.primitives.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wdata_lbl_mgr {
private Hash_adp_bry ttl_hash = Hash_adp_bry.ci_a7();
private Hash_adp qid_hash = Hash_adp_.New(), pid_hash = Hash_adp_.New(); private Int_obj_ref int_hash_key = Int_obj_ref.New_neg1();
private Wdata_visitor__lbl_gatherer lbl_gatherer;
public Wdata_lbl_mgr() {
lbl_gatherer = new Wdata_visitor__lbl_gatherer(this);
}
public void Clear() {ttl_hash.Clear(); qid_hash.Clear(); pid_hash.Clear(); queue.Clear();}
public List_adp Queue() {return queue;} private List_adp queue = List_adp_.New();
@gplx.Internal protected void Wkr_(Wdata_lbl_wkr v) {this.wkr = v;} private Wdata_lbl_wkr wkr;
public Wdata_lbl_itm Get_itm__ttl(byte[] ttl) {
Wdata_lbl_itm rv = (Wdata_lbl_itm)ttl_hash.Get_by(ttl);
if (rv == null) Gfo_usr_dlg_.Instance.Warn_many("", "", "wdata.hwtr:unknown entity; ttl=~{0}", String_.new_u8(ttl)); // NOTE: should not happen
return rv;
}
public byte[] Get_text__ttl(byte[] ttl, byte[] or) {
Wdata_lbl_itm rv_itm = Get_itm__ttl(ttl);
return rv_itm == null ? or : rv_itm.Text();
}
public byte[] Get_text__qid(int id) {return Get_text(Bool_.N, id);}
public byte[] Get_text__pid(int id) {return Get_text(Bool_.Y, id);}
private byte[] Get_text(boolean is_pid, int id) {
Hash_adp hash = is_pid ? pid_hash : qid_hash;
Wdata_lbl_itm rv_itm = (Wdata_lbl_itm)hash.Get_by(int_hash_key.Val_(id));
if (rv_itm != null) return rv_itm.Text(); // found; return lbl
Gfo_usr_dlg_.Instance.Warn_many("", "", "wdata.hwtr:unknown entity; is_pid=~{0} id=~{1}", Yn.To_str(is_pid), id); // NOTE: should not happen
return Wdata_lbl_itm.Make_ttl(is_pid, id); // missing; return ttl; EX: "Property:P1", "Q1";
}
public void Queue_if_missing__ttl(byte[] ttl) {Queue_if_missing__ttl(ttl, Bool_.N);}
public void Queue_if_missing__ttl(byte[] ttl, boolean get_en) {
if (ttl == null) {Gfo_usr_dlg_.Instance.Warn_many("", "", "wdata.hwtr:unknown href; href=~{0}", String_.new_u8(ttl)); return;}
boolean has = ttl_hash.Has(ttl);
if (!has) Queue_add(qid_hash, Bool_.N, Qid_int(ttl), get_en);
}
public void Queue_if_missing__qid(int id) {Queue_if_missing(Bool_.N, id);}
public void Queue_if_missing__pid(int id) {Queue_if_missing(Bool_.Y, id);}
private void Queue_if_missing(boolean is_pid, int id) {
Hash_adp hash = is_pid ? pid_hash : qid_hash;
boolean has = hash.Has(int_hash_key.Val_(id));
if (!has) Queue_add(hash, is_pid, id, Bool_.N);
}
private void Queue_add(Hash_adp hash, boolean is_pid, int id, boolean get_en) {
Wdata_lbl_itm itm = new Wdata_lbl_itm(is_pid, id, get_en);
hash.Add(Int_obj_ref.New(id), itm);
ttl_hash.Add(itm.Ttl(), itm);
queue.Add(itm);
}
public void Resolve(Ordered_hash found) {
int len = queue.Count();
for (int i = 0; i < len; ++i) {
Wdata_lbl_itm pending_itm = (Wdata_lbl_itm)queue.Get_at(i);
Wdata_langtext_itm found_itm = (Wdata_langtext_itm)found.Get_by(pending_itm.Ttl());
if (found_itm != null)
pending_itm.Load_vals(found_itm.Lang(), found_itm.Text());
}
queue.Clear();
}
public void Gather_labels(Wdata_doc wdoc, Wdata_lang_sorter sorter) {
Ordered_hash claim_list = wdoc.Claim_list();
int len = claim_list.Count();
for (int i = 0; i < len; ++i) {
Wbase_claim_grp grp = (Wbase_claim_grp)claim_list.Get_at(i);
int grp_len = grp.Len();
for (int j = 0; j < grp_len; ++j) {
Wbase_claim_base itm = (Wbase_claim_base)grp.Get_at(j);
this.Queue_if_missing__pid(itm.Pid());
itm.Welcome(lbl_gatherer);
Wbase_claim_grp_list qual_list = itm.Qualifiers();
if (qual_list != null) {
int qual_list_len = qual_list.Len();
for (int k = 0; k < qual_list_len; ++k) {
Wbase_claim_grp qual_grp = qual_list.Get_at(k);
int qual_grp_len = qual_grp.Len();
for (int m = 0; m < qual_grp_len; ++m) {
Wbase_claim_base qual = qual_grp.Get_at(m);
this.Queue_if_missing__pid(qual.Pid());
qual.Welcome(lbl_gatherer);
}
}
}
Wbase_references_grp[] ref_grp_ary = itm.References();
if (ref_grp_ary != null) {
int ref_grp_ary_len = ref_grp_ary.length;
for (int k = 0; k < ref_grp_ary_len; ++k) {
Wbase_references_grp ref_grp = ref_grp_ary[k];
Wbase_claim_grp_list ref_list = ref_grp.References();
int ref_list_len = ref_list.Len();
for (int m = 0; m < ref_list_len; ++m) {
Wbase_claim_grp claim_grp = ref_list.Get_at(m);
int claim_grp_len = claim_grp.Len();
for (int n = 0; n < claim_grp_len; ++n) {
Wbase_claim_base claim = claim_grp.Get_at(n);
this.Queue_if_missing__pid(claim.Pid());
claim.Welcome(lbl_gatherer);
}
}
}
}
}
}
Ordered_hash slink_list = wdoc.Slink_list();
len = slink_list.Count();
for (int i = 0; i < len; ++i) {
Wdata_sitelink_itm itm = (Wdata_sitelink_itm)slink_list.Get_at(i);
byte[][] badges = itm.Badges();
int badges_len = badges.length;
for (int j = 0; j < badges_len; ++j) {
byte[] badge = badges[j];
this.Queue_if_missing__ttl(badge, Bool_.Y); // badges has qid; EX: ["Q1", "Q2"]
}
}
wkr.Resolve(this, sorter);
}
public static int Qid_int(byte[] qid) {
byte qid_0 = qid[0];
if (qid_0 != Byte_ascii.Ltr_Q && qid_0 != Byte_ascii.Ltr_q) return -1;
return Bry_.To_int_or(qid, 1, qid.length, -1);
}
}

View File

@@ -0,0 +1,22 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.wbases.core.*;
public interface Wdata_lbl_wkr {
void Resolve(Wdata_lbl_mgr lbl_mgr, Wdata_lang_sorter sorter);
}

View File

@@ -0,0 +1,50 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.langs.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.apps.apis.xowa.xtns.*;
public class Wdata_lbl_wkr_wiki implements Wdata_lbl_wkr {
private Wdata_wiki_mgr wdata_mgr;
private Xoapi_wikibase wikibase_api;
public Wdata_lbl_wkr_wiki(Xoapi_wikibase wikibase_api, Wdata_wiki_mgr wdata_mgr) {this.wikibase_api = wikibase_api; this.wdata_mgr = wdata_mgr;}
public void Resolve(Wdata_lbl_mgr lbl_mgr, Wdata_lang_sorter sorter) {
List_adp queue = lbl_mgr.Queue();
int len = queue.Count();
for (int i = 0; i < len; ++i) {
Wdata_lbl_itm itm = (Wdata_lbl_itm)queue.Get_at(i);
Wdata_doc wdoc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(itm.Ttl());
if (wdoc == null) {
Xoa_app_.Usr_dlg().Warn_many("", "", "wbase.lbl_wkr:page does not exists; page=~{0}", itm.Ttl());
continue; // handle incomplete wikidata dumps; DATE:2015-06-11
}
Ordered_hash labels = wdoc.Label_list();
if (labels.Count() == 0) continue;
labels.Sort_by(sorter);
Wdata_langtext_itm label = Wdata_langtext_itm.Get_itm_or_null(wdoc.Label_list(), wikibase_api.Core_langs());
if (label == null)
itm.Load_vals(Bry_.Empty, itm.Ttl()); // NOTE: use itm.Ttl() in case no label is found for the core_lang
else {
itm.Load_vals(label.Lang(), label.Text());
if (itm.Text_en_enabled()) {
Wdata_langtext_itm en_label = (Wdata_langtext_itm)labels.Get_by(Xol_lang_itm_.Key_en);
itm.Text_en_(en_label == null ? Bry_.Empty : en_label.Text());
}
}
}
}
}

View File

@@ -0,0 +1,83 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.apps.apis.xowa.html.*;
import gplx.xowa.wikis.domains.*;
class Wdata_slink_grp {
public Wdata_slink_grp(int tid, byte[] wiki_name, Xoapi_toggle_itm toggle_itm, Wdata_toc_data toc_data) {
this.tid = tid; this.wiki_name = wiki_name; this.toggle_itm = toggle_itm; this.toc_data = toc_data;
}
public int Tid() {return tid;} private final int tid;
public byte[] Wiki_name() {return wiki_name;} private final byte[] wiki_name;
public Wdata_toc_data Toc_data() {return toc_data;} private final Wdata_toc_data toc_data;
public Xoapi_toggle_itm Toggle_itm() {return toggle_itm;} private Xoapi_toggle_itm toggle_itm;
public Ordered_hash Rows() {return rows;} private final Ordered_hash rows = Ordered_hash_.New();
public static void Sift(Wdata_slink_grp[] rv, Ordered_hash list) {
for (int i = 0; i < Idx__len; ++i)
rv[i].Rows().Clear();
int list_len = list.Count();
for (int i = 0; i < list_len; ++i) {
Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.Get_at(i);
int idx = Idx_by_tid(itm.Domain_info().Domain_type_id());
rv[idx].Rows().Add(itm.Site(), itm);
}
}
public static int Idx_by_tid(int tid) {
switch (tid) {
case Xow_domain_tid_.Int__wikipedia: return Idx_w;
case Xow_domain_tid_.Int__wiktionary: return Idx_d;
case Xow_domain_tid_.Int__wikisource: return Idx_s;
case Xow_domain_tid_.Int__wikivoyage: return Idx_v;
case Xow_domain_tid_.Int__wikiquote: return Idx_q;
case Xow_domain_tid_.Int__wikibooks: return Idx_b;
case Xow_domain_tid_.Int__wikiversity: return Idx_u;
case Xow_domain_tid_.Int__wikinews: return Idx_n;
default: return Idx_x;
}
}
public static byte[] Msg_by_tid(Wdata_hwtr_msgs msgs, int tid) {
switch (tid) {
case Idx_w: return msgs.Slink_tbl_hdr_w();
case Idx_d: return msgs.Slink_tbl_hdr_d();
case Idx_s: return msgs.Slink_tbl_hdr_s();
case Idx_v: return msgs.Slink_tbl_hdr_v();
case Idx_q: return msgs.Slink_tbl_hdr_q();
case Idx_b: return msgs.Slink_tbl_hdr_b();
case Idx_u: return msgs.Slink_tbl_hdr_u();
case Idx_n: return msgs.Slink_tbl_hdr_n();
case Idx_x: return msgs.Slink_tbl_hdr_x();
default: throw Err_.new_unhandled(tid);
}
}
public static byte[] Name_by_tid(int idx) {
switch (idx) {
case Idx_w: return Xow_domain_tid_.Bry__wikipedia;
case Idx_d: return Xow_domain_tid_.Bry__wiktionary;
case Idx_s: return Xow_domain_tid_.Bry__wikisource;
case Idx_v: return Xow_domain_tid_.Bry__wikivoyage;
case Idx_q: return Xow_domain_tid_.Bry__wikiquote;
case Idx_b: return Xow_domain_tid_.Bry__wikibooks;
case Idx_u: return Xow_domain_tid_.Bry__wikiversity;
case Idx_n: return Xow_domain_tid_.Bry__wikinews;
case Idx_x: return Name_special;
default: throw Err_.new_unhandled(idx);
}
}
public static final int Idx__len = 9, Idx_w = 0, Idx_d = 1, Idx_s = 2, Idx_v = 3, Idx_q = 4, Idx_b = 5, Idx_u = 6, Idx_n = 7, Idx_x = 8;
private static final byte[] Name_special = Bry_.new_a7("special");
}

View File

@@ -0,0 +1,37 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.encoders.*;
class Wdata_toc_data {
private final Wdata_fmtr__toc_div fmtr_toc;
private final Gfo_url_encoder href_encoder;
private final Bry_fmtr text_fmtr = Bry_fmtr.new_("~{orig} <sup><small>(~{len})</small></sup>", "orig", "len");
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(8);
public Wdata_toc_data(Wdata_fmtr__toc_div fmtr_toc, Gfo_url_encoder href_encoder) {this.fmtr_toc = fmtr_toc; this.href_encoder = href_encoder;}
public Wdata_toc_data Make(int itms_len) {
this.text = itms_len_enable ? text_fmtr.Bld_bry_many(tmp_bfr, orig, itms_len) : orig;
this.href = href_encoder.Encode(orig);
fmtr_toc.Add(this);
return this;
}
public Wdata_toc_data Itms_len_enable_n_() {itms_len_enable = false; return this;} private boolean itms_len_enable = true;
public byte[] Orig() {return orig;} public void Orig_(byte[] v) {orig = v;} private byte[] orig;
public byte[] Href() {return href;} private byte[] href;
public byte[] Text() {return text;} private byte[] text;
}

View File

@@ -0,0 +1,98 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
class Wdata_visitor__html_wtr implements Wbase_claim_visitor {
private byte[] ttl; private Bry_bfr tmp_bfr; private Wdata_hwtr_msgs msgs; private Wdata_lbl_mgr lbl_mgr;
private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_(); private final Bry_bfr tmp_time_bfr = Bry_bfr_.New_w_size(32);
public Wdata_visitor__html_wtr Init(byte[] ttl, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wdata_lbl_mgr lbl_mgr) {
this.ttl = ttl; this.tmp_bfr = tmp_bfr; this.msgs = msgs; this.lbl_mgr = lbl_mgr;
return this;
}
public void Visit_str(Wbase_claim_string itm) {
tmp_bfr.Add(itm.Val_str());
}
public void Visit_entity(Wbase_claim_entity itm) {
int entity_id = itm.Entity_id();
byte[] text = itm.Entity_tid_is_qid() ? lbl_mgr.Get_text__qid(entity_id) : lbl_mgr.Get_text__pid(entity_id);
if (text == null) {// handle incomplete wikidata dumps; DATE:2015-06-11
Xoa_app_.Usr_dlg().Warn_many("", "", "wbase.html_visitor:page does not exists; page=~{0}", entity_id);
return;
}
Wdata_hwtr_mgr.Write_link_wikidata(tmp_bfr, itm.Page_ttl_gui(), text);
}
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {
tmp_bfr.Add(itm.Text());
tmp_bfr.Add_byte(Byte_ascii.Space).Add_byte(Byte_ascii.Brack_bgn).Add(itm.Lang()).Add_byte(Byte_ascii.Brack_end);
}
public void Visit_quantity(Wbase_claim_quantity itm) {
try {
Decimal_adp val = itm.Amount_as_num();
Decimal_adp hi = itm.Ubound_as_num();
Decimal_adp lo = itm.Lbound_as_num();
Decimal_adp hi_diff = hi.Subtract(val);
Decimal_adp lo_diff = val.Subtract(lo);
float hi_diff_val = (float)hi_diff.To_double();
float lo_diff_val = (float)lo_diff.To_double();
tmp_bfr.Add(itm.Amount()).Add_byte_space();
if (hi_diff.Eq(lo_diff)) { // delta is same in both directions; EX: val=50 hi=60 lo=40 -> hi_diff == lo_diff == 10
if (hi_diff_val != 0) // skip if 0
tmp_bfr.Add(msgs.Sym_plusminus()).Add_str_a7(hi_diff.To_str());
}
else { // delta is diff in both directions; EX: val=50 hi=60 lo=30 -> hi_diff == 10, lo_diff == 20
if (hi_diff_val != 0) // skip if 0
tmp_bfr.Add(msgs.Sym_plus()).Add_str_a7(hi_diff.To_str());
if (lo_diff_val != 0) { // skip if 0
if (hi_diff_val != 0) tmp_bfr.Add(Time_plus_minus_spr);
tmp_bfr.Add(msgs.Sym_minus()).Add_str_a7(lo_diff.To_str());
}
}
byte[] unit = itm.Unit();
if (!Bry_.Eq(unit, Wbase_claim_quantity.Unit_1))
tmp_bfr.Add_byte_space().Add(unit);
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to write quantity; ttl=~{0} pid=~{1} err=~{2}", ttl, itm.Pid(), Err_.Message_gplx_full(e));
}
} private static final byte[] Time_plus_minus_spr = Bry_.new_a7(" / ");
public void Visit_time(Wbase_claim_time itm) {itm.Write_to_bfr(tmp_bfr, tmp_time_bfr, tmp_time_fmtr, msgs, ttl);}
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
try {
Decimal_adp precision_frac = itm.Prc_as_num(); // precision is a decimal; EX: .00027777
int precision_int = Math_.Log10(Decimal_adp_.One.Divide(precision_frac).To_int()); // convert precision to log10 integer; EX: .00027777 -> 3600 -> 3
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(tmp_bfr, Bool_.Y, itm.Lng(), precision_int);
tmp_bfr.Add_byte_comma().Add_byte_space();
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(tmp_bfr, Bool_.N, itm.Lat(), precision_int);
byte[] glb_ttl = itm.Glb_ttl();
if (glb_ttl != null) {
byte[] glb_lbl = lbl_mgr.Get_text__ttl(glb_ttl, itm.Glb());
tmp_bfr.Add_byte_space().Add_byte(Byte_ascii.Paren_bgn);
Wdata_hwtr_mgr.Write_link_wikidata(tmp_bfr, glb_ttl, glb_lbl);
tmp_bfr.Add_byte(Byte_ascii.Paren_end);
}
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to write globecoordinate; ttl=~{0} pid=~{1} err=~{2}", ttl, itm.Pid(), Err_.Message_gplx_full(e));
}
}
public void Visit_system(Wbase_claim_value itm) {
switch (itm.Snak_tid()) {
case Wbase_claim_value_type_.Tid__somevalue: tmp_bfr.Add(msgs.Val_tid_somevalue()); break;
case Wbase_claim_value_type_.Tid__novalue: tmp_bfr.Add(msgs.Val_tid_novalue()); break;
}
}
}

View File

@@ -0,0 +1,89 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.apps.apis.xowa.html.*;
public class Wdata_visitor__html_wtr_tst {
@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
@Test public void Monolingualtext() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto")
, "Motto [en]"
);
}
@Test public void Time() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Wbase_date.Fmt_ymdhns)
, "4:05:06 3 Feb 2001"
);
}
@Test public void Quantity_ubound_lbound() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "units", "60", "30")
, "50 +10 / -20 units"
);
}
@Test public void Quantity_same() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "units", "60", "40")
, "50 ±10 units"
);
}
@Test public void Quantity_frac() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_quantity(1, "+0.1234", "units", "+0.1235", "+0.1233")
, "+0.1234 ±0.0001 units"
);
}
@Test public void Entity_qid() {
fxt
.Init_resolved_qid(1, "item_1")
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_entity_qid(1, 1)
, "<a href='/wiki/Q1'>item_1</a>"
);
}
@Test public void Entity_pid() {
fxt
.Init_resolved_pid(1, "item_1")
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_entity_pid(1, 1)
, "<a href='/wiki/Property:P1'>item_1</a>"
);
}
@Test public void Globecoordinate() {
fxt
.Init_resolved_qid(2, "Earth")
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
, "51° 30' 26&quot; N, 0° 7' 39&quot; W (<a href='/wiki/Q2'>Earth</a>)"
);
}
@Test public void Globecoordinate_null() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
, "51° 30' 26&quot; N, 0° 7' 39&quot; W"
);
}
}

View File

@@ -0,0 +1,43 @@
/*
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.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
class Wdata_visitor__lbl_gatherer implements Wbase_claim_visitor {
private Wdata_lbl_mgr lbl_mgr;
public Wdata_visitor__lbl_gatherer(Wdata_lbl_mgr lbl_mgr) {this.lbl_mgr = lbl_mgr;}
public void Visit_entity(Wbase_claim_entity itm) {
if (itm.Entity_tid_is_qid())
lbl_mgr.Queue_if_missing__qid(itm.Entity_id());
else
lbl_mgr.Queue_if_missing__pid(itm.Entity_id());
}
public void Visit_time(Wbase_claim_time itm) {
byte[] ttl = Wdata_lbl_itm.Extract_ttl(itm.Calendar());
itm.Calendar_ttl_(ttl);
lbl_mgr.Queue_if_missing__ttl(ttl);
}
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
byte[] ttl = Wdata_lbl_itm.Extract_ttl(itm.Glb());
itm.Glb_ttl_(ttl);
lbl_mgr.Queue_if_missing__ttl(ttl);
}
public void Visit_str(Wbase_claim_string itm) {}
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {}
public void Visit_quantity(Wbase_claim_quantity itm) {}
public void Visit_system(Wbase_claim_value itm) {}
}

View File

@@ -0,0 +1,73 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.core.criterias.*; import gplx.core.envs.*;
class Io_stream_rdr_mgr {
public static Io_stream_rdr Get_rdr_or_null(Io_url src_fil, Io_url src_dir, Io_stream_unzip_mgr unzip_mgr, String... filter_ary) {
IoItmFil src_itm = null;
if (src_fil != null) src_itm = Io_mgr.Instance.QueryFil(src_fil);
// specified file doesn't exist; try to find similar file based on filter
if (src_itm == null || !src_itm.Exists()) {
src_itm = Get_itm_by_filters(src_dir, filter_ary);
if (src_itm == null) return null;
}
// return rdr
Io_url src_itm_url = src_itm.Url();
Io_stream_rdr rv = unzip_mgr.Handles(src_itm_url)
? unzip_mgr.New_rdr(src_itm_url)
: Io_stream_rdr_.file_(src_itm_url);
rv.Len_(src_itm.Size());
return rv;
}
private static IoItmFil Get_itm_by_filters(Io_url dir, String... filter_ary) {
// create array of matches based on filters
int match_ary_len = filter_ary.length;
Criteria_ioMatch[] match_ary = new Criteria_ioMatch[match_ary_len];
for (int i = 0; i < match_ary_len; ++i)
match_ary[i] = Criteria_ioMatch.parse(true, filter_ary[i], dir.Info().CaseSensitive());
// get files and check each file for match
IoItmFil rv = null;
IoItmHash itm_hash = Io_mgr.Instance.QueryDir_args(dir).ExecAsItmHash();
int len = itm_hash.Count();
for (int i = 0; i < len; ++i) {
IoItm_base itm = itm_hash.Get_at(i);
for (int j = 0; j < match_ary_len; ++j) {
if (itm.Type_fil() && match_ary[j].Matches(itm.Url()))
rv = (IoItmFil)itm; // NOTE: this will return the last match; useful for getting latest dump when multiple dumps are in one dir; (assuming latest should alphabetize last)
}
}
return rv;
}
}
class Io_stream_unzip_mgr {
private final String[] zip_exts;
private final boolean stdout_enabled; private final Process_adp stdout_process;
public Io_stream_unzip_mgr(boolean stdout_enabled, Process_adp stdout_process, String[] zip_exts) {
this.stdout_enabled = stdout_enabled; this.stdout_process = stdout_process; this.zip_exts = zip_exts;
}
public boolean Handles(Io_url url) {return String_.In(url.Ext(), zip_exts);}
public Io_stream_rdr New_rdr(Io_url url) {
return stdout_enabled
? Io_stream_rdr_process.new_(stdout_process.Exe_url(), url, stdout_process.Xto_process_bldr_args(url.Raw()))
: Io_stream_rdr_.bzip2_(url)
;
}
}

View File

@@ -0,0 +1,42 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*; import gplx.core.ios.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.parsers.*;
import gplx.xowa.xtns.wbases.imports.*;
abstract class Wdata_idx_mgr_base {
public void Ctor(Xob_itm_dump_base wkr, Xob_bldr bldr, Xowe_wiki wiki, int dump_fil_len) {
this.wkr = wkr; this.wiki = wiki; this.bldr = bldr; this.dump_fil_len = dump_fil_len;
} Xob_itm_dump_base wkr; protected Xowe_wiki wiki; Xob_bldr bldr; Xol_csv_parser csv_parser = Xol_csv_parser.Instance; protected Ordered_hash hash = Ordered_hash_.New(); protected int dump_fil_len;
public void Flush() {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Wdata_idx_wtr wtr = (Wdata_idx_wtr)hash.Get_at(i);
wtr.Flush();
}
}
public void Make() {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Wdata_idx_wtr wtr = (Wdata_idx_wtr)hash.Get_at(i);
wtr.Make(bldr.Usr_dlg(), wkr.Make_fil_len());
}
if (wkr.Delete_temp()) Io_mgr.Instance.DeleteDirDeep(wkr.Temp_dir());
}
}

View File

@@ -0,0 +1,54 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.ios.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*;
class Wdata_idx_wtr {
public Wdata_idx_wtr(Io_url dump_dir, int dump_fil_max, Io_url make_dir) {
this.dump_dir = dump_dir;
this.dump_fil_max = dump_fil_max;
dump_url_gen = Io_url_gen_.dir_(dump_dir);
this.make_dir = make_dir;
} private Bry_bfr dump_bfr = Bry_bfr_.Reset(2 * Io_mgr.Len_kb); int dump_fil_max; Io_url dump_dir, make_dir; Io_url_gen dump_url_gen;
public void Write(byte[] ttl, byte[] qid) {
if (dump_bfr.Len() + ttl.length + qid.length + 2 > dump_fil_max) Flush(); // 2 = "|" + "\n"; NOTE: all items have format of "data|qid\n"
dump_bfr.Add(ttl).Add_byte_pipe().Add(qid).Add_byte_nl();
}
public void Flush() {
Io_mgr.Instance.AppendFilBfr(dump_url_gen.Nxt_url(), dump_bfr);
}
public void Make(Gfo_usr_dlg usr_dlg, int make_fil_len) {
Xobdc_merger.Basic(usr_dlg, dump_url_gen, dump_dir.OwnerDir().GenSubDir("sort"), dump_fil_max, Io_line_rdr_key_gen_.first_pipe, new Xob_make_cmd_site(usr_dlg, make_dir, make_fil_len));
}
public static Wdata_idx_wtr new_qid_(Xowe_wiki wdata_wiki, String wiki_str, String ns_num, int dump_fil_max) {
Io_url dump_dir = wdata_wiki.Fsys_mgr().Tmp_dir().GenSubDir_nest("wdata.qid", "qid", wiki_str, ns_num, "dump"); // /xowa/wiki/www.wikidata.org/tmp/wdata_qid/ + enwiki/000/dump/
Io_url make_dir = dir_qid_(wdata_wiki, wiki_str, ns_num); // /xowa/wiki/www.wikidata.org/site/data/qid/ + enwiki/000/
return new Wdata_idx_wtr(dump_dir, dump_fil_max, make_dir);
}
public static Wdata_idx_wtr new_pid_(Xowe_wiki wdata_wiki, String lang_key, int dump_fil_max) {
Io_url dump_dir = wdata_wiki.Fsys_mgr().Tmp_dir().GenSubDir_nest("wdata.pid", "pid", lang_key, "dump"); // /xowa/wiki/www.wikidata.org/tmp/wdata_pid/ + en/
Io_url make_dir = dir_pid_(wdata_wiki, lang_key); // /xowa/wiki/www.wikidata.org/site/data/pid/ + en/
return new Wdata_idx_wtr(dump_dir, dump_fil_max, make_dir);
}
public static Io_url dir_qid_(Xowe_wiki wiki, String wiki_str, String ns_num) {
return wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid", wiki_str, ns_num); // /xowa/wiki/www.wikidata.org/site/data/ + qid/enwiki/000/
}
public static Io_url dir_pid_(Xowe_wiki wiki, String lang_key) {
return wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid", lang_key); // /xowa/wiki/www.wikidata.org/site/data/ + pid/en/
}
}

View File

@@ -0,0 +1,38 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xob_wbase_json_dump_cmd implements Xob_cmd {
private final Xob_wbase_json_dump_parser json_dump_parser;
private Io_url src_fil;
public Xob_wbase_json_dump_cmd(Xob_bldr bldr, Xowe_wiki wiki) {
this.json_dump_parser = new Xob_wbase_json_dump_parser(bldr, wiki);
}
public String Cmd_key() {return Xob_cmd_keys.Key_wbase_json_dump;}
public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return null;}
public void Cmd_run() {json_dump_parser.Parse(src_fil);}
public void Cmd_init(Xob_bldr bldr) {}
public void Cmd_bgn(Xob_bldr bldr) {}
public void Cmd_end() {}
public void Cmd_term() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_src_fil_)) this.src_fil = m.ReadIoUrl("v");
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_src_fil_ = "src_fil_";
}

View File

@@ -0,0 +1,92 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.ios.*;
import gplx.langs.jsons.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.bldrs.cmds.texts.sqls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.apps.apis.xowa.bldrs.imports.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*;
class Xob_wbase_json_dump_db {
private final Gfo_usr_dlg usr_dlg; private final Xoae_app app; private final Xowe_wiki wiki; private final Xob_bldr bldr;
private final Json_parser json_parser;
private final Xob_wdata_pid_sql pid_cmd = new Xob_wdata_pid_sql(); private final Xob_wdata_qid_sql qid_cmd = new Xob_wdata_qid_sql();
private Xowd_page_tbl page_tbl;
private Xob_ns_to_db_mgr ns_to_db_mgr;
private DateAdp page_modified_on;
private Xow_db_mgr db_mgr;
private Xowd_page_tbl page_core_tbl;
private Io_stream_zip_mgr text_zip_mgr; private byte text_zip_tid;
private Xow_ns_mgr ns_mgr;
public Xob_wbase_json_dump_db(Xob_bldr bldr, Xowe_wiki wiki) {
this.app = bldr.App(); this.usr_dlg = app.Usr_dlg(); this.wiki = wiki; this.bldr = bldr;
this.json_parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
this.ns_mgr = wiki.Ns_mgr();
}
public void Parse_bgn(long src_fil_len, String src_fil_name) {
Xowe_wiki_.Create(wiki, src_fil_len, src_fil_name);
this.db_mgr = wiki.Data__core_mgr();
this.page_tbl = db_mgr.Tbl__page();
pid_cmd.Cmd_ctor(bldr, wiki); qid_cmd.Cmd_ctor(bldr, wiki);
wiki.Ns_mgr().Add_defaults();
wiki.Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, Wdata_wiki_mgr.Ns_property_name);
wiki.Ns_mgr().Init();
Xoapi_import import_cfg = app.Api_root().Bldr().Wiki().Import();
this.ns_to_db_mgr = new Xob_ns_to_db_mgr(new Xob_ns_to_db_wkr__text(), db_mgr, import_cfg.Text_db_max());
this.text_zip_mgr = wiki.Utl__zip_mgr(); text_zip_tid = import_cfg.Zip_tid_text();
byte[] ns_file_map = import_cfg.New_ns_file_map(src_fil_len);
Xob_ns_file_itm.Init_ns_bldr_data(Xow_db_file_.Tid__text, wiki.Ns_mgr(), ns_file_map);
this.page_modified_on = Datetime_now.Get();
this.page_core_tbl = db_mgr.Tbl__page();
page_tbl.Insert_bgn();
qid_cmd.Page_wkr__bgn();
pid_cmd.Pid_bgn();
}
private int page_id = 0, page_count_main = 0;
public void Parse_cmd(byte[] json_bry) {
Json_doc jdoc = json_parser.Parse(json_bry);
if (jdoc == null) {usr_dlg.Warn_many("", "", "wbase.json_dump:json is invalid: json=~{0}", json_bry); return;}
byte[] id = jdoc.Get_val_as_bry_or(id_key, null);
if (id == null) {usr_dlg.Warn_many("", "", "wbase.json_dump:id is invalid: json=~{0}", json_bry); return;}
boolean jdoc_is_qid = Bry_.Has_at_bgn(id, Byte_ascii.Ltr_Q, 0);
Xow_ns ns = jdoc_is_qid ? ns_mgr.Ns_main() : ns_mgr.Ids_get_or_null(Wdata_wiki_mgr.Ns_property);
int random_int = ns.Count() + 1; ns.Count_(random_int);
byte[] json_zip = text_zip_mgr.Zip(text_zip_tid, json_bry);
Xow_db_file text_db = ns_to_db_mgr.Get_by_ns(ns.Bldr_data(), json_zip.length);
db_mgr.Create_page(page_core_tbl, text_db.Tbl__text(), ++page_id, ns.Id(), id, Bool_.N, page_modified_on, json_zip, json_bry.length, random_int, text_db.Id(), -1);
if (jdoc_is_qid) {
qid_cmd.Parse_jdoc(jdoc);
++page_count_main;
}
else
pid_cmd.Parse_jdoc(jdoc);
}
public void Parse_end() {
page_tbl.Insert_end();
page_tbl.Create_idx();
qid_cmd.Qid_end();
pid_cmd.Pid_end();
ns_to_db_mgr.Rls_all();
Xow_db_file db_core = db_mgr.Db__core();
db_core.Tbl__site_stats().Update(page_count_main, page_id, ns_mgr.Ns_file().Count()); // save page stats
db_core.Tbl__ns().Insert(ns_mgr); // save ns
db_mgr.Tbl__cfg().Insert_str(Xow_cfg_consts.Grp__wiki_init, Xow_cfg_consts.Key__init__modified_latest, page_modified_on.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
}
private static final byte[] id_key = Bry_.new_a7("id");
}

View File

@@ -0,0 +1,90 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.ios.*; import gplx.core.ios.streams.*;
import gplx.xowa.bldrs.*;
import gplx.xowa.wikis.data.tbls.*;
class Xob_wbase_json_dump_parser {
private final Gfo_usr_dlg usr_dlg; private final Xoae_app app; private final Xob_bldr bldr; private final Xowe_wiki wiki;
private final Xob_wbase_json_dump_db dump_db;
private final Io_stream_unzip_mgr unzip_mgr;
public Xob_wbase_json_dump_parser(Xob_bldr bldr, Xowe_wiki wiki) {
this.bldr = bldr; this.wiki = wiki;
this.app = bldr.App(); this.usr_dlg = app.Usr_dlg();
this.dump_db = new Xob_wbase_json_dump_db(bldr, wiki);
this.unzip_mgr = new Io_stream_unzip_mgr(app.Setup_mgr().Dump_mgr().Import_bz2_by_stdout(), app.Prog_mgr().App_decompress_bz2_by_stdout(), String_.Ary(".bz2", ".gz", ".zip"));
}
public void Parse(Io_url src_fil) {
byte[] json_bgn = Bry_.new_a7("[\n"), id_bgn = Bry_.new_a7("{\"id\":");
String prog_fmt = "reading ~{0} MB: ~{1} ~{2}";
Io_stream_rdr stream_rdr = Io_stream_rdr_mgr.Get_rdr_or_null(src_fil, wiki.Fsys_mgr().Root_dir(), unzip_mgr, "*wikidata-*-all.json", "*wikidata-*-all.json.gz");
if (stream_rdr == null) {usr_dlg.Warn_many("", "", "wbase.import:file not found: src_dir=~{0}", wiki.Fsys_mgr().Root_dir()); return;}
Io_buffer_rdr buffer_rdr = Io_buffer_rdr.new_(stream_rdr, 10 * Io_mgr.Len_mb); long buffer_rdr_len = buffer_rdr.Fil_len();
try {
Io_url stream_rdr_url = stream_rdr.Url();
int page_bgn = Bry_find_.Find_fwd(buffer_rdr.Bfr(), id_bgn);
if (page_bgn == Bry_find_.Not_found) {usr_dlg.Warn_many("", "", "wbase.import:initial id not found: url=~{0}", stream_rdr_url.Raw()); return;}
if (!Bry_.Match(buffer_rdr.Bfr(), 0, page_bgn, json_bgn)) {usr_dlg.Warn_many("", "", "wbase.import:doc_bgn is not '[\n': url=~{0}", stream_rdr_url.Raw()); return;}
Xowd_page_itm page = new Xowd_page_itm();
dump_db.Parse_bgn(stream_rdr.Len(), stream_rdr.Url().NameAndExt());
while (true) {
int cur_pos = Extract_page(page, buffer_rdr, page_bgn);
if (cur_pos == -1) break;
if (cur_pos < page_bgn)
bldr.Print_prog_msg(buffer_rdr.Fil_pos(), buffer_rdr_len, 1, prog_fmt, Int_.To_str_pad_bgn_zero((int)(buffer_rdr.Fil_pos() / Io_mgr.Len_mb), Int_.DigitCount((int)(buffer_rdr.Fil_len() / Io_mgr.Len_mb))), "", page.Ttl_page_db());
page_bgn = cur_pos;
}
dump_db.Parse_end();
}
catch (Exception e) {
String msg = usr_dlg.Warn_many("", "", "dump_rdr:error while reading; url=~{0} err=~{1}", src_fil.Raw(), Err_.Message_lang(e));
throw Err_.new_wo_type(msg);
}
finally {buffer_rdr.Rls();}
}
private int Extract_page(Xowd_page_itm page, Io_buffer_rdr rdr, int page_bgn) {
int pos = page_bgn;
byte[] bry = rdr.Bfr();
int bry_len = rdr.Bfr_len();
while (true) {
if (pos == bry_len) {
rdr.Bfr_load_from(page_bgn); // refill src from pos;
bry_len = rdr.Bfr_len();
pos -= page_bgn;
page_bgn = 0;
}
byte b = Byte_.Zero;
boolean exit = false;
if (pos < bry_len)
b = bry[pos];
else {
b = Byte_ascii.Nl;
pos = bry_len;
exit = true;
}
if (b == Byte_ascii.Nl) {
byte[] json_bry = Bry_.Mid(bry, page_bgn, pos);
if (json_bry.length == 1 && json_bry[0] == Byte_ascii.Brack_end) return -1;
if (exit) return -1;
dump_db.Parse_cmd(json_bry);
return pos + 1;
}
++pos;
}
}
}

View File

@@ -0,0 +1,51 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.dbs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.bldrs.wms.sites.*;
class Xob_wbase_ns_parser {
private final Hash_adp_bry ns_mgr_hash = Hash_adp_bry.cs();
private final Site_core_db core_db;
public Xob_wbase_ns_parser(Io_url url) {
this.core_db = new Site_core_db(url);
}
public void Find(Xob_wbase_ns_parser_rslt rv, byte[] wiki_abrv, byte[] ttl) { // enwiki, Category:Abc
Xow_ns_mgr ns_mgr = (Xow_ns_mgr)ns_mgr_hash.Get_by_bry(wiki_abrv);
rv.Init(Xow_ns_.Tid__main, 0); // default to Main ns
int ttl_len = ttl.length;
int colon_pos = Bry_find_.Find_fwd(ttl, Byte_ascii.Colon, 0, ttl_len); if (colon_pos == Bry_find_.Not_found) return;
if (ns_mgr == null) { // ns_mgr not found; load from db
wiki_abrv = Bry_.Replace(wiki_abrv, Byte_ascii.Underline, Byte_ascii.Dash);
byte[] wiki_domain = Xow_abrv_wm_.Parse_to_domain_bry(wiki_abrv);
ns_mgr = core_db.Load_namespace(wiki_domain);
if (ns_mgr.Count() == 0) {Xoa_app_.Usr_dlg().Warn_many("", "", "wbase.ns_parser:no ns found; abrv=~{0}", wiki_abrv); return;}
ns_mgr_hash.Add_bry_obj(wiki_abrv, ns_mgr);
}
Xow_ns ns = ns_mgr.Names_get_or_null(ttl, 0, colon_pos); if (ns == null) return; // not a ns; EX: "No_namespace:Page_title"
rv.Init(ns.Id(), colon_pos + 1);
}
}
class Xob_wbase_ns_parser_rslt {
public int Ns_id() {return ns_id;} private int ns_id;
public int Ttl_bgn() {return ttl_bgn;} private int ttl_bgn;
public void Init(int ns_id, int ttl_bgn) {
this.ns_id = ns_id; this.ttl_bgn = ttl_bgn;
}
}

View File

@@ -0,0 +1,424 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.engines.sqlite.*; import gplx.xowa.bldrs.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.origs.*;
import gplx.xowa.bldrs.wkrs.*;
import gplx.langs.jsons.*;
import gplx.xowa.langs.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.bldrs.cmds.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Xob_wdata_db_cmd extends Xob_dump_mgr_base implements Xob_cmd {
private Wdata_tbl_mgr tbl_mgr = new Wdata_tbl_mgr();
private Wdata_wiki_mgr wdata_mgr; private Json_parser json_parser;
private byte[] lang_key = Xol_lang_itm_.Key_en;
public Xob_wdata_db_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
@Override public String Cmd_key() {return Xob_cmd_keys.Key_wbase_db;}
@Override public byte Init_redirect() {return Bool_.N_byte;} // json will never be found in a redirect
@Override public int[] Init_ns_ary() {return Int_.Ary(Xow_ns_.Tid__main, Wdata_wiki_mgr.Ns_property);}
@Override protected void Init_reset(Db_conn conn) {
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
cfg_tbl.Delete_all();
}
@Override protected Db_conn Init_db_file() {
Xob_db_file tbl_file = Xob_db_file.New(wiki.Fsys_mgr().Root_dir(), "wdata_db.sqlite3");
Db_conn conn = tbl_file.Conn();
tbl_mgr.Init(conn);
return conn;
}
@Override protected void Cmd_bgn_end() {
wdata_mgr = bldr.App().Wiki_mgr().Wdata_mgr();
json_parser = wdata_mgr.Jdoc_parser();
tbl_mgr.Conn().Txn_bgn("bldr__wdata_db");
}
@Override public void Exec_pg_itm_hook(int ns_ord, Xow_ns ns, Xowd_page_itm page, byte[] page_src) {
Json_doc jdoc = json_parser.Parse(page_src); if (jdoc == null) return; // not a json document
Wdata_doc wdoc = new Wdata_doc(page.Ttl_page_db(), wdata_mgr, jdoc);
tbl_mgr.Exec_insert_by_wdoc(lang_key, wdata_mgr, page.Id(), wdoc);
}
@Override public void Exec_commit_hook() {
tbl_mgr.Conn().Txn_sav();
}
@Override public void Exec_end_hook() {
tbl_mgr.Term(usr_dlg);
}
}
class Wdata_tbl_mgr {
private Wdata_tbl_base[] tbls; private int tbls_len;
public Wdata_tbl_mgr() {
tbls = new Wdata_tbl_base[] {label_tbl, alias_tbl, description_tbl, link_tbl, claim_tbl, claim_time_tbl, claim_geo_tbl};
tbls_len = tbls.length;
}
public Db_conn Conn() {return conn;} private Db_conn conn;
public Wdata_label_tbl Label_tbl() {return label_tbl;} private Wdata_label_tbl label_tbl = new Wdata_label_tbl();
public Wdata_alias_tbl Alias_tbl() {return alias_tbl;} private Wdata_alias_tbl alias_tbl = new Wdata_alias_tbl();
public Wdata_description_tbl Description_tbl() {return description_tbl;} private Wdata_description_tbl description_tbl = new Wdata_description_tbl();
public Wdata_link_tbl Link_tbl() {return link_tbl;} private Wdata_link_tbl link_tbl = new Wdata_link_tbl();
public Wbase_claim_tbl Claim_tbl() {return claim_tbl;} private Wbase_claim_tbl claim_tbl = new Wbase_claim_tbl();
public Wbase_claim_time_tbl Claim_time_tbl() {return claim_time_tbl;} private Wbase_claim_time_tbl claim_time_tbl = new Wbase_claim_time_tbl();
public Wbase_claim_geo_tbl Claim_geo_tbl() {return claim_geo_tbl;} private Wbase_claim_geo_tbl claim_geo_tbl = new Wbase_claim_geo_tbl();
public void Init(Db_conn conn) {
this.conn = conn;
for (int i = 0; i < tbls_len; i++)
tbls[i].Init(conn);
}
public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) {
for (int i = 0; i < tbls_len; i++)
tbls[i].Exec_insert_by_wdoc(lang_key, wdata_mgr, page_id, wdoc);
}
public void Term(Gfo_usr_dlg usr_dlg) {
conn.Txn_end();
for (int i = 0; i < tbls_len; i++)
tbls[i].Make_idxs(usr_dlg, conn);
}
}
abstract class Wdata_tbl_base {
public abstract String Tbl_name();
public abstract String Tbl_create_sql();
public abstract Db_idx_itm[] Idx_ary();
public abstract String[] Fld_ary();
@gplx.Virtual public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) {}
public void Make_tbl(Db_conn p) {Sqlite_engine_.Tbl_create(p, this.Tbl_name(), this.Tbl_create_sql());}
public void Make_idxs(Gfo_usr_dlg usr_dlg, Db_conn p) {
Sqlite_engine_.Idx_create(usr_dlg, p, this.Tbl_name(), this.Idx_ary());
}
public Db_stmt Make_insert_stmt(Db_conn p) {return Db_stmt_.new_insert_(p, this.Tbl_name(), this.Fld_ary());}
public Db_stmt Insert_stmt() {return insert_stmt;} private Db_stmt insert_stmt;
public void Init(Db_conn conn) {
this.Make_tbl(conn);
insert_stmt = this.Make_insert_stmt(conn);
}
public static void Exec_insert_kvs(Db_stmt stmt, int page_id, Ordered_hash hash) {
int len = hash.Count();
for (int i = 0; i < len; i++) {
Json_kv kv = (Json_kv)hash.Get_at(i);
stmt.Clear()
.Val_int(page_id)
.Val_bry_as_str(kv.Key().Data_bry())
.Val_bry_as_str(kv.Val().Data_bry())
.Exec_insert();
}
}
}
class Wdata_label_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_label";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_label"
, "( page_id integer NOT NULL"
, ", lang_key varchar(16) NOT NULL"
, ", val varchar(255) NOT NULL"
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {return new Db_idx_itm[] {Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_label__main ON wdata_label (page_id, lang_key);")};}
@Override public String[] Fld_ary() {return new String[] {Fld_page_id, Fld_lang_key, Fld_val};}
@Override public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) {Exec_insert_kvs(this.Insert_stmt(), page_id, wdoc.Label_list());}
private static final String Fld_page_id = "page_id", Fld_lang_key = "lang_key", Fld_val = "val";
}
class Wdata_alias_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_alias";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_alias"
, "( page_id integer NOT NULL"
, ", lang_key varchar(16) NOT NULL"
, ", val varchar(255) NOT NULL"
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {return new Db_idx_itm[] {Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_alias__main ON wdata_alias (page_id, lang_key);")};}
@Override public String[] Fld_ary() {return new String[] {Fld_page_id, Fld_lang_key, Fld_val};}
@Override public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) {
Ordered_hash hash = wdoc.Alias_list();
int len = hash.Count();
Db_stmt insert_stmt = this.Insert_stmt();
for (int i = 0; i < len; i++) {
Json_kv kv = (Json_kv)hash.Get_at(i);
byte[] key = kv.Key().Data_bry();
Json_grp val_grp = (Json_grp)kv.Val();
int val_grp_len = val_grp.Len();
for (int j = 0; j < val_grp_len; j++) {
Json_itm val_itm = val_grp.Get_at(j);
byte[] val = Bry_.Empty;
if (val_itm.Tid() == Json_itm_.Tid__str)
val = val_itm.Data_bry();
else if (val_itm.Tid() == Json_itm_.Tid__kv) { // EX: q80 and de aliases
val = ((Json_kv)val_itm).Val().Data_bry();
}
insert_stmt.Clear()
.Val_int(page_id)
.Val_bry_as_str(key)
.Val_bry_as_str(val)
.Exec_insert();
}
}
}
private static final String Fld_page_id = "page_id", Fld_lang_key = "lang_key", Fld_val = "val";
}
class Wdata_description_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_description";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_description"
, "( page_id integer NOT NULL"
, ", lang_key varchar(16) NOT NULL"
, ", val varchar(255) NOT NULL"
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {return new Db_idx_itm[] {Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_description__main ON wdata_description (page_id, lang_key);")};}
@Override public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) {Exec_insert_kvs(this.Insert_stmt(), page_id, wdoc.Descr_list());}
@Override public String[] Fld_ary() {return new String[] {Fld_page_id, Fld_lang_key, Fld_val};}
private static final String Fld_page_id = "page_id", Fld_lang_key = "lang_key", Fld_val = "val";
}
class Wdata_link_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_link";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_link"
, "( page_id integer NOT NULL"
, ", wiki_key varchar(255) NOT NULL"
, ", val varchar(255) NOT NULL"
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {return new Db_idx_itm[] {Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_link__main ON wdata_link (page_id, wiki_key);")};}
@Override public String[] Fld_ary() {return new String[] {Fld_page_id, Fld_wiki_key, Fld_val};}
@Override public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) {
Ordered_hash hash = wdoc.Slink_list();
int len = hash.Count();
Db_stmt insert_stmt = this.Insert_stmt();
for (int i = 0; i < len; i++) {
Json_kv kv = (Json_kv)hash.Get_at(i);
byte[] key = kv.Key().Data_bry();
Json_itm kv_val = kv.Val();
byte[] val = Bry_.Empty;
if (kv_val.Tid() == Json_itm_.Tid__str)
val = kv_val.Data_bry();
else {
Json_nde val_nde = (Json_nde)kv.Val();
Json_kv val_name_kv = (Json_kv)val_nde.Get_at(0); // ASSUME: 1st item is always "name" kv; EX: "name":"Earth"
val = val_name_kv.Val().Data_bry();
}
insert_stmt.Clear()
.Val_int(page_id)
.Val_bry_as_str(key)
.Val_bry_as_str(val)
.Exec_insert();
}
}
private static final String Fld_page_id = "page_id", Fld_wiki_key = "wiki_key", Fld_val = "val";
}
class Wbase_claim_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_claim";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_claim"
, "( claim_id integer NOT NULL"
, ", page_id integer NOT NULL"
, ", prop_id integer NOT NULL" // 60; P60
, ", val_tid smallint NOT NULL" // String;wikibase-entity-id;time;globecoordinate
, ", entity_tid smallint NOT NULL" // null;item
, ", entity_id integer NOT NULL" // null;123
, ", val_text varchar(255) NOT NULL"
, ", guid varchar(64) NOT NULL"
, ", rank integer NOT NULL"
, ", ref_count integer NOT NULL"
, ", qual_count integer NOT NULL"
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {
return new Db_idx_itm[]
{ Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_claim__main ON wdata_claim (page_id, prop_id, val_tid, entity_tid);")
};
}
@Override public String[] Fld_ary() {return new String[] {Fld_claim_id, Fld_page_id, Fld_prop_id, Fld_val_tid, Fld_entity_tid, Fld_entity_id, Fld_val_text, Fld_guid, Fld_rank, Fld_ref_count, Fld_qual_count};}
private int next_claim_id = 0;
private Xob_wdata_db_visitor visitor;
@Override public void Exec_insert_by_wdoc(byte[] lang_key, Wdata_wiki_mgr wdata_mgr, int page_id, Wdata_doc wdoc) {
if (visitor == null) visitor = new Xob_wdata_db_visitor(wdata_mgr);
visitor.Init(lang_key);
Ordered_hash list = wdoc.Claim_list();
int list_len = list.Count();
for (int i = 0; i < list_len; i++) {
Wbase_claim_grp claim_grp = (Wbase_claim_grp)list.Get_at(i);
int itms_len = claim_grp.Len();
int entity_id = -1;
byte[] claim_val = Bry_.Empty;
for (int j = 0; j < itms_len; j++) {
Wbase_claim_base claim = claim_grp.Get_at(j);
claim.Welcome(visitor);
claim_val = visitor.Rv();
Exec_insert(++next_claim_id, page_id, claim_grp.Id(), claim.Val_tid(), claim.Snak_tid(), entity_id, claim_val, claim.Wguid(), claim.Rank_tid(), 0, 0);
}
}
}
public void Exec_insert(int claim_id, int page_id, int prop_id, byte val_tid, byte entity_tid, int entity_id, byte[] val_text, byte[] guid, int rank, int ref_count, int qual_count) {
if (val_text == null) val_text = Bry_.Empty;
if (guid == null) guid = Bry_.Empty;
this.Insert_stmt().Clear()
.Val_int(claim_id)
.Val_int(page_id)
.Val_int(prop_id)
.Val_byte(val_tid)
.Val_byte(entity_tid)
.Val_int(entity_id)
.Val_bry_as_str(val_text)
.Val_bry_as_str(guid)
.Val_int(rank)
.Val_int(ref_count)
.Val_int(qual_count)
.Exec_insert();
}
private static final String Fld_claim_id = "claim_id", Fld_page_id = "page_id", Fld_prop_id = "prop_id", Fld_val_tid = "val_tid", Fld_entity_tid = "entity_tid", Fld_entity_id = "entity_id", Fld_val_text = "val_text"
, Fld_guid = "guid", Fld_rank = "rank", Fld_ref_count = "ref_count", Fld_qual_count = "qual_count"
;
}
class Wbase_claim_time_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_claim_time";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_claim_time"
, "( claim_id integer NOT NULL"
, ", time_val varchar(64) NOT NULL" // -04540000000-01-01T00:00:00Z
, ", time_tz integer NOT NULL" // 0
, ", time_before integer NOT NULL" // 0
, ", time_after integer NOT NULL" // 0
, ", time_precision integer NOT NULL" // 2; number of digits
, ", time_model varchar(64) NOT NULL" // http:\/\/www.wikidata.org\/entity\/Q1985727
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {
return new Db_idx_itm[] {
Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_claim_time__main ON wdata_claim_time (claim_id);")
};
}
@Override public String[] Fld_ary() {return new String[] {Fld_claim_id, Fld_time_val, Fld_time_tz, Fld_time_before, Fld_time_after, Fld_time_precision, Fld_time_model};}
public void Insert(Db_stmt stmt, int claim_id, byte[] time_val, int tz, int before, int after, int precision, byte[] model) {
stmt.Clear()
.Val_int(claim_id)
.Val_bry_as_str(time_val)
.Val_int(tz)
.Val_int(before)
.Val_int(after)
.Val_int(precision)
.Val_bry_as_str(model)
.Exec_insert();
}
private static final String Fld_claim_id = "claim_id", Fld_time_val = "time_val", Fld_time_tz = "time_tz", Fld_time_before = "time_before", Fld_time_after = "time_after", Fld_time_precision = "time_precision", Fld_time_model = "time_model";
}
class Wbase_claim_geo_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_claim_geo";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_claim_geo"
, "( claim_id integer NOT NULL"
, ", geo_latitude double NOT NULL" // 41.590833333333
, ", geo_longitude double NOT NULL" // -93.620833333333
, ", geo_altitude varchar(255) NOT NULL" // null
, ", geo_precision double NOT NULL" // 0.00027777777777778
, ", geo_globe integer NOT NULL" // http:\/\/www.wikidata.org\/entity\/Q2
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {
return new Db_idx_itm[]
{ Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_claim_geo__main ON wdata_claim_geo (claim_id);")
};
}
public void Insert(Db_stmt stmt, int claim_id, double latitude, double longitude, byte[] altitude, double precision, byte[] globe) {
stmt.Clear()
.Val_int(claim_id)
.Val_double(latitude)
.Val_double(longitude)
.Val_bry_as_str(altitude)
.Val_double(precision)
.Val_bry_as_str(globe)
.Exec_insert();
}
@Override public String[] Fld_ary() {return new String[] {Fld_claim_id, Fld_geo_latitude, Fld_geo_longitude, Fld_geo_altitude, Fld_geo_precision, Fld_geo_globe};}
private static final String Fld_claim_id = "claim_id", Fld_geo_latitude = "geo_latitude", Fld_geo_longitude = "geo_longitude", Fld_geo_altitude = "geo_altitude", Fld_geo_precision = "geo_precision", Fld_geo_globe = "geo_globe";
}
class Wdata_ref_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_ref";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_ref"
, "( ref_id integer NOT NULL"
, ", page_id integer NOT NULL"
, ", prop_id integer NOT NULL" // 60; P60
, ", val_tid smallint NOT NULL" // String;wikibase-entity-id;time;globecoordinate
, ", entity_tid smallint NOT NULL" // null;item
, ", entity_id integer NOT NULL" // null;123
, ", val_text varchar(255) NOT NULL"
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {
return new Db_idx_itm[] {
Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_ref__main ON wdata_ref (page_id, prop_id, val_tid, entity_tid);")
};
}
@Override public String[] Fld_ary() {return new String[] {Fld_ref_id, Fld_page_id, Fld_prop_id, Fld_val_tid, Fld_entity_tid, Fld_entity_id, Fld_val_text};}
private static final String Fld_ref_id = "ref_id", Fld_page_id = "page_id", Fld_prop_id = "prop_id", Fld_val_tid = "val_tid", Fld_entity_tid = "entity_tid", Fld_entity_id = "entity_id", Fld_val_text = "val_ext";
}
class Wdata_qual_tbl extends Wdata_tbl_base {
@Override public String Tbl_name() {return "wdata_qual";}
@Override public String Tbl_create_sql() {
return String_.Concat_lines_nl
( "CREATE TABLE IF NOT EXISTS wdata_qual"
, "( qual_id integer NOT NULL"
, ", page_id integer NOT NULL"
, ", val_text varchar(4096) NOT NULL"
, ");"
);
}
@Override public Db_idx_itm[] Idx_ary() {
return new Db_idx_itm[] {
Db_idx_itm.sql_("CREATE INDEX IF NOT EXISTS wdata_qual__main ON wdata_ref (qual_id, page_id);")
};
}
@Override public String[] Fld_ary() {return new String[] {Fld_qual_id, Fld_page_id, Fld_val_text};}
public void Insert(Db_stmt stmt, int qual_id, int page_id, byte[] val_text) {
stmt.Clear()
.Val_int(qual_id)
.Val_int(page_id)
.Val_bry_as_str(val_text)
.Exec_insert();
}
private static final String Fld_qual_id = "qual_id", Fld_page_id = "page_id", Fld_val_text = "val_text";
}
class Xob_wdata_db_visitor implements Wbase_claim_visitor {
private final Wdata_wiki_mgr wdata_mgr; private byte[] lang_key;
public Xob_wdata_db_visitor(Wdata_wiki_mgr wdata_mgr) {this.wdata_mgr = wdata_mgr;}
public void Init(byte[] lang_key) {this.lang_key = lang_key;}
public byte[] Rv() {return rv;} private byte[] rv;
public void Visit_str(Wbase_claim_string itm) {rv = itm.Val_str();}
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {rv = Bry_.Add_w_dlm(Byte_ascii.Pipe, itm.Lang(), itm.Text());}
public void Visit_quantity(Wbase_claim_quantity itm) {rv = itm.Amount();}
public void Visit_time(Wbase_claim_time itm) {rv = itm.Time();}
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {rv = Bry_.Add_w_dlm(Byte_ascii.Comma, itm.Lat(), itm.Lng());}
public void Visit_system(Wbase_claim_value itm) {rv = Bry_.Empty;}
public void Visit_entity(Wbase_claim_entity itm) {
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(itm.Page_ttl_db());
rv = entity_doc == null ? Bry_.Empty : entity_doc.Label_list__get(lang_key);
}
}

View File

@@ -0,0 +1,55 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xob_page_wkr, Gfo_invk {
private Json_parser parser;
public Xob_wdata_pid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
public abstract String Page_wkr__key();
public abstract void Pid_bgn();
public abstract void Pid_add(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl);
public abstract void Pid_end();
public void Page_wkr__bgn() {
this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
this.Pid_bgn();
}
public void Page_wkr__run(Xowd_page_itm page) {
if (page.Ns_id() != Wdata_wiki_mgr.Ns_property) return;
Json_doc jdoc = parser.Parse(page.Text());
if (jdoc == null) {
bldr.Usr_dlg().Warn_many(GRP_KEY, "json.invalid", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db()));
return;
}
Parse_jdoc(jdoc);
}
public void Page_wkr__run_cleanup() {}
public void Parse_jdoc(Json_doc jdoc) {
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
byte[] qid = wdoc_parser.Parse_qid(jdoc);
Ordered_hash list = wdoc_parser.Parse_langvals(qid, jdoc, Bool_.Y);
int len = list.Count();
for (int i = 0; i < len; ++i) {
Wdata_langtext_itm label = (Wdata_langtext_itm)list.Get_at(i);
this.Pid_add(label.Lang(), label.Text(), qid);
}
}
public void Page_wkr__end() {this.Pid_end();}
static final String GRP_KEY = "xowa.wdata.pid_wkr";
}

View File

@@ -0,0 +1,74 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
public class Xob_wdata_pid_base_tst {
gplx.xowa.bldrs.Xob_fxt fxt = new gplx.xowa.bldrs.Xob_fxt().Ctor_mem();
Io_url reg_(Xowe_wiki wdata, String wiki) {return Wdata_idx_wtr.dir_pid_(wdata, wiki).GenSubFil(Xotdb_dir_info_.Name_reg_fil);}
Io_url ttl_(Xowe_wiki wdata, String wiki, int fil_id) {
Io_url root = Wdata_idx_wtr.dir_pid_(wdata, wiki);
return Xotdb_fsys_mgr.Url_fil(root, fil_id, Xotdb_dir_info_.Bry_xdat);
}
@Test public void Basic() {
fxt.Wiki().Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, "Property");
fxt.doc_ary_
( fxt.doc_wo_date_(2, "Property:P2", json_("p2", "label", String_.Ary("en", "p2_en", "fr", "p2_fr")))
, fxt.doc_wo_date_(1, "Property:P1", json_("p1", "label", String_.Ary("en", "p1_en", "fr", "p1_fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "en", 0)
, "!!!!*|!!!!*|"
, "p1_en|p1"
, "p2_en|p2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "en")
, "0|p1_en|p2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "fr", 0)
, "!!!!*|!!!!*|"
, "p1_fr|p1"
, "p2_fr|p2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "fr")
, "0|p1_fr|p2_fr|2"
, ""
)
.Run(new Xob_wdata_pid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
public static String json_(String entity_id, String grp_key, String[] grp_vals) {
Bry_bfr bfr = Bry_bfr_.New();
bfr.Add_str_a7("{ 'entity':'").Add_str_u8(entity_id).Add_byte(Byte_ascii.Apos).Add_byte_nl();
bfr.Add_str_a7(", '").Add_str_u8(grp_key).Add_str_a7("':").Add_byte_nl();
int len = grp_vals.length;
for (int i = 0; i < len; i += 2) {
bfr.Add_byte_repeat(Byte_ascii.Space, 2);
bfr.Add_byte(i == 0 ? Byte_ascii.Curly_bgn : Byte_ascii.Comma).Add_byte(Byte_ascii.Space);
bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(grp_vals[i ]).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Colon);
bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(grp_vals[i + 1]).Add_byte(Byte_ascii.Apos).Add_byte_nl();
}
bfr.Add_str_a7(" }").Add_byte_nl();
bfr.Add_str_a7("}").Add_byte_nl();
return String_.Replace(bfr.To_str_and_clear(), "'", "\"");
}
}

View File

@@ -0,0 +1,36 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
public class Xob_wdata_pid_sql extends Xob_wdata_pid_base {
private Xowd_wbase_pid_tbl tbl;
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;}
@Override public void Pid_bgn() {
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
tbl = db_mgr.Db__wbase().Tbl__wbase_pid();
tbl.Create_tbl();
tbl.Insert_bgn();
}
@Override public void Pid_add(byte[] lang_key, byte[] ttl, byte[] pid) {
tbl.Insert_cmd_by_batch(lang_key, ttl, pid);
}
@Override public void Pid_end() {
tbl.Insert_end();
tbl.Create_idx();
}
}

View File

@@ -0,0 +1,49 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
public class Xob_wdata_pid_txt extends Xob_wdata_pid_base {
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_pid;}
@Override public void Pid_bgn() {
pid_bldr = new Wdata_idx_bldr_pid(this, bldr, wiki, dump_fil_len);
} Wdata_idx_bldr_pid pid_bldr;
@Override public void Pid_add(byte[] lang_key, byte[] prop_key, byte[] qid) {
pid_bldr.Add(lang_key, prop_key, qid);
}
@Override public void Pid_end() {
pid_bldr.Flush();
pid_bldr.Make();
}
}
class Wdata_idx_bldr_pid extends Wdata_idx_mgr_base {
public Wdata_idx_bldr_pid(Xob_itm_dump_base wkr, Xob_bldr bldr, Xowe_wiki wiki, int dump_fil_len) {this.Ctor(wkr, bldr, wiki, dump_fil_len);}
public void Add(byte[] lang, byte[] prop_key, byte[] pid) {
Wdata_idx_wtr wtr = Get_or_new(lang);
wtr.Write(prop_key, pid);
}
public Wdata_idx_wtr Get_or_new(byte[] lang_bry) {
String lang = String_.Lower(String_.new_u8(lang_bry)); // NOTE: for some reason, both "en" and "En" can be added; normalize case
Object rv = hash.Get_by(lang);
if (rv == null) {
Wdata_idx_wtr wtr = Wdata_idx_wtr.new_pid_(wiki, lang, dump_fil_len);
hash.Add(lang, wtr);
return wtr;
}
return (Wdata_idx_wtr)rv;
}
}

View File

@@ -0,0 +1,64 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*; import gplx.core.ios.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
import gplx.xowa.bldrs.wms.sites.*;
public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xob_page_wkr, Gfo_invk {
private Json_parser parser; private Xob_wbase_ns_parser ns_parser; private final Xob_wbase_ns_parser_rslt ns_parser_rslt = new Xob_wbase_ns_parser_rslt();
public Xob_wdata_qid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
public abstract String Page_wkr__key();
public abstract void Qid_bgn();
public abstract void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid);
public abstract void Qid_end();
public void Page_wkr__bgn() {
this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
this.parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
this.ns_parser = new Xob_wbase_ns_parser(bldr.App().Fsys_mgr().Cfg_site_meta_fil());
this.Qid_bgn();
}
public void Page_wkr__run(Xowd_page_itm page) {
if (page.Ns_id() != Xow_ns_.Tid__main) return; // qid pages are only in the Main Srch_rslt_cbk
Json_doc jdoc = parser.Parse(page.Text());
if (jdoc == null) {bldr.Usr_dlg().Warn_many("", "", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db())); return;}
this.Parse_jdoc(jdoc);
}
public void Page_wkr__run_cleanup() {}
public void Parse_jdoc(Json_doc jdoc) {
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
byte[] qid = wdoc_parser.Parse_qid(jdoc);
Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
Ordered_hash sitelinks = wdoc_parser.Parse_sitelinks(qid, jdoc);
int sitelinks_len = sitelinks.Count(); if (sitelinks_len == 0) return; // no subs; return;
for (int i = 0; i < sitelinks_len; i++) { // iterate sitelinks
Wdata_sitelink_itm sitelink = (Wdata_sitelink_itm)sitelinks.Get_at(i);
byte[] sitelink_site = sitelink.Site(), sitelink_ttl = sitelink.Name();
ns_parser.Find(ns_parser_rslt, sitelink_site, sitelink_ttl);
int sitelink_ns = ns_parser_rslt.Ns_id();
if (sitelink_ns != Xow_ns_.Tid__main) // ttl not in main; chop off ns portion; EX:Aide:French_title -> French_title
sitelink_ttl = Bry_.Mid(sitelink_ttl, ns_parser_rslt.Ttl_bgn(), sitelink_ttl.length);
sitelink_ttl = wiki.Lang().Case_mgr().Case_build_1st_upper(tmp_bfr, sitelink_ttl, 0, sitelink_ttl.length);
this.Qid_add(sitelink.Site(), sitelink_ns, Xoa_ttl.Replace_spaces(sitelink_ttl), qid); // NOTE: always convert spaces to underscores; EX: "A B" -> "A_B" DATE:2015-04-21
}
}
public void Page_wkr__end() {
this.Qid_end();
// wiki.Data__core_mgr().Db__wbase().Tbl__cfg().Insert_int("", "", 1);
}
}

View File

@@ -0,0 +1,175 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; import gplx.dbs.*;
import gplx.xowa.bldrs.wms.sites.*;
public class Xob_wdata_qid_base_tst {
private gplx.xowa.bldrs.Xob_fxt fxt; // NOTE: reset memory instance (don't just call clear)
@Before public void init() {
this.fxt = new gplx.xowa.bldrs.Xob_fxt().Ctor_mem();
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
}
@Test public void Basic() {
fxt.doc_ary_
( fxt.doc_wo_date_(2, "q2", Xob_wdata_pid_base_tst.json_("q2", "links", String_.Ary("enwiki", "q2_en", "frwiki", "q2_fr")))
, fxt.doc_wo_date_(1, "q1", Xob_wdata_pid_base_tst.json_("q1", "links", String_.Ary("enwiki", "q1_en", "frwiki", "q1_fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_en|q1"
, "Q2_en|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "000")
, "0|Q1_en|Q2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_fr|q1"
, "Q2_fr|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "000")
, "0|Q1_fr|Q2_fr|2"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
@Test public void Ns() {
// setup db
Site_core_db json_db = new Site_core_db(fxt.App().Fsys_mgr().Cfg_site_meta_fil());
Site_namespace_tbl ns_tbl = json_db.Tbl__namespace();
ns_tbl.Insert(Bry_.new_a7("en.w"), Xow_ns_.Tid__help, Xow_ns_case_.Bry__1st, Bry_.Empty, Bry_.new_a7("Help"), Bool_.N, Bool_.N, Bry_.Empty);
ns_tbl.Insert(Bry_.new_a7("fr.w"), Xow_ns_.Tid__help, Xow_ns_case_.Bry__1st, Bry_.Empty, Bry_.new_a7("Aide"), Bool_.N, Bool_.N, Bry_.Empty);
// run test
fxt.doc_ary_
( fxt.doc_wo_date_(1, "11", Xob_wdata_pid_base_tst.json_("q1", "links", String_.Ary("enwiki", "Help:Q1_en", "frwiki", "Aide:Q1_fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "012", 0)
, "!!!!*|"
, "Q1_en|q1"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "012")
, "0|Q1_en|Q1_en|1"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "012", 0)
, "!!!!*|"
, "Q1_fr|q1"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "012")
, "0|Q1_fr|Q1_fr|1"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
@Test public void Links_w_name() { // PURPOSE: wikidata changed links node from "enwiki:A" to "enwiki:{name:A,badges:[]}"; DATE:2013-09-14
String q1_str = String_.Concat_lines_nl
( "{ \"entity\":\"q1\""
, ", \"links\":"
, " { \"enwiki\":\"q1_en\""
, " , \"frwiki\":\"q1_fr\""
, " }"
, "}"
);
String q2_str = String_.Concat_lines_nl
( "{ \"entity\":[\"item\",2]"
, ", \"links\":"
, " { \"enwiki\":{\"name\":\"q2_en\",\"badges\":[]}"
, " , \"frwiki\":{\"name\":\"q2_fr\",\"badges\":[]}"
, " }"
, "}"
);
fxt.doc_ary_
( fxt.doc_wo_date_(1, "q1", q1_str)
, fxt.doc_wo_date_(2, "q2", q2_str)
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_en|q1"
, "Q2_en|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "000")
, "0|Q1_en|Q2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_fr|q1"
, "Q2_fr|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "000")
, "0|Q1_fr|Q2_fr|2"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
@Test public void Spaces() { // PURPOSE: assert that ttls with spaces are converted to unders DATE:2015-04-21
fxt.doc_ary_
( fxt.doc_wo_date_(2, "q2", Xob_wdata_pid_base_tst.json_("q2", "links", String_.Ary("enwiki", "q2 en", "frwiki", "q2 fr"))) // note "q2 en" not "q2_en"
, fxt.doc_wo_date_(1, "q1", Xob_wdata_pid_base_tst.json_("q1", "links", String_.Ary("enwiki", "q1 en", "frwiki", "q1 fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_en|q1"
, "Q2_en|q2" // NOTE: q2_en
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "000")
, "0|Q1_en|Q2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_fr|q1"
, "Q2_fr|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "000")
, "0|Q1_fr|Q2_fr|2"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
public static Io_url reg_(Xowe_wiki wdata, String wiki, String ns_id) {
return Wdata_idx_wtr.dir_qid_(wdata, wiki, ns_id).GenSubFil(Xotdb_dir_info_.Name_reg_fil);
}
public static Io_url ttl_(Xowe_wiki wdata, String wiki, String ns_id, int fil_id) {
Io_url root = Wdata_idx_wtr.dir_qid_(wdata, wiki, ns_id);
return Xotdb_fsys_mgr.Url_fil(root, fil_id, Xotdb_dir_info_.Bry_xdat);
}
}

View File

@@ -0,0 +1,42 @@
/*
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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
public class Xob_wdata_qid_sql extends Xob_wdata_qid_base {
private Xowd_wbase_qid_tbl tbl;
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_qid;}
@Override public void Qid_bgn() {
Xow_db_mgr db_mgr = wiki.Db_mgr_as_sql().Core_data_mgr();
boolean db_is_all_or_few = db_mgr.Props().Layout_text().Tid_is_all_or_few();
Xow_db_file wbase_db = db_is_all_or_few
? db_mgr.Db__core()
: db_mgr.Dbs__make_by_tid(Xow_db_file_.Tid__wbase);
if (db_is_all_or_few)
db_mgr.Db__wbase_(wbase_db);
tbl = wbase_db.Tbl__wbase_qid();
tbl.Create_tbl();
tbl.Insert_bgn();
}
@Override public void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid) {
tbl.Insert_cmd_by_batch(wiki_key, ns_id, ttl, qid);
}
@Override public void Qid_end() {
tbl.Insert_end();
tbl.Create_idx();
}
}

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.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.bldrs.*;
public class Xob_wdata_qid_txt extends Xob_wdata_qid_base {
private Wdata_idx_bldr_qid qid_bldr;
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_qid;}
@Override public void Qid_bgn() {qid_bldr = new Wdata_idx_bldr_qid().Ctor(this, bldr, wiki, dump_fil_len);}
@Override public void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid) {
qid_bldr.Add(String_.new_u8(wiki_key), Int_.To_str_pad_bgn_zero(ns_id, 3), ttl, qid);
}
@Override public void Qid_end() {
qid_bldr.Flush();
qid_bldr.Make();
}
}
class Wdata_idx_bldr_qid extends Wdata_idx_mgr_base {
public Wdata_idx_bldr_qid Ctor(Xob_wdata_qid_base wkr, Xob_bldr bldr, Xowe_wiki wiki, int dump_fil_len) {super.Ctor(wkr, bldr, wiki, dump_fil_len); return this;}
public void Add(String wiki_key, String ns_num_str, byte[] ttl, byte[] qid) {
Wdata_idx_wtr wtr = Get_or_new(wiki_key, ns_num_str);
wtr.Write(ttl, qid);
}
private Wdata_idx_wtr Get_or_new(String wiki_key, String ns_num_str) {
String wtr_key = wiki_key + "|" + ns_num_str;
Object rv = hash.Get_by(wtr_key);
if (rv == null) {
Wdata_idx_wtr wtr = Wdata_idx_wtr.new_qid_(wiki, wiki_key, ns_num_str, dump_fil_len);
hash.Add(wtr_key, wtr);
return wtr;
}
return (Wdata_idx_wtr)rv;
}
}

View File

@@ -0,0 +1,117 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wbase_claim_factory {
public Wbase_claim_base Parse(byte[] qid, int pid, byte snak_tid, Json_nde nde, byte value_tid, Json_itm value_itm) {
switch (value_tid) {
case Wbase_claim_type_.Tid__string: return new Wbase_claim_string(pid, snak_tid, value_itm.Data_bry());
case Wbase_claim_type_.Tid__entity: return Parse_datavalue_entity (qid, pid, snak_tid, Json_nde.cast(value_itm));
case Wbase_claim_type_.Tid__time: return Parse_datavalue_time (qid, pid, snak_tid, Json_nde.cast(value_itm));
case Wbase_claim_type_.Tid__quantity: return Parse_datavalue_quantity (qid, pid, snak_tid, Json_nde.cast(value_itm));
case Wbase_claim_type_.Tid__globecoordinate: return Parse_datavalue_globecoordinate (qid, pid, snak_tid, Json_nde.cast(value_itm));
case Wbase_claim_type_.Tid__monolingualtext: return Parse_datavalue_monolingualtext (qid, pid, snak_tid, Json_nde.cast(value_itm));
default: throw Err_.new_unhandled_default(value_tid);
}
}
private Wbase_claim_entity Parse_datavalue_entity(byte[] qid, int pid, byte snak_tid, Json_nde nde) {
int len = nde.Len();
byte entity_tid = Byte_.Max_value_127;
byte[] entity_id_bry = null;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wbase_claim_entity_.To_tid_or_invalid(qid, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wbase_claim_entity_.Tid__entity_type: entity_tid = Wbase_claim_entity_type_.To_tid_or_fail(sub.Val().Data_bry()); break;
case Wbase_claim_entity_.Tid__numeric_id: entity_id_bry = sub.Val().Data_bry(); break;
}
}
if (entity_id_bry == null) throw Err_.new_wo_type("pid is invalid entity", "pid", pid);
return new Wbase_claim_entity(pid, snak_tid, entity_tid, entity_id_bry);
}
private Wbase_claim_monolingualtext Parse_datavalue_monolingualtext(byte[] qid, int pid, byte snak_tid, Json_nde nde) {
int len = nde.Len();
byte[] lang = null, text = null;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wbase_claim_monolingualtext_.To_tid_or_invalid(qid, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
byte[] sub_val_bry = sub.Val().Data_bry();
switch (tid) {
case Wbase_claim_monolingualtext_.Tid__text: text = sub_val_bry; break;
case Wbase_claim_monolingualtext_.Tid__language: lang = sub_val_bry; break;
}
}
if (lang == null || text == null) throw Err_.new_wo_type("pid is invalid monolingualtext", "pid", pid);
return new Wbase_claim_monolingualtext(pid, snak_tid, lang, text);
}
private Wbase_claim_globecoordinate Parse_datavalue_globecoordinate(byte[] qid, int pid, byte snak_tid, Json_nde nde) {
int len = nde.Len();
byte[] lat = null, lng = null, alt = null, prc = null, glb = null;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wbase_claim_globecoordinate_.To_tid_or_invalid(qid, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
byte[] sub_val_bry = sub.Val().Data_bry();
switch (tid) {
case Wbase_claim_globecoordinate_.Tid__latitude: lat = sub_val_bry; break;
case Wbase_claim_globecoordinate_.Tid__longitude: lng = sub_val_bry; break;
case Wbase_claim_globecoordinate_.Tid__altitude: alt = sub_val_bry; break;
case Wbase_claim_globecoordinate_.Tid__precision: prc = sub_val_bry; break;
case Wbase_claim_globecoordinate_.Tid__globe: glb = sub_val_bry; break;
}
}
if (lat == null || lng == null) throw Err_.new_wo_type("pid is invalid globecoordinate", "pid", pid);
return new Wbase_claim_globecoordinate(pid, snak_tid, lat, lng, alt, prc, glb);
}
private Wbase_claim_quantity Parse_datavalue_quantity(byte[] qid, int pid, byte snak_tid, Json_nde nde) {
int len = nde.Len();
byte[] amount = null, unit = null, ubound = null, lbound = null;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wbase_claim_quantity_.To_tid_or_invalid(qid, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
byte[] sub_val_bry = sub.Val().Data_bry();
switch (tid) {
case Wbase_claim_quantity_.Tid__amount: amount = sub_val_bry; break;
case Wbase_claim_quantity_.Tid__unit: unit = sub_val_bry; break;
case Wbase_claim_quantity_.Tid__upperbound: ubound = sub_val_bry; break;
case Wbase_claim_quantity_.Tid__lowerbound: lbound = sub_val_bry; break;
}
}
if (amount == null) throw Err_.new_wo_type("pid is invalid quantity", "pid", pid);
return new Wbase_claim_quantity(pid, snak_tid, amount, unit, ubound, lbound);
}
private Wbase_claim_time Parse_datavalue_time(byte[] qid, int pid, byte snak_tid, Json_nde nde) {
int len = nde.Len();
byte[] time = null, timezone = null, before = null, after = null, precision = null, calendarmodel = null;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wbase_claim_time_.To_tid_or_invalid(qid, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
byte[] sub_val_bry = sub.Val().Data_bry();
switch (tid) {
case Wbase_claim_time_.Tid__time: time = sub_val_bry; break;
case Wbase_claim_time_.Tid__timezone: timezone = sub_val_bry; break;
case Wbase_claim_time_.Tid__before: before = sub_val_bry; break;
case Wbase_claim_time_.Tid__after: after = sub_val_bry; break;
case Wbase_claim_time_.Tid__precision: precision = sub_val_bry; break;
case Wbase_claim_time_.Tid__calendarmodel: calendarmodel = sub_val_bry; break;
}
}
if (time == null) throw Err_.new_wo_type("pid is invalid time", "pid", pid);
return new Wbase_claim_time(pid, snak_tid, time, timezone, before, after, precision, calendarmodel);
}
}

View File

@@ -0,0 +1,151 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.primitives.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
class Wdata_claims_parser_v2 {
private final Wbase_claim_factory factory = new Wbase_claim_factory();
public void Make_claim_itms(byte[] qid, List_adp claim_itms_list, byte[] src, Json_kv claim_grp) {
Json_ary claim_itms_ary = Json_ary.cast_or_null(claim_grp.Val());
int claim_itms_len = claim_itms_ary.Len();
int pid = Parse_pid(claim_grp.Key().Data_bry());
for (int i = 0; i < claim_itms_len; ++i) {
Json_nde claim_itm_nde = Json_nde.cast(claim_itms_ary.Get_at(i));
Wbase_claim_base itm = Parse_claim_itm(qid, claim_itm_nde, pid);
if (itm != null) // HACK: itm can be null if value is "somevalue"; DATE:2014-09-20
claim_itms_list.Add(itm);
}
}
private Wbase_claim_base Parse_claim_itm(byte[] qid, Json_nde nde, int pid) {
int len = nde.Len();
Hash_adp_bry dict = Wdata_dict_claim.Dict;
byte rank_tid = Wbase_claim_rank_.Tid__unknown;
Wbase_claim_base claim_itm = null; Wbase_claim_grp_list qualifiers = null; int[] qualifiers_order = null; Wbase_references_grp[] snaks_grp = null;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wdata_dict_claim.Tid_mainsnak: claim_itm = Parse_mainsnak(qid, Json_nde.cast(sub.Val()), pid); break;
case Wdata_dict_claim.Tid_rank: rank_tid = Wbase_claim_rank_.To_tid_or_unknown(sub.Val().Data_bry()); break;
case Wdata_dict_claim.Tid_references: snaks_grp = Parse_references(qid, Json_ary.cast_or_null(sub.Val())); break;
case Wdata_dict_claim.Tid_qualifiers: qualifiers = Parse_qualifiers(qid, Json_nde.cast(sub.Val())); break;
case Wdata_dict_claim.Tid_qualifiers_order: qualifiers_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
case Wdata_dict_claim.Tid_type: break; // ignore: "statement"
case Wdata_dict_claim.Tid_id: break; // ignore: "Q2$F909BD1C-D34D-423F-9ED2-3493663321AF"
}
}
if (claim_itm != null) {
claim_itm.Rank_tid_(rank_tid);
if (qualifiers != null) claim_itm.Qualifiers_(qualifiers);
if (qualifiers_order != null) claim_itm.Qualifiers_order_(qualifiers_order);
if (snaks_grp != null) claim_itm.References_(snaks_grp);
}
return claim_itm;
}
public Wbase_references_grp[] Parse_references(byte[] qid, Json_ary owner) {
int len = owner.Len();
Wbase_references_grp[] rv = new Wbase_references_grp[len];
for (int i = 0; i < len; ++i) {
Json_nde grp_nde = Json_nde.cast(owner.Get_at(i));
rv[i] = Parse_references_grp(qid, grp_nde);
}
return rv;
}
private Wbase_references_grp Parse_references_grp(byte[] qid, Json_nde owner) {
int len = owner.Len();
Hash_adp_bry dict = Wdata_dict_reference.Dict;
Wbase_claim_grp_list snaks = null; int[] snaks_order = null;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(owner.Get_at(i));
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wdata_dict_reference.Tid_hash: break; // ignore: "b923b0d68beb300866b87ead39f61e63ec30d8af"
case Wdata_dict_reference.Tid_snaks: snaks = Parse_qualifiers(qid, Json_nde.cast(sub.Val())); break;
case Wdata_dict_reference.Tid_snaks_order: snaks_order = Parse_pid_order(Json_ary.cast_or_null(sub.Val())); break;
}
}
return new Wbase_references_grp(snaks, snaks_order);
}
public Wbase_claim_grp_list Parse_qualifiers(byte[] qid, Json_nde qualifiers_nde) {
Wbase_claim_grp_list rv = new Wbase_claim_grp_list();
if (qualifiers_nde == null) return rv; // NOTE:sometimes references can have 0 snaks; return back an empty Wbase_claim_grp_list, not null; PAGE:Птичкин,_Евгений_Николаевич; DATE:2015-02-16
int len = qualifiers_nde.Len();
for (int i = 0; i < len; ++i) {
Json_kv qualifier_kv = Json_kv.cast(qualifiers_nde.Get_at(i));
int pid = Parse_pid(qualifier_kv.Key().Data_bry());
Wbase_claim_grp claims_grp = Parse_props_grp(qid, pid, Json_ary.cast_or_null(qualifier_kv.Val()));
rv.Add(claims_grp);
}
return rv;
}
public int[] Parse_pid_order(Json_ary ary) {
int len = ary.Len();
int[] rv = new int[len];
for (int i = 0; i < len; ++i) {
Json_itm pid_itm = ary.Get_at(i);
rv[i] = Parse_pid(pid_itm.Data_bry());
}
return rv;
}
private Wbase_claim_grp Parse_props_grp(byte[] qid, int pid, Json_ary props_ary) {
List_adp list = List_adp_.New();
int len = props_ary.Len();
for (int i = 0; i < len; ++i) {
Json_nde qualifier_nde = Json_nde.cast(props_ary.Get_at(i));
Wbase_claim_base qualifier_itm = Parse_mainsnak(qid, qualifier_nde, pid);
list.Add(qualifier_itm);
}
return new Wbase_claim_grp(Int_obj_ref.New(pid), (Wbase_claim_base[])list.To_ary_and_clear(Wbase_claim_base.class));
}
public Wbase_claim_base Parse_mainsnak(byte[] qid, Json_nde nde, int pid) {
int len = nde.Len();
Hash_adp_bry dict = Wdata_dict_mainsnak.Dict;
byte snak_tid = Byte_.Max_value_127;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wdata_dict_mainsnak.Tid_snaktype: snak_tid = Wbase_claim_value_type_.To_tid_or_fail(sub.Val().Data_bry()); break;
case Wdata_dict_mainsnak.Tid_datavalue: return Parse_datavalue(qid, pid, snak_tid, Json_nde.cast(sub.Val()));
case Wdata_dict_mainsnak.Tid_datatype: break; // ignore: has values like "wikibase-property"; EX: www.wikidata.org/wiki/Property:P397; DATE:2015-06-12
case Wdata_dict_mainsnak.Tid_property: break; // ignore: pid already available above
case Wdata_dict_mainsnak.Tid_hash: break; // ignore: "84487fc3f93b4f74ab1cc5a47d78f596f0b49390"
}
}
return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown, snak_tid); // NOTE: mainsnak can be null, especially for qualifiers; PAGE:Q2!P576; DATE:2014-09-20
}
public Wbase_claim_base Parse_datavalue(byte[] qid, int pid, byte snak_tid, Json_nde nde) {
int len = nde.Len();
Hash_adp_bry dict = Wdata_dict_datavalue.Dict;
Json_itm value_itm = null; byte value_tid = Wbase_claim_type_.Tid__unknown;
for (int i = 0; i < len; ++i) {
Json_kv sub = Json_kv.cast(nde.Get_at(i));
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wdata_dict_datavalue.Tid_type: value_tid = Wbase_claim_type_.To_tid_or_unknown(sub.Val().Data_bry()); break;
case Wdata_dict_datavalue.Tid_value: value_itm = sub.Val(); break;
case Wdata_dict_datavalue.Tid_error: break; // ignore: "Can only construct GlobeCoordinateValue with a String globe parameter"
}
}
return factory.Parse(qid, pid, snak_tid, nde, value_tid, value_itm);
}
private static int Parse_pid(byte[] pid_bry) {
int rv = Bry_.To_int_or(pid_bry, 1, pid_bry.length, -1); if (rv == -1) throw Err_.new_wo_type("invalid pid", "pid", String_.new_u8(pid_bry));
return rv;
}
}

View File

@@ -0,0 +1,30 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public interface Wdata_doc_parser {
byte[] Parse_qid(Json_doc doc);
Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc);
Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description);
Ordered_hash Parse_aliases(byte[] qid, Json_doc doc);
Ordered_hash Parse_claims(byte[] qid, Json_doc doc);
Wbase_claim_base Parse_claims_data(byte[] qid, int pid, byte snak_tid, Json_nde nde);
Wbase_claim_grp_list Parse_qualifiers(byte[] qid, Json_nde nde);
int[] Parse_pid_order(byte[] qid, Json_ary ary);
Wbase_references_grp[] Parse_references(byte[] qid, Json_ary owner);
}

View File

@@ -0,0 +1,102 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
abstract class Wdata_doc_parser_fxt_base {
protected Wdata_doc_parser wdoc_parser;
private final Json_parser json_parser = new Json_parser();
private final Bry_bfr tmp_time_bfr = Bry_bfr_.New();
public void Init() {
if (wdoc_parser == null) wdoc_parser = Make_parser();
}
public abstract Wdata_doc_parser Make_parser();
public Wdata_sitelink_itm Make_sitelink(String site, String name, String... badges) {return new Wdata_sitelink_itm(Bry_.new_u8(site), Bry_.new_u8(name), Bry_.Ary(badges));}
public Wdata_langtext_itm Make_langval(String lang, String text) {return new Wdata_langtext_itm(Bry_.new_u8(lang), Bry_.new_u8(text));}
public Wdata_alias_itm Make_alias(String lang, String... vals) {return new Wdata_alias_itm(Bry_.new_u8(lang), Bry_.Ary(vals));}
public Wbase_claim_base Make_claim_string (int pid, String val) {return new Wbase_claim_string(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_u8(val));}
public Wbase_claim_base Make_claim_entity_qid (int pid, int eid) {return new Wbase_claim_entity(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_entity_type_.Tid__item, Int_.To_bry(eid));}
public Wbase_claim_base Make_claim_entity_pid (int pid, int eid) {return new Wbase_claim_entity(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_entity_type_.Tid__property, Int_.To_bry(eid));}
public Wbase_claim_base Make_claim_monolingualtext (int pid, String lang, String text) {return new Wbase_claim_monolingualtext(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_u8(lang), Bry_.new_u8(text));}
public Wbase_claim_base Make_claim_globecoordinate (int pid, String lat, String lng, String prc) {return new Wbase_claim_globecoordinate(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_u8(lat), Bry_.new_u8(lng), Object_.Bry__null, Bry_.new_u8(prc), Bry_.new_a7("http://www.wikidata.org/entity/Q2"));}
public Wbase_claim_base Make_claim_quantity (int pid, int val, int unit, int ubound, int lbound) {return new Wbase_claim_quantity(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_u8(Int_.To_str(val)), Bry_.new_u8(Int_.To_str(unit)), Bry_.new_u8(Int_.To_str(ubound)), Bry_.new_u8(Int_.To_str(lbound)));}
public Wbase_claim_base Make_claim_time (int pid, String val) {return new Wbase_claim_time(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_time_.To_bry(tmp_time_bfr, val), Wbase_claim_time_.Dflt__timezone.Val_bry(), Wbase_claim_time_.Dflt__before.Val_bry(), Wbase_claim_time_.Dflt__after.Val_bry(), Wbase_claim_time_.Dflt__precision.Val_bry(), Wbase_claim_time_.Dflt__calendarmodel.Val_bry());}
public Wbase_claim_base Make_claim_novalue (int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown, Wbase_claim_value_type_.Tid__novalue);}
public void Test_entity(String raw, String expd) {Tfds.Eq(expd, String_.new_u8(wdoc_parser.Parse_qid(json_parser.Parse_by_apos(raw))));}
public void Test_sitelinks(String raw, Wdata_sitelink_itm... expd) {
Ordered_hash actl_hash = wdoc_parser.Parse_sitelinks(Q1_bry, json_parser.Parse_by_apos(raw));
Tfds.Eq_ary_str((Wdata_sitelink_itm[])actl_hash.To_ary(Wdata_sitelink_itm.class), expd);
}
public void Test_labels(String raw, Wdata_langtext_itm... expd) {Test_langvals(raw, Bool_.Y, expd);}
public void Test_descriptions(String raw, Wdata_langtext_itm... expd) {Test_langvals(raw, Bool_.N, expd);}
private void Test_langvals(String raw, boolean labels_or_descriptions, Wdata_langtext_itm... expd) {
Ordered_hash actl_hash = wdoc_parser.Parse_langvals(Q1_bry, json_parser.Parse_by_apos(raw), labels_or_descriptions);
Tfds.Eq_ary_str((Wdata_langtext_itm[])actl_hash.To_ary(Wdata_langtext_itm.class), expd);
}
public void Test_aliases(String raw, Wdata_alias_itm... expd) {
Ordered_hash actl_hash = wdoc_parser.Parse_aliases(Q1_bry, json_parser.Parse_by_apos(raw));
Tfds.Eq_ary_str((Wdata_alias_itm[])actl_hash.To_ary(Wdata_alias_itm.class), expd);
}
public void Test_claims(String raw, Wbase_claim_base... expd) {
Ordered_hash actl_hash = wdoc_parser.Parse_claims(Q1_bry, json_parser.Parse_by_apos(raw));
List_adp actl_list = Wbase_claim_grp.Xto_list(actl_hash);
Tfds.Eq_ary_str((Wbase_claim_base[])actl_list.To_ary(Wbase_claim_base.class), expd);
}
public void Test_claims_data(String raw, Wbase_claim_base expd) {
Json_doc jdoc = json_parser.Parse_by_apos(raw);
Wbase_claim_base actl = wdoc_parser.Parse_claims_data(Q1_bry, 1, Wbase_claim_value_type_.Tid__value, jdoc.Root_nde());
Tfds.Eq(expd.toString(), actl.toString());
}
public void Test_qualifiers(String raw, Wbase_claim_base... expd_itms) {
Json_doc jdoc = json_parser.Parse_by_apos(raw);
Json_nde qualifiers_nde = Json_nde.cast(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
Wbase_claim_grp_list actl = wdoc_parser.Parse_qualifiers(Q1_bry, qualifiers_nde);
Tfds.Eq_ary_str(expd_itms, To_ary(actl));
}
public void Test_references(String raw, int[] expd_order, Wbase_claim_base... expd_itms) {
Json_doc jdoc = json_parser.Parse_by_apos(raw);
Json_ary owner = Json_ary.cast_or_null(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
Wbase_references_grp[] actl = wdoc_parser.Parse_references(Q1_bry, owner);
Wbase_references_grp actl_grp = actl[0];
Tfds.Eq_ary(expd_order, actl_grp.References_order());
Tfds.Eq_ary_str(expd_itms, To_ary(actl_grp.References()));
}
public void Test_pid_order(String raw, int... expd) {
Json_doc jdoc = json_parser.Parse_by_apos(raw);
Json_ary nde = Json_ary.cast_or_null(Json_kv.cast(jdoc.Root_nde().Get_at(0)).Val());
int[] actl = wdoc_parser.Parse_pid_order(Q1_bry, nde);
Tfds.Eq_ary(expd, actl);
}
Wbase_claim_base[] To_ary(Wbase_claim_grp_list list) {
List_adp rv = List_adp_.New();
int list_len = list.Len();
for (int i = 0; i < list_len; ++i) {
Wbase_claim_grp grp = list.Get_at(i);
int grp_len = grp.Len();
for (int j = 0; j < grp_len; ++j) {
Wbase_claim_base itm = grp.Get_at(j);
rv.Add(itm);
}
}
return (Wbase_claim_base[])rv.To_ary_and_clear(Wbase_claim_base.class);
}
private static final byte[] Q1_bry = Bry_.new_a7("Q1");
}
class Wdata_doc_parser_v2_fxt extends Wdata_doc_parser_fxt_base {
@Override public Wdata_doc_parser Make_parser() {return new Wdata_doc_parser_v2();}
}

View File

@@ -0,0 +1,265 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.primitives.*; import gplx.langs.jsons.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wdata_doc_parser_v1 implements Wdata_doc_parser {
public Wdata_doc_parser_v1(Gfo_usr_dlg usr_dlg) {this.usr_dlg = usr_dlg;} private Gfo_usr_dlg usr_dlg;
public Wdata_doc_parser_v1() {}
public byte[] Parse_qid(Json_doc doc) {
try {
Json_itm kv_val = doc.Find_nde(Bry_entity);
switch (kv_val.Tid()) {
case Json_itm_.Tid__str: // "entity":"q1"
return kv_val.Data_bry();
case Json_itm_.Tid__ary: // "entity":["item",1]
Json_ary kv_val_as_ary = (Json_ary)kv_val;
Json_itm entity_id = kv_val_as_ary.Get_at(1);
return Bry_.Add(Byte_ascii.Ltr_q, entity_id.Data_bry());
default:
throw Err_.new_unhandled(kv_val.Tid());
}
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse qid", "src", String_.new_u8(doc.Src()));}
}
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
try {
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_links)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
Ordered_hash rv = Ordered_hash_.New_bry();
int list_len = list_nde.Len();
for (int i = 0; i < list_len; ++i) {
Json_kv wiki_kv = Json_kv.cast(list_nde.Get_at(i));
byte[] site_bry = wiki_kv.Key().Data_bry();
byte[] title_bry = null; byte[][] badges_bry_ary = null;
if (wiki_kv.Val().Tid() == Json_itm_.Tid__nde) { // v1.2: "enwiki":{name:"Earth", badges:[]}
Json_nde val_nde = Json_nde.cast(wiki_kv.Val());
Json_kv name_kv = Json_kv.cast(val_nde.Get_at(0));
title_bry = name_kv.Val().Data_bry();
Json_kv badges_kv = Json_kv.cast(val_nde.Get_at(1));
if (badges_kv != null) {// TEST:some tests do not define a badges nde; ignore if null; DATE:2014-09-19
Json_ary badges_ary = Json_ary.cast_or_null(badges_kv.Val());
badges_bry_ary = badges_ary.Xto_bry_ary();
}
}
else { // v1.1: "enwiki":"Earth"
title_bry = wiki_kv.Val().Data_bry();
}
Wdata_sitelink_itm itm = new Wdata_sitelink_itm(site_bry, title_bry, badges_bry_ary);
rv.Add(site_bry, itm);
}
return rv;
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse sitelinks", "qid", String_.new_u8(qid));}
}
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
try {
byte[] langval_key = label_or_description ? Bry_label : Bry_description;
Json_nde list_nde = Json_nde.cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
Ordered_hash rv = Ordered_hash_.New_bry();
int list_len = list_nde.Len();
for (int i = 0; i < list_len; ++i) {
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
byte[] lang_bry = data_kv.Key().Data_bry();
Wdata_langtext_itm itm = new Wdata_langtext_itm(lang_bry, data_kv.Val().Data_bry());
rv.Add(lang_bry, itm);
}
return rv;
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse langvals", "qid", String_.new_u8(qid), "langval_tid", label_or_description);}
}
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
try {
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
Ordered_hash rv = Ordered_hash_.New_bry();
int list_len = list_nde.Len();
for (int i = 0; i < list_len; ++i) {
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
byte[] lang_bry = data_kv.Key().Data_bry();
byte[][] vals_bry_ary = null;
Json_itm data_val = data_kv.Val();
switch (data_val.Tid()) {
case Json_itm_.Tid__ary: // EX: 'en':['en_val_1','en_val_2']
Json_ary vals_ary = Json_ary.cast_or_null(data_val);
vals_bry_ary = vals_ary.Xto_bry_ary();
break;
case Json_itm_.Tid__nde: // EX: 'en':{'0:en_val_1','1:en_val_2'}; PAGE:wd.q:621080 DATE:2014-09-21
Json_nde vals_nde = Json_nde.cast(data_val);
int vals_len = vals_nde.Len();
vals_bry_ary = new byte[vals_len][];
for (int j = 0; j < vals_len; ++j) {
Json_kv vals_sub_kv = Json_kv.cast(vals_nde.Get_at(j));
vals_bry_ary[j] = vals_sub_kv.Val().Data_bry();
}
break;
default: throw Err_.new_unhandled(data_val.Tid());
}
Wdata_alias_itm itm = new Wdata_alias_itm(lang_bry, vals_bry_ary);
rv.Add(lang_bry, itm);
}
return rv;
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse aliases", "qid", String_.new_u8(qid));}
}
public Ordered_hash Parse_claims(byte[] qid, Json_doc doc) {
try {
Json_ary list_nde = Json_ary.cast_or_null(doc.Get_grp(Bry_claims)); if (list_nde == null) return Empty_ordered_hash_generic;
List_adp temp_list = List_adp_.New();
byte[] src = doc.Src();
int len = list_nde.Len();
for (int i = 0; i < len; i++) {
Json_nde claim_nde = Json_nde.cast(list_nde.Get_at(i));
Wbase_claim_base claim_itm = Make_claim_itm(src, claim_nde);
temp_list.Add(claim_itm);
}
return Claims_list_to_hash(temp_list);
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse claims", "qid", String_.new_u8(doc.Src()));}
}
public Wbase_claim_base Parse_claims_data(byte[] qid, int pid, byte snak_tid, Json_nde nde) {throw Err_.new_unimplemented();}
public static Ordered_hash Claims_list_to_hash(List_adp full_list) {
full_list.Sort();
Ordered_hash rv = Ordered_hash_.New(); List_adp temp_itms = List_adp_.New();
int prv_pid = -1;
int len = full_list.Count();
for (int i = 0; i < len; ++i) {
Wbase_claim_base claim_itm = (Wbase_claim_base)full_list.Get_at(i);
int cur_pid = claim_itm.Pid();
if (prv_pid != cur_pid && prv_pid != -1)
Claims_list_to_hash__add(rv, prv_pid, temp_itms);
temp_itms.Add(claim_itm);
prv_pid = cur_pid;
}
Claims_list_to_hash__add(rv, prv_pid, temp_itms);
return rv;
}
private static void Claims_list_to_hash__add(Ordered_hash rv, int pid, List_adp temp_itms) {
if (temp_itms.Count() == 0) return; // NOTE: will be empty when claims are empty; EX: "claims": []; PAGE:wd.p:585; DATE:2014-10-03
Int_obj_ref claim_grp_key = Int_obj_ref.New(pid);
Wbase_claim_grp claim_grp = new Wbase_claim_grp(claim_grp_key, (Wbase_claim_base[])temp_itms.To_ary_and_clear(Wbase_claim_base.class));
rv.Add(claim_grp_key, claim_grp);
}
private Wbase_claim_base Make_claim_itm(byte[] src, Json_nde prop_nde) {
int len = prop_nde.Len(); // should have 5 (m, q, g, rank, refs), but don't enforce (can rely on keys)
Wbase_claim_base rv = null;
for (int i = 0; i < len; i++) {
Json_kv kv = Json_kv.cast(prop_nde.Get_at(i));
Json_itm kv_key = kv.Key();
Byte_obj_val bv = (Byte_obj_val)Prop_key_hash.Get_by_mid(src, kv_key.Src_bgn(), kv_key.Src_end());
if (bv == null) {Warn("invalid prop node: ~{0}", String_.new_u8(src, kv_key.Src_bgn(), kv_key.Src_end())); return null;}
switch (bv.Val()) {
case Prop_tid_m:
rv = New_prop_by_m(src, Json_ary.cast_or_null(kv.Val()));
if (rv == null) return null;
break;
case Prop_tid_g:
rv.Wguid_(kv.Data_bry());
break;
case Prop_tid_rank:
rv.Rank_tid_((byte)Int_.cast(((Json_itm_int)kv.Val()).Data_as_int()));
break;
case Prop_tid_q:
break;
case Prop_tid_refs:
break;
default: throw Err_.new_unhandled(bv.Val());
}
}
return rv;
}
private Wbase_claim_base New_prop_by_m(byte[] src, Json_ary ary) {
byte snak_tid = Wbase_claim_value_type_.To_tid_or_fail(ary.Get_at(0).Data_bry());
int pid = Json_itm_int.cast(ary.Get_at(1)).Data_as_int();
switch (snak_tid) {
case Wbase_claim_value_type_.Tid__novalue : return Wbase_claim_value.New_novalue(pid);
case Wbase_claim_value_type_.Tid__somevalue : return Wbase_claim_value.New_somevalue(pid);
}
Json_itm val_tid_itm = ary.Get_at(2);
byte val_tid = Wbase_claim_type_.To_tid_or_unknown(src, val_tid_itm.Src_bgn(), val_tid_itm.Src_end());
return Make_itm(pid, snak_tid, val_tid, ary);
}
private Wbase_claim_base Make_itm(int pid, byte snak_tid, byte val_tid, Json_ary ary) {
switch (val_tid) {
case Wbase_claim_type_.Tid__string:
return new Wbase_claim_string(pid, snak_tid, ary.Get_at(3).Data_bry());
case Wbase_claim_type_.Tid__entity: {
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
Json_kv entity_kv = Json_kv.cast(sub_nde.Get_at(1));
return new Wbase_claim_entity(pid, snak_tid, Wbase_claim_entity_type_.Tid__item, entity_kv.Val().Data_bry());
}
case Wbase_claim_type_.Tid__time: {
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
return new Wbase_claim_time(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4), Get_val(sub_nde, 5));
}
case Wbase_claim_type_.Tid__globecoordinate: case Wbase_claim_type_.Tid__bad: {
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
return new Wbase_claim_globecoordinate(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3), Get_val(sub_nde, 4));
}
case Wbase_claim_type_.Tid__quantity: {
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
return new Wbase_claim_quantity(pid, snak_tid, Get_val(sub_nde, 0), Get_val(sub_nde, 1), Get_val(sub_nde, 2), Get_val(sub_nde, 3));
}
case Wbase_claim_type_.Tid__monolingualtext: {
Json_nde sub_nde = Json_nde.cast(ary.Get_at(3));
return new Wbase_claim_monolingualtext(pid, snak_tid, Get_val(sub_nde, 1), Get_val(sub_nde, 0));
}
default: {throw Err_.new_unhandled(val_tid);}
}
}
private static byte[] Get_val(Json_nde sub_nde, int i) {
Json_kv kv = Json_kv.cast(sub_nde.Get_at(i));
return kv.Val().Data_bry();
}
private void Warn(String fmt, Object... args) {usr_dlg.Warn_many("", "", fmt, args);}
public static final Ordered_hash Empty_ordered_hash_bry = Ordered_hash_.New_bry(), Empty_ordered_hash_generic = Ordered_hash_.New();
private static final byte Prop_tid_m = 0, Prop_tid_q = 1, Prop_tid_g = 2, Prop_tid_rank = 3, Prop_tid_refs = 4;
private static final Hash_adp_bry Prop_key_hash = Hash_adp_bry.ci_a7()
.Add_bry_byte(Wdata_dict_claim_v1.Bry_m , Prop_tid_m)
.Add_bry_byte(Wdata_dict_claim_v1.Bry_q , Prop_tid_q)
.Add_bry_byte(Wdata_dict_claim_v1.Bry_g , Prop_tid_g)
.Add_bry_byte(Wdata_dict_claim_v1.Bry_rank , Prop_tid_rank)
.Add_bry_byte(Wdata_dict_claim_v1.Bry_refs , Prop_tid_refs);
Ordered_hash Bld_hash(Json_doc doc, byte[] key) {
Json_nde nde = Json_nde.cast(doc.Get_grp(key)); if (nde == null) return Empty_ordered_hash_bry;
Ordered_hash rv = Ordered_hash_.New_bry();
int len = nde.Len();
for (int i = 0; i < len; i++) {
Json_kv kv = Json_kv.cast(nde.Get_at(i));
byte[] kv_key = kv.Key().Data_bry();
rv.Add(kv_key, kv);
}
return rv;
}
public Wbase_claim_grp_list Parse_qualifiers(byte[] qid, Json_nde nde) {throw Err_.new_unimplemented();}
public Wbase_references_grp[] Parse_references(byte[] qid, Json_ary owner) {throw Err_.new_unimplemented();}
public int[] Parse_pid_order(byte[] qid, Json_ary ary) {throw Err_.new_unimplemented();}
public static final String
Str_entity = "entity"
, Str_id = "id"
, Str_links = "links"
, Str_label = "label"
, Str_aliases = "aliases"
, Str_claims = "claims"
, Str_description = "description"
, Str_name = "name"
;
public static final byte[]
Bry_entity = Bry_.new_a7(Str_entity)
, Bry_id = Bry_.new_a7(Str_id)
, Bry_links = Bry_.new_a7(Str_links)
, Bry_label = Bry_.new_a7(Str_label)
, Bry_aliases = Bry_.new_a7(Str_aliases)
, Bry_claims = Bry_.new_a7(Str_claims)
, Bry_description = Bry_.new_a7(Str_description)
, Bry_name = Bry_.new_a7(Str_name)
;
}

View File

@@ -0,0 +1,187 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*;
public class Wdata_doc_parser_v1_tst {
@Before public void init() {fxt.Init();} private Wdata_doc_parser_v1_fxt fxt = new Wdata_doc_parser_v1_fxt();
@Test public void Entity_v1_1() {
fxt.Test_entity("{ 'entity':'q1' }", "q1");
}
@Test public void Entity_v1_2() {
fxt.Test_entity("{ 'entity':['item',1] }", "q1");
}
@Test public void Sitelink_v1_1() {
fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last
( "{ 'links':"
, " { 'enwiki':'en_val'"
, " , 'dewiki':'de_val'"
, " , 'frwiki':'fr_val'"
, " }"
, "}"
)
, fxt.Make_sitelink("enwiki", "en_val")
, fxt.Make_sitelink("dewiki", "de_val")
, fxt.Make_sitelink("frwiki", "fr_val")
);
}
@Test public void Sitelink_v1_2() {
fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last
( "{ 'links':"
, " { 'enwiki':"
, " { 'name':'en_val'"
, " , 'badges':"
, " [ 'Q10'"
, " , 'Q11'"
, " , 'Q12'"
, " ]"
, " }"
, " , 'dewiki':"
, " { 'name':'de_val'"
, " , 'badges':"
, " [ 'Q2'"
, " ]"
, " }"
, " , 'frwiki':"
, " { 'name':'fr_val'"
, " , 'badges':[]"
, " }"
, " }"
, "}"
)
, fxt.Make_sitelink("enwiki", "en_val", "Q10", "Q11", "Q12")
, fxt.Make_sitelink("dewiki", "de_val", "Q2")
, fxt.Make_sitelink("frwiki", "fr_val")
);
}
@Test public void Labels() {
fxt.Test_labels(String_.Concat_lines_nl_skip_last
( "{ 'label':"
, " { 'en':'en_val'"
, " , 'de':'de_val'"
, " , 'fr':'fr_val'"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Descriptions() {
fxt.Test_descriptions(String_.Concat_lines_nl_skip_last
( "{ 'description':"
, " { 'en':'en_val'"
, " , 'de':'de_val'"
, " , 'fr':'fr_val'"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Aliases() {
fxt.Test_aliases(String_.Concat_lines_nl_skip_last
( "{ 'aliases':"
, " { 'en':"
, " [ 'en_val_1'"
, " , 'en_val_2'"
, " , 'en_val_3'"
, " ]"
, " ,"
, " 'de':"
, " [ 'de_val_1'"
, " , 'de_val_2'"
, " ]"
, " ,"
, " 'fr':"
, " [ 'fr_val_1'"
, " ]"
, " }"
, "}"
)
, fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3")
, fxt.Make_alias("de", "de_val_1", "de_val_2")
, fxt.Make_alias("fr", "fr_val_1")
);
}
@Test public void Aliases_alt() {
fxt.Test_aliases(String_.Concat_lines_nl_skip_last
( "{ 'aliases':"
, " { 'en':"
, " { '0':'en_val_1'"
, " , '1':'en_val_2'"
, " , '2':'en_val_3'"
, " }"
, " }"
, "}"
)
, fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3")
);
}
@Test public void Claims() {
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'claims':"
, " ["
, " { 'm':"
, " [ 'value'"
, " , 1"
, " , 'string'"
, " , 'abc'"
, " ]"
, " , 'q':[]"
, " , 'g':'Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e'"
, " , 'rank':1"
, " , 'refs':[]"
, " }"
, " ]"
, "}"
)
, fxt.Make_claim_string(1, "abc")
);
}
@Test public void Claim_bad() { // wikidata flags several entries as "bad"; https://www.wikidata.org/wiki/Wikidata:Project_chat/Archive/2013/10
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'entity':['item',2]"
, ", 'claims':"
, " ["
, " { 'm':"
, " [ 'value'"
, " , 373"
, " , 'bad'"
, " ,"
, " { 'latitude':1"
, " , 'longitude':2"
, " , 'altitude':null"
, " , 'precision':1"
, " , 'globe':'http:\\/\\/www.wikidata.org\\/entity\\/Q2'"
, " }"
, " ]"
, " }"
, " ]"
, "}"
)
, fxt.Make_claim_globecoordinate(1, "1", "2", "1") // assume "bad" is same as globecoordinate; DATE:2014-09-20
);
}
}
class Wdata_doc_parser_v1_fxt extends Wdata_doc_parser_fxt_base {
@Override public Wdata_doc_parser Make_parser() {return new Wdata_doc_parser_v1();}
}

View File

@@ -0,0 +1,150 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*; import gplx.core.btries.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wdata_doc_parser_v2 implements Wdata_doc_parser {
private Wdata_claims_parser_v2 claims_parser = new Wdata_claims_parser_v2();
public byte[] Parse_qid(Json_doc doc) {
try {
Json_itm itm = doc.Find_nde(Bry_id);
return Bry_.Lcase__1st(itm.Data_bry()); // standardize on "q" instead of "Q" for compatibility with v1
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse qid", "src", String_.new_u8(doc.Src()));}
}
public Ordered_hash Parse_sitelinks(byte[] qid, Json_doc doc) {
try {
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_sitelinks)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
Ordered_hash rv = Ordered_hash_.New_bry();
int list_len = list_nde.Len();
Hash_adp_bry dict = Wdata_dict_sitelink.Dict;
for (int i = 0; i < list_len; ++i) {
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
Json_nde data_nde = Json_nde.cast(data_kv.Val());
int data_nde_len = data_nde.Len();
Json_kv site_kv = null, name_kv = null; Json_ary badges_ary = null;
for (int j = 0; j < data_nde_len; ++j) {
Json_kv sub = Json_kv.cast(data_nde.Get_at(j));
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wdata_dict_sitelink.Tid_site: site_kv = Json_kv.cast(sub); break;
case Wdata_dict_sitelink.Tid_title: name_kv = Json_kv.cast(sub); break;
case Wdata_dict_sitelink.Tid_badges: badges_ary = Json_ary.cast_or_null(Json_kv.cast(sub).Val()); break;
}
}
byte[] site_bry = site_kv.Val().Data_bry();
Wdata_sitelink_itm itm = new Wdata_sitelink_itm(site_bry, name_kv.Val().Data_bry(), badges_ary.Xto_bry_ary());
rv.Add(site_bry, itm);
}
return rv;
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse sitelinks", "qid", String_.new_u8(qid));}
}
public Ordered_hash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description) {
try {
byte[] langval_key = label_or_description ? Bry_labels : Bry_descriptions;
Json_nde list_nde = Json_nde.cast(doc.Get_grp(langval_key)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
Ordered_hash rv = Ordered_hash_.New_bry();
int list_len = list_nde.Len();
Hash_adp_bry dict = Wdata_dict_langtext.Dict;
for (int i = 0; i < list_len; ++i) {
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
Json_nde data_nde = Json_nde.cast(data_kv.Val());
Json_kv text_kv = null;
int data_nde_len = data_nde.Len();
for (int j = 0; j < data_nde_len; ++j) {
Json_kv sub = Json_kv.cast(data_nde.Get_at(j));
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wdata_dict_langtext.Tid_language: break;
case Wdata_dict_langtext.Tid_value: text_kv = Json_kv.cast(sub); break;
}
}
byte[] lang_bry = data_kv.Key().Data_bry();
Wdata_langtext_itm itm = new Wdata_langtext_itm(lang_bry, text_kv.Val().Data_bry());
rv.Add(lang_bry, itm);
}
return rv;
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse langvals", "qid", String_.new_u8(qid), "langval_tid", label_or_description);}
}
public Ordered_hash Parse_aliases(byte[] qid, Json_doc doc) {
try {
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_aliases)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_bry;
Ordered_hash rv = Ordered_hash_.New_bry();
int list_len = list_nde.Len();
Hash_adp_bry dict = Wdata_dict_langtext.Dict;
for (int i = 0; i < list_len; ++i) {
Json_kv data_kv = Json_kv.cast(list_nde.Get_at(i));
Json_ary vals_ary = Json_ary.cast_or_null(data_kv.Val());
int vals_len = vals_ary.Len();
byte[][] vals = new byte[vals_len][];
for (int j = 0; j < vals_len; ++j) {
Json_nde lang_nde = Json_nde.cast(vals_ary.Get_at(j));
int k_len = lang_nde.Len();
for (int k = 0; k < k_len; ++k) {
Json_kv sub = Json_kv.cast(lang_nde.Get_at(k));
byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wbase_claim_enum_.Tid__invalid) continue;
switch (tid) {
case Wdata_dict_langtext.Tid_language: break;
case Wdata_dict_langtext.Tid_value: vals[j] = sub.Val().Data_bry(); break;
}
}
}
byte[] lang_bry = data_kv.Key().Data_bry();
Wdata_alias_itm itm = new Wdata_alias_itm(lang_bry, vals);
rv.Add(lang_bry, itm);
}
return rv;
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse sitelinks", "qid", String_.new_u8(qid));}
}
public Ordered_hash Parse_claims(byte[] qid, Json_doc doc) {
synchronized (this) {// TS; DATE:2016-07-06
try {
Json_nde list_nde = Json_nde.cast(doc.Get_grp(Bry_claims)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_generic;
List_adp temp_list = List_adp_.New();
byte[] src = doc.Src();
int len = list_nde.Len();
for (int i = 0; i < len; i++) {
Json_kv claim_nde = Json_kv.cast(list_nde.Get_at(i));
claims_parser.Make_claim_itms(qid, temp_list, src, claim_nde);
}
return Wdata_doc_parser_v1.Claims_list_to_hash(temp_list);
} catch (Exception e) {throw Err_.new_exc(e, "xo", "failed to parse claims", "qid", String_.new_u8(doc.Src()));}
}
}
public Wbase_claim_base Parse_claims_data(byte[] qid, int pid, byte snak_tid, Json_nde nde) {return claims_parser.Parse_datavalue(qid, pid, snak_tid, nde);}
public Wbase_claim_grp_list Parse_qualifiers(byte[] qid, Json_nde nde) {return claims_parser.Parse_qualifiers(qid, nde);}
public Wbase_references_grp[] Parse_references(byte[] qid, Json_ary owner) {return claims_parser.Parse_references(qid, owner);}
public int[] Parse_pid_order(byte[] qid, Json_ary ary) {return claims_parser.Parse_pid_order(ary);}
public static final String
Str_id = "id"
, Str_sitelinks = "sitelinks"
, Str_labels = "labels"
, Str_descriptions = "descriptions"
, Str_aliases = "aliases"
, Str_claims = "claims"
, Str_type = "type"
;
public static final byte[]
Bry_id = Bry_.new_a7(Str_id)
, Bry_sitelinks = Bry_.new_a7(Str_sitelinks)
, Bry_labels = Bry_.new_a7(Str_labels)
, Bry_descriptions = Bry_.new_a7(Str_descriptions)
, Bry_aliases = Bry_.new_a7(Str_aliases)
, Bry_claims = Bry_.new_a7(Str_claims)
, Bry_type = Bry_.new_a7(Str_type)
;
}

View File

@@ -0,0 +1,260 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*;
public class Wdata_doc_parser_v2__basic__tst {
@Before public void init() {fxt.Init();} private Wdata_doc_parser_v2_fxt fxt = new Wdata_doc_parser_v2_fxt();
@Test public void Entity() {
fxt.Test_entity("{ 'id':'Q2' }", "q2");
}
@Test public void Sitelink() {
fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last
( "{ 'sitelinks':"
, " { 'enwiki':"
, " { 'site':'enwiki'"
, " , 'title':'en_val'"
, " , 'badges':"
, " [ 'Q10'"
, " , 'Q11'"
, " , 'Q12'"
, " ]"
, " }"
, " , 'dewiki':"
, " { 'site':'dewiki'"
, " , 'title':'de_val'"
, " , 'badges':"
, " [ 'Q2'"
, " ]"
, " }"
, " , 'frwiki':"
, " { 'site':'frwiki'"
, " , 'title':'fr_val'"
, " , 'badges':[]"
, " }"
, " }"
, "}"
)
, fxt.Make_sitelink("enwiki", "en_val", "Q10", "Q11", "Q12")
, fxt.Make_sitelink("dewiki", "de_val", "Q2")
, fxt.Make_sitelink("frwiki", "fr_val")
);
}
@Test public void Labels() {
fxt.Test_labels(String_.Concat_lines_nl_skip_last
( "{ 'labels':"
, " { 'en':"
, " { 'language':'enwiki'"
, " , 'value':'en_val'"
, " }"
, " , 'de':"
, " { 'language':'dewiki'"
, " , 'value':'de_val'"
, " }"
, " , 'fr':"
, " { 'language':'frwiki'"
, " , 'value':'fr_val'"
, " }"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Descriptions() {
fxt.Test_descriptions(String_.Concat_lines_nl_skip_last
( "{ 'descriptions':"
, " { 'en':"
, " { 'language':'enwiki'"
, " , 'value':'en_val'"
, " }"
, " , 'de':"
, " { 'language':'dewiki'"
, " , 'value':'de_val'"
, " }"
, " , 'fr':"
, " { 'language':'frwiki'"
, " , 'value':'fr_val'"
, " }"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Aliases() {
fxt.Test_aliases(String_.Concat_lines_nl_skip_last
( "{ 'aliases':"
, " { 'en':"
, " ["
, " { 'language':'en'"
, " , 'value':'en_val_1'"
, " }"
, " ,"
, " { 'language':'en'"
, " , 'value':'en_val_2'"
, " }"
, " ,"
, " { 'language':'en'"
, " , 'value':'en_val_3'"
, " }"
, " ]"
, " ,"
, " 'de':"
, " ["
, " { 'language':'de'"
, " , 'value':'de_val_1'"
, " }"
, " ,"
, " { 'language':'de'"
, " , 'value':'de_val_2'"
, " }"
, " ]"
, " ,"
, " 'fr':"
, " ["
, " { 'language':'fr'"
, " , 'value':'fr_val_1'"
, " }"
, " ]"
, " }"
, "}"
)
, fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3")
, fxt.Make_alias("de", "de_val_1", "de_val_2")
, fxt.Make_alias("fr", "fr_val_1")
);
}
@Test public void Qualifiers() {
fxt.Test_qualifiers(String_.Concat_lines_nl_skip_last
( "{ 'qualifiers':"
, " { 'P1':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P1'"
, " , 'hash':''"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':11"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ,"
, " { 'snaktype':'value'"
, " , 'property':'P1'"
, " , 'hash':''"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':12"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " ,"
, " 'P2':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P2'"
, " , 'hash':''"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':21"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " }"
, "}"
), fxt.Make_claim_entity_qid(1, 11), fxt.Make_claim_entity_qid(1, 12), fxt.Make_claim_entity_qid(2, 21)
);
}
@Test public void Pid_order() {
fxt.Test_pid_order
( "{ 'qualifiers-order':['P1', 'P2', 'P3'] }"
, 1, 2, 3
);
}
@Test public void References() {
fxt.Test_references(String_.Concat_lines_nl_skip_last
( "{ 'references':"
, " [ "
, " { 'hash':'8e7d51e38606193465d2a1e9d41ba490e06682a6'"
, " , 'snaks':"
, " { 'P2':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P2'"
, " , 'hash':'358e3c0ffa2bfecfe962b39141d99dc2d482110f'"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':21"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " , 'P3':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P3'"
, " , 'hash':'358e3c0ffa2bfecfe962b39141d99dc2d482110f'"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':31"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " }"
, " , 'snaks-order':"
, " [ 'P2'"
, " , 'P3'"
, " ]"
, " }"
, " ]"
, "}"
), Int_.Ary(2, 3), fxt.Make_claim_entity_qid(2, 21), fxt.Make_claim_entity_qid(3, 31))
;
}
@Test public void References_empty() { // PURPOSE:sometimes references can have 0 snaks; return back an empty Wbase_claim_grp_list, not null; PAGE:Птичкин,_Евгений_Николаевич; DATE:2015-02-16
fxt.Test_references(String_.Concat_lines_nl_skip_last
( "{ 'references':"
, " [ "
, " { 'hash':'8e7d51e38606193465d2a1e9d41ba490e06682a6'"
, " , 'snaks':[]"
, " , 'snaks-order':[]"
, " }"
, " ]"
, "}"
), Int_.Ary_empty)
;
}
}

View File

@@ -0,0 +1,193 @@
/*
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.xtns.wbases.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*;
public class Wdata_doc_parser_v2__claims__tst {
@Before public void init() {fxt.Init();} private Wdata_doc_parser_v2_fxt fxt = new Wdata_doc_parser_v2_fxt();
@Test public void Full__string() {
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'claims':"
, " { 'P1':"
, " ["
, " { 'mainsnak':"
, " { 'snaktype':'value'"
, " , 'property':'P1'"
, " , 'hash':'84487fc3f93b4f74ab1cc5a47d78f596f0b49390'"
, " , 'datavalue':"
, " { 'value':'abc'"
, " , 'type':'string'"
, " }"
, " }"
, " , 'type':'statement'"
, " , 'id':'Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e'"
, " , 'rank':'normal'"
, " }"
, " ]"
, " }"
, "}"
)
, fxt.Make_claim_string(1, "abc")
);
}
@Test public void Full__novalue() {
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'claims':"
, " { 'P1':"
, " ["
, " { 'mainsnak':"
, " { 'snaktype':'novalue'"
, " , 'property':'P1'"
, " , 'hash':'84487fc3f93b4f74ab1cc5a47d78f596f0b49390'"
, " }"
, " }"
, " ]"
, " }"
, "}"
)
, fxt.Make_claim_novalue(1)
);
}
@Test public void Data__string() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'abc'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "abc")
);
}
@Test public void Data__item() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':'123'"
, " }"
, ", 'type':'wikibase-entityid'"
, "}"
)
, fxt.Make_claim_entity_qid(1, 123)
);
}
@Test public void Data__property() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'entity-type':'property'"
, " , 'numeric-id':'398'"
, " }"
, ", 'type':'wikibase-entityid'"
, "}"
)
, fxt.Make_claim_entity_pid(1, 398)
);
}
@Test public void Data__monolingualtext() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'text':'en_text'"
, " , 'language':'en'"
, " }"
, ", 'type':'monolingualtext'"
, "}"
)
, fxt.Make_claim_monolingualtext(1, "en", "en_text")
);
}
@Test public void Data__globecoordinate() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'latitude':1.2"
, " , 'longitude':3.4"
, " , 'altitude':null"
, " , 'precision':0.0002"
, " , 'globe':'http:\\/\\/www.wikidata.org\\/entity\\/Q2'"
, " }"
, ", 'type':'globecoordinate'"
, "}"
)
, fxt.Make_claim_globecoordinate(1, "1.2", "3.4", "0.0002")
);
}
@Test public void Data__quantity() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'amount':'123'"
, " , 'unit':'2'"
, " , 'upperBound':'125'"
, " , 'lowerBound':'121'"
, " }"
, ", 'type':'quantity'"
, "}"
)
, fxt.Make_claim_quantity(1, 123, 2, 125, 121)
);
}
@Test public void Data__time() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'time':'+00000002001-02-03T04:05:06Z'"
, " , 'timezone':0"
, " , 'before':0"
, " , 'after':0"
, " , 'precision':11"
, " , 'calendarmodel':'http:\\/\\/www.wikidata.org\\/entity\\/Q1985727'"
, " }"
, ", 'type':'time'"
, "}"
)
, fxt.Make_claim_time(1, "2001-02-03 04:05:06")
);
}
@Test public void Data__url() { // NOTE:has "String" property-type; EX:wd:Q23548; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'http:\\/\\/www.nasa.gov\\/rss\\/dyn\\/breaking_news.rss'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "http://www.nasa.gov/rss/dyn/breaking_news.rss")
);
}
@Test public void Data__commonsMedia() { // NOTE:has "String" property-type; EX:wd:Q327162; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'Tabliczka E40.svg'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "Tabliczka E40.svg")
);
}
@Test public void Data__externalid() { // NOTE:has "String" property-type; EX:wd:Q77177; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'000331371'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "000331371")
);
}
@Test public void Data__math() { // NOTE:has "String" property-type; EX:wd:Q11518; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'a^2+b^2=c^2'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "a^2+b^2=c^2")
);
}
// www.wikidata.org/wiki/Q11518
}

View File

@@ -0,0 +1,54 @@
/*
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.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Wdata_external_lang_links_data {
private List_adp langs_list = List_adp_.New(); private Hash_adp_bry langs_hash = Hash_adp_bry.ci_a7(); // ASCII:lang_code
public boolean Enabled() {return enabled;} private boolean enabled; public Wdata_external_lang_links_data Enabled_(boolean v) {enabled = v; return this;}
public boolean Sort() {return sort;} public Wdata_external_lang_links_data Sort_(boolean v) {sort = v; return this;} private boolean sort;
public int Langs_len() {return langs_list.Count();}
public Wdata_external_lang_links_data Langs_add(byte[] v) {langs_hash.Add(v, v); langs_list.Add(v); return this;}
public byte[] Langs_get_at(int i) {return (byte[])langs_list.Get_at(i);}
public boolean Langs_hide(byte[] src, int bgn, int end) {
if (sort) return false;
return langs_hash.Get_by_mid(src, bgn, end) == null;
}
public void Reset() {
enabled = false;
sort = false;
langs_list.Clear();
langs_hash.Clear();
}
public void Parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Pf_func_base pfunc) {
enabled = true;
byte[] argx = pfunc.Eval_argx(ctx, src, caller, self);
if (Bry_.Eq(argx, Key_sort)) {sort = true; return;} // {{noexternallanglinks:*}}; assume it cannot be combined with other langs_hash: EX: {{noexternallanglinks:*|en|fr}}
int args_len = self.Args_len();
Langs_add(argx);
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b128();
for (int i = 0; i < args_len; i++) {
Arg_nde_tkn nde = self.Args_get_by_idx(i);
nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, tmp_bfr); // NOTE: changed from self to caller; DATE:2016-03-16
byte[] lang = tmp_bfr.To_bry_and_clear();
Langs_add(lang);
}
tmp_bfr.Mkr_rls();
}
public static final byte[] Key_sort = new byte[] {Byte_ascii.Star};
}

View File

@@ -0,0 +1,34 @@
/*
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.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Wdata_pf_noExternalLangLinks extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_noexternallanglinks;}
@Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_noExternalLangLinks().Name_(name);}
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
ctx.Page().Wdata_external_lang_links().Parse(ctx, src, caller, self, this);
}
public static void Print_self(Gfo_usr_dlg usr_dlg, Bry_bfr bfr, byte[] src, Xot_invk self, String warn_cls, String warn_fmt, Object... args) {
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
usr_dlg.Warn_many(GRP_KEY, warn_cls, warn_fmt, args);
}
static final String GRP_KEY = "xowa.xtns.wdata.noexternallanglinks";
}

View File

@@ -0,0 +1,64 @@
/*
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.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
public class Wdata_pf_noExternalLangLinks_tst {
@Before public void init() {fxt.Clear();} Wdata_pf_noExternalLangLinks_fxt fxt = new Wdata_pf_noExternalLangLinks_fxt();
@Test public void Basic() {
fxt.Clear().Expd_enabled_(true).Test_parse("{{noexternallanglinks}}");
fxt.Clear().Expd_enabled_(false).Expd_sort_(false).Expd_langs_().Test_parse("");
}
@Test public void Selected() {
fxt.Clear().Expd_enabled_(true).Expd_langs_("en", "fr").Test_parse("{{noexternallanglinks:en|fr}}");
}
@Test public void Sort() {
fxt.Clear().Expd_enabled_(true).Expd_sort_(true).Expd_langs_().Test_parse("{{noexternallanglinks:*}}");
}
}
class Wdata_pf_noExternalLangLinks_fxt {
public Wdata_pf_noExternalLangLinks_fxt Clear() {
if (parser_fxt == null) {
parser_fxt = new Xop_fxt();
app = parser_fxt.App();
wiki = parser_fxt.Wiki();
data = wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links();
}
expd_sort = expd_enabled = Bool_.__byte;
expd_langs = null;
data.Reset();
return this;
} private Xop_fxt parser_fxt; Xoae_app app; Xowe_wiki wiki; Wdata_external_lang_links_data data;
public Wdata_pf_noExternalLangLinks_fxt Expd_enabled_(boolean v) {expd_enabled = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_enabled;
public Wdata_pf_noExternalLangLinks_fxt Expd_sort_(boolean v) {expd_sort = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_sort;
public Wdata_pf_noExternalLangLinks_fxt Expd_langs_(String... v) {expd_langs = v; return this;} private String[] expd_langs;
public void Test_parse(String raw) {
byte[] expd = parser_fxt.Test_parse_tmpl_str_rv(raw);
Tfds.Eq(Bry_.Empty, expd);
if (expd_enabled != Bool_.__byte) Tfds.Eq(expd_enabled == Bool_.Y_byte, data.Enabled());
if (expd_sort != Bool_.__byte) Tfds.Eq(expd_sort == Bool_.Y_byte, data.Sort());
if (expd_langs != null) Tfds.Eq_ary_str(expd_langs, Data_langs_xto_str_ary());
}
String[] Data_langs_xto_str_ary() {
int len = data.Langs_len();
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
rv[i] = String_.new_u8((byte[])data.Langs_get_at(i));
}
return rv;
}
}

Some files were not shown because too many files have changed in this diff Show More