mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Wikibase: Return label and language, not just label [#407]
This commit is contained in:
parent
9bc0c2c75d
commit
88dfc857bd
@ -152,7 +152,7 @@ public class Xoh_js_cbk implements Gfo_invk {
|
||||
if (Bry_.Eq(lang_key, Wikidata_get_label_xowa_title))
|
||||
val_bry = ttl_bry;
|
||||
else {
|
||||
val_bry = page.Label_list__get(lang_key);
|
||||
val_bry = page.Get_label_bry_or_null(lang_key);
|
||||
}
|
||||
if (val_bry == null) continue;
|
||||
rv[i - 1] = String_.new_u8(val_bry);
|
||||
|
@ -45,7 +45,7 @@ public class Xoh_js_cbk_wdata_labels_tst {
|
||||
private Wdata_doc doc_(String qid, String src) {
|
||||
Json_doc jdoc = fxt.Make_json(src);
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Wdata_doc rv = new Wdata_doc(Bry_.new_a7(qid), app.Wiki_mgr().Wdata_mgr(), jdoc);
|
||||
Wdata_doc rv = new Wdata_doc(app.Wiki_mgr().Wdata_mgr(), jdoc, Bry_.new_a7(qid));
|
||||
return rv;
|
||||
}
|
||||
private void Tst_wikidata_label_get(String[] args, String[] expd) {
|
||||
|
@ -95,7 +95,8 @@ class Referenced_entity_lookup_wkr {
|
||||
return entity_mgr.Get_by_loose_id_or_null(id);
|
||||
}
|
||||
private Wbase_claim_base[] getMainSnaks(Wdata_doc entity, int propertyId) {
|
||||
Wbase_claim_grp claims = entity.Claim_list_get(propertyId);
|
||||
Wbase_claim_grp claims = entity.Get_claim_grp_or_null(propertyId);
|
||||
if (claims == null) return Wbase_claim_base.Ary_empty;
|
||||
return claims.Get_best(tmp_snak_list);
|
||||
}
|
||||
private byte[] processSnak(Wbase_claim_base snak, Ordered_hash toVisit, Ordered_hash toIds) {
|
||||
|
@ -17,7 +17,7 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.stores.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.xtns.scribunto.procs.*;
|
||||
import gplx.xowa.xtns.wbases.mediawiki.client.includes.*; import gplx.xowa.xtns.wbases.mediawiki.client.includes.dataAccess.scribunto.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.mediawiki.client.includes.*; import gplx.xowa.xtns.wbases.mediawiki.client.includes.dataAccess.scribunto.*;
|
||||
public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
private final Scrib_core core;
|
||||
private Wbase_doc_mgr entity_mgr;
|
||||
@ -268,24 +268,31 @@ public function formatValues( $snaksSerialization ) {
|
||||
}
|
||||
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core, "GetLabel", true);
|
||||
if (wdoc == null)
|
||||
return rslt.Init_ary_empty();
|
||||
else
|
||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||
if (wdoc == null) return rslt.Init_ary_empty();
|
||||
|
||||
Wdata_langtext_itm itm = wdoc.Get_label_itm_or_null(core.Lang());
|
||||
return itm == null ? rslt.Init_ary_empty() : rslt.Init_many_objs(itm.Text(), itm.Lang());
|
||||
}
|
||||
public boolean GetLabelByLanguage(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] prefixedEntityId = args.Pull_bry(0);
|
||||
byte[] languageCode = args.Pull_bry(1);
|
||||
return rslt.Init_obj(wdata_mgr.Lua_bindings().getLabelByLanguage(prefixedEntityId, languageCode));
|
||||
byte[] label = wdata_mgr.Lua_bindings().getLabelByLanguage_or_null(prefixedEntityId, languageCode);
|
||||
return label == null ? rslt.Init_str_empty() : rslt.Init_obj(label);
|
||||
}
|
||||
public boolean GetSiteLinkPageName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core, "GetSiteLinkPageName", true); if (wdoc == null) return rslt.Init_ary_empty(); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core, "GetSiteLinkPageName", true); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
||||
if (wdoc == null) return rslt.Init_ary_empty();
|
||||
|
||||
Xow_domain_itm domain_itm = core.Wiki().Domain_itm();
|
||||
return rslt.Init_obj(wdoc.Slink_list__get_or_fallback(domain_itm.Abrv_wm()));
|
||||
Wdata_sitelink_itm itm = wdoc.Get_slink_itm_or_null(domain_itm.Abrv_wm());
|
||||
return itm == null ? rslt.Init_ary_empty() : rslt.Init_many_objs(itm.Name(), itm.Lang());
|
||||
}
|
||||
public boolean GetDescription(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core, "GetDescription", true); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Descr_list__get_or_fallback(core.Lang()));
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core, "GetDescription", true);
|
||||
if (wdoc == null) return rslt.Init_ary_empty();
|
||||
|
||||
Wdata_langtext_itm itm = wdoc.Get_descr_itm_or_null(core.Lang());
|
||||
return itm == null ? rslt.Init_ary_empty() : rslt.Init_many_objs(itm.Text(), itm.Lang());
|
||||
}
|
||||
public boolean GetUserLang(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.App().Usere().Lang().Key_bry());
|
||||
|
@ -87,7 +87,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib { // REF.MW:https://
|
||||
if (pid_int == Wbase_pid.Id_null) return rslt.Init_str_empty();
|
||||
|
||||
// get prop_grp
|
||||
Wbase_claim_grp prop_grp = wdoc.Claim_list_get(pid_int);
|
||||
Wbase_claim_grp prop_grp = wdoc.Get_claim_grp_or_null(pid_int);
|
||||
if (prop_grp == null)
|
||||
return rslt.Init_str_empty();
|
||||
|
||||
|
@ -71,21 +71,21 @@ public class Basic__tst {
|
||||
rv[i] = Keyval_.int_(i, toIds[i]);
|
||||
return rv;
|
||||
}
|
||||
@Test public void GetLabel__cur() {
|
||||
@Test public void GetLabel__cur() {// do not get fallback
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hans", "s").Add_label("zh-hant", "t").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "s"); // do not get fallback
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), String_.Concat_lines_nl_skip_last("1=s", "2=zh-hans"));
|
||||
}
|
||||
@Test public void GetLabel__fallback_1() {
|
||||
@Test public void GetLabel__fallback_1() { // get 1st fallback
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hant", "t").Add_label("zh-hk", "h").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "t"); // get 1st fallback
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), String_.Concat_lines_nl_skip_last("1=t", "2=zh-hant"));
|
||||
}
|
||||
@Test public void GetLabel__fallback_2() {
|
||||
@Test public void GetLabel__fallback_2() {// get 2nd fallback
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("zh-hk", "hk").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "hk"); // get 2nd fallback
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), String_.Concat_lines_nl_skip_last("1=hk", "2=zh-hk"));
|
||||
}
|
||||
@Test public void GetLabel__fallback_en() {
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "en").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), "en"); // get en
|
||||
@Test public void GetLabel__fallback_en() {// get en
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "lbl_en").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getLabel, Object_.Ary("q2"), String_.Concat_lines_nl_skip_last("1=lbl_en", "2=en"));
|
||||
}
|
||||
@Test public void GetDescr() {
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_description("zh-hans", "s").Add_description("zh-hant", "t").Xto_wdoc());
|
||||
|
@ -79,7 +79,7 @@ public class Srl__tst {// see also FOOTNOTE:VIEWING_WIKIDATA_JSON
|
||||
, " }"
|
||||
, "}"
|
||||
);
|
||||
Wdata_doc wdoc = new Wdata_doc(Bry_.new_a7("q2"), fxt.Wdata_fxt().App().Wiki_mgr().Wdata_mgr(), jdoc);
|
||||
Wdata_doc wdoc = new Wdata_doc(fxt.Wdata_fxt().App().Wiki_mgr().Wdata_mgr(), jdoc, Bry_.new_a7("q2"));
|
||||
fxt.Test
|
||||
( wdoc
|
||||
, "sitelinks:"
|
||||
|
@ -19,50 +19,55 @@ 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;
|
||||
private final Wdata_wiki_mgr mgr;
|
||||
public Wdata_doc(Wdata_wiki_mgr mgr, Json_doc jdoc, byte[] qid) {
|
||||
this.mgr = mgr; this.jdoc = jdoc; this.qid = qid;
|
||||
}
|
||||
public Json_doc Jdoc() {return jdoc;} private Json_doc jdoc;
|
||||
public byte[] Qid() {return qid;} private final byte[] qid;
|
||||
public Json_doc Jdoc() {return jdoc;} private final Json_doc jdoc;
|
||||
public int Jdoc_size() {return jdoc == null ? 1 : jdoc.Src().length;}
|
||||
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;
|
||||
|
||||
// NOTE: lazy instantiation b/c we don't want to parse entire json unless called; particulary necessary for {{#property}} calls;
|
||||
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));
|
||||
|
||||
// various getters
|
||||
public Wbase_claim_grp Get_claim_grp_or_null(int pid) {
|
||||
Object o = this.Claim_list().Get_by(Int_obj_ref.New(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();
|
||||
public byte[] Get_label_bry_or_null(byte[] lang_key) {
|
||||
Wdata_langtext_itm itm = (Wdata_langtext_itm)this.Label_list().Get_by(lang_key);
|
||||
return itm == null ? null : itm.Text();
|
||||
}
|
||||
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);
|
||||
public Wdata_langtext_itm Get_label_itm_or_null(Xol_lang_itm lang) {return Get_langtext_itm_or_null(this.Label_list(), lang);}
|
||||
public Wdata_langtext_itm Get_descr_itm_or_null(Xol_lang_itm lang) {return Get_langtext_itm_or_null(this.Descr_list(), lang);}
|
||||
public Wdata_sitelink_itm Get_slink_itm_or_null(byte[] abrv_wm) {return (Wdata_sitelink_itm)this.Slink_list().Get_by(abrv_wm);}
|
||||
|
||||
// helper method
|
||||
private Wdata_langtext_itm Get_langtext_itm_or_null(Ordered_hash hash, Xol_lang_itm lang) {
|
||||
// get itm by lang's key
|
||||
Wdata_langtext_itm itm = (Wdata_langtext_itm)hash.Get_by(lang.Key_bry());
|
||||
if (itm != null) return itm;
|
||||
|
||||
// loop over fallback_langs
|
||||
byte[][] fallback_langs = lang.Fallback_bry_ary(); // NOTE: en is currently automatically being added by Xol_lang_itm
|
||||
int len = fallback_langs.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] lang_key = fallback_langs[i];
|
||||
Object itm_obj = hash.Get_by(lang_key);
|
||||
if (itm_obj != null) {
|
||||
Wdata_langtext_itm itm = (Wdata_langtext_itm)itm_obj;
|
||||
return itm.Text();
|
||||
return (Wdata_langtext_itm)itm_obj;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Wdata_doc Ctor_by_test(Ordered_hash slink_list, Ordered_hash label_list, Ordered_hash descr_list, Ordered_hash alias_list, Ordered_hash claim_list) {// TEST
|
||||
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;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class Wdata_doc_bldr {
|
||||
}
|
||||
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);
|
||||
Wdata_doc rv = new Wdata_doc(null, null, qid).Ctor_by_test(slink_list, label_list, descr_list, alias_list, claim_list);
|
||||
this.Init();
|
||||
return rv;
|
||||
}
|
||||
|
@ -58,11 +58,11 @@ public class Wdata_prop_val_visitor implements Wbase_claim_visitor { // THREAD.U
|
||||
return;
|
||||
|
||||
// get label
|
||||
byte[] label = entity_doc.Label_list__get(lang_key);
|
||||
byte[] label = entity_doc.Get_label_bry_or_null(lang_key);
|
||||
|
||||
// NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19
|
||||
if (label == null && !Bry_.Eq(lang_key, Xol_lang_itm_.Key_en))
|
||||
label = entity_doc.Label_list__get(Xol_lang_itm_.Key_en);
|
||||
label = entity_doc.Get_label_bry_or_null(Xol_lang_itm_.Key_en);
|
||||
|
||||
// if label is still not found, don't add null reference
|
||||
if (label != null) {
|
||||
@ -110,7 +110,11 @@ public class Wdata_prop_val_visitor implements Wbase_claim_visitor { // THREAD.U
|
||||
bfr.Add_byte_space();
|
||||
byte[] xid = Bry_.Mid(unit, Wikidata_url.length);
|
||||
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(xid);
|
||||
bfr.Add(entity_doc.Label_list__get_or_fallback(lang));
|
||||
if (entity_doc != null) {
|
||||
Wdata_langtext_itm label = entity_doc.Get_label_itm_or_null(lang);
|
||||
if (label != null)
|
||||
bfr.Add(label.Text());
|
||||
}
|
||||
}
|
||||
}
|
||||
private static Decimal_adp Decimal__parse_or(byte[] bry, Decimal_adp or) { // handle missing lbound / ubound; DATE:2016-12-03
|
||||
|
@ -88,7 +88,8 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
public byte[] Get_claim_or(Xow_domain_itm domain, Xoa_ttl page_ttl, int pid, byte[] or) {
|
||||
byte[] qid = this.Qid_mgr.Get_qid_or_null(domain.Abrv_wm(), page_ttl); if (qid == null) return or;
|
||||
Wdata_doc wdoc = Doc_mgr.Get_by_loose_id_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_grp claim_grp = wdoc.Get_claim_grp_or_null(pid);
|
||||
if (claim_grp == null || claim_grp.Len() == 0) return or;
|
||||
Wbase_claim_base claim_itm = claim_grp.Get_at(0);
|
||||
Resolve_claim(tmp_bfr, domain, claim_itm);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
|
@ -58,7 +58,7 @@ public class Wdata_xwiki_link_wtr_tst {
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
Wdata_doc wdata_doc = new Wdata_doc(Bry_.new_a7("Q1"), fxt.App().Wiki_mgr().Wdata_mgr(), jdoc);
|
||||
Wdata_doc wdata_doc = new Wdata_doc(fxt.App().Wiki_mgr().Wdata_mgr(), jdoc, Bry_.new_a7("Q1"));
|
||||
fxt.Init__docs__add(wdata_doc);
|
||||
fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr");
|
||||
}
|
||||
@ -74,7 +74,7 @@ public class Wdata_xwiki_link_wtr_tst {
|
||||
, " }"
|
||||
, "}"
|
||||
));
|
||||
Wdata_doc wdata_doc = new Wdata_doc(Bry_.new_a7("Q1"), fxt.App().Wiki_mgr().Wdata_mgr(), jdoc);
|
||||
Wdata_doc wdata_doc = new Wdata_doc(fxt.App().Wiki_mgr().Wdata_mgr(), jdoc, Bry_.new_a7("Q1"));
|
||||
fxt.Init__docs__add(wdata_doc);
|
||||
fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr");
|
||||
}
|
||||
|
@ -41,4 +41,6 @@ public abstract class Wbase_claim_base implements CompareAble {
|
||||
Wbase_claim_base comp = (Wbase_claim_base)obj;
|
||||
return Int_.Compare(pid, comp.pid);
|
||||
}
|
||||
|
||||
public static final Wbase_claim_base[] Ary_empty = new Wbase_claim_base[0];
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class Xob_wdata_db_cmd extends Xob_dump_mgr_base implements Xob_cmd {
|
||||
}
|
||||
@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);
|
||||
Wdata_doc wdoc = new Wdata_doc(wdata_mgr, jdoc, page.Ttl_page_db());
|
||||
tbl_mgr.Exec_insert_by_wdoc(lang_key, wdata_mgr, page.Id(), wdoc);
|
||||
}
|
||||
@Override public void Exec_commit_hook() {
|
||||
@ -417,6 +417,10 @@ class Xob_wdata_db_visitor implements Wbase_claim_visitor {
|
||||
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);
|
||||
if (entity_doc != null) {
|
||||
rv = entity_doc.Get_label_bry_or_null(lang_key);
|
||||
}
|
||||
if (rv == null) // can be null if entity_doc is null or if label is null;
|
||||
rv = Bry_.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class Wbase_entity_accessor {
|
||||
}
|
||||
|
||||
List_adp rv = List_adp_.New();
|
||||
Wbase_claim_grp statements = entity.Claim_list_get(propertyId);
|
||||
Wbase_claim_grp statements = entity.Get_claim_grp_or_null(propertyId);
|
||||
if (statements == null)
|
||||
return null;
|
||||
|
||||
|
@ -22,8 +22,8 @@ public class WikibaseLanguageIndependentLuaBindings {
|
||||
public WikibaseLanguageIndependentLuaBindings(Wbase_doc_mgr entity_mgr) {
|
||||
this.termLookup = new EntityRetrievingTermLookup(entity_mgr);
|
||||
}
|
||||
public byte[] getLabelByLanguage(byte[] prefixedEntityId, byte[] languageCode) {
|
||||
return termLookup.getLabel(prefixedEntityId, languageCode);
|
||||
public byte[] getLabelByLanguage_or_null(byte[] prefixedEntityId, byte[] languageCode) {
|
||||
return termLookup.getLabel_or_null(prefixedEntityId, languageCode);
|
||||
}
|
||||
public Object getSetting(byte[] key) {
|
||||
return settings.getSetting(key);
|
||||
|
@ -21,8 +21,8 @@ public class EntityRetrievingTermLookup {
|
||||
this.entity_mgr = entity_mgr;
|
||||
}
|
||||
|
||||
public byte[] getLabel(byte[] entityId, byte[] languageCode) {
|
||||
public byte[] getLabel_or_null(byte[] entityId, byte[] languageCode) {
|
||||
Wdata_doc entity = entity_mgr.Get_by_xid_or_null(entityId);
|
||||
return entity.Label_list__get(languageCode);
|
||||
return entity.Get_label_bry_or_null(languageCode);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class Wbase_statement_mgr_ {
|
||||
if (doc == null) return; // NOTE: some pages will not have a qid; EX: "Some_unknown_page" will not have a qid in wikidata; if no qid, then all {{#property:p###}} will have no prop_val
|
||||
|
||||
// get val based on pid and doc; EX: {{#property:p123|of=Earth}} -> doc=Q2; pid=123 -> "value of p123 in Q2"
|
||||
Wbase_claim_grp claim_grp = doc.Claim_list_get(pid_int);
|
||||
Wbase_claim_grp claim_grp = doc.Get_claim_grp_or_null(pid_int);
|
||||
if (claim_grp == null) return;// NOTE: some props may not exist; EX: "Some_known_page" has a qid of 123 but does not have pid 345 required by {{#property:P345|q=123}}
|
||||
wdata_mgr.Resolve_to_bfr(bfr, claim_grp, wiki.Wdata_wiki_lang(), mode_is_statements); // NOTE: was ctx.Page().Lang().Key_bry(), but fails in simplewiki; DATE:2013-12-02
|
||||
if (property_wkr != null) property_wkr.Eval_end(ctx.Page(), pid_ttl, log_time_bgn);
|
||||
|
@ -126,7 +126,7 @@ public class Wbase_doc_mgr {
|
||||
}
|
||||
|
||||
// is json doc, and not a redirect; return
|
||||
rv = new Wdata_doc(cur_ttl_bry, wbase_mgr, jdoc);
|
||||
rv = new Wdata_doc(wbase_mgr, jdoc, cur_ttl_bry);
|
||||
break;
|
||||
}
|
||||
if (rv == null && load_count >= 2)
|
||||
|
95
h origin master
Normal file
95
h origin master
Normal file
@ -0,0 +1,95 @@
|
||||
[1mdiff --git a/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java b/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java[m
|
||||
[1mindex f6d1ef3..97fdf7f 100644[m
|
||||
[1m--- a/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java[m
|
||||
[1m+++ b/400_xowa/src/gplx/xowa/xtns/wbases/Wdata_doc.java[m
|
||||
[36m@@ -19,50 +19,55 @@[m [mimport gplx.langs.jsons.*;[m
|
||||
import gplx.xowa.langs.*;[m
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.parsers.*;[m
|
||||
public class Wdata_doc {[m
|
||||
[31m- private Wdata_wiki_mgr mgr; private Int_obj_ref tmp_key;[m
|
||||
[31m- public Wdata_doc(byte[] qid, Wdata_wiki_mgr mgr, Json_doc jdoc) {this.qid = qid; this.mgr = mgr; this.jdoc = jdoc;}[m
|
||||
[31m- 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[m
|
||||
[31m- this.qid = qid;[m
|
||||
[31m- 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;[m
|
||||
[32m+[m [32mprivate final Wdata_wiki_mgr mgr;[m[41m
[m
|
||||
[32m+[m [32mpublic Wdata_doc(Wdata_wiki_mgr mgr, Json_doc jdoc, byte[] qid) {[m[41m
[m
|
||||
[32m+[m [32mthis.mgr = mgr; this.jdoc = jdoc; this.qid = qid;[m[41m
[m
|
||||
}[m
|
||||
[31m- public Json_doc Jdoc() {return jdoc;} private Json_doc jdoc;[m
|
||||
[32m+[m [32mpublic byte[] Qid() {return qid;} private final byte[] qid;[m[41m
[m
|
||||
[32m+[m [32mpublic Json_doc Jdoc() {return jdoc;} private final Json_doc jdoc;[m[41m
[m
|
||||
public int Jdoc_size() {return jdoc == null ? 1 : jdoc.Src().length;}[m
|
||||
[31m- public byte[] Qid() {return qid;} private byte[] qid;[m
|
||||
public byte[][] Sort_langs() {return sort_langs;} public void Sort_langs_(byte[][] v) {sort_langs = v;} private byte[][] sort_langs = Bry_.Ary_empty;[m
|
||||
[31m- 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;[m
|
||||
[31m- 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;[m
|
||||
[31m- 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;[m
|
||||
[31m- 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;[m
|
||||
[31m- 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;[m
|
||||
[31m- public Wbase_claim_grp Claim_list_get(int pid) {[m
|
||||
[31m- if (tmp_key == null) tmp_key = Int_obj_ref.New_neg1(); [m
|
||||
[31m- Object o = this.Claim_list().Get_by(tmp_key.Val_(pid));[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// NOTE: lazy instantiation b/c we don't want to parse entire json unless called; particulary necessary for {{#property}} calls;[m[41m
[m
|
||||
[32m+[m [32mpublic 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;[m[41m
[m
|
||||
[32m+[m [32mpublic 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;[m[41m
[m
|
||||
[32m+[m [32mpublic 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;[m[41m
[m
|
||||
[32m+[m [32mpublic 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;[m[41m
[m
|
||||
[32m+[m [32mpublic 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;[m[41m
[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// various getters[m[41m
[m
|
||||
[32m+[m [32mpublic Wbase_claim_grp Get_claim_grp_or_null(int pid) {[m[41m
[m
|
||||
[32m+[m [32mObject o = this.Claim_list().Get_by(Int_obj_ref.New(pid));[m[41m
[m
|
||||
return (Wbase_claim_grp)o;[m
|
||||
[31m- } [m
|
||||
[31m- public byte[] Label_list__get(byte[] lang_key) {return Lang_text_list__get(this.Label_list(), lang_key);}[m
|
||||
[31m- public byte[] Label_list__get_or_fallback(Xol_lang_itm lang) {return Lang_text_list__get_or_fallback(this.Label_list(), lang);}[m
|
||||
[31m- public byte[] Descr_list__get_or_fallback(Xol_lang_itm lang) {return Lang_text_list__get_or_fallback(this.Descr_list(), lang);}[m
|
||||
[31m- public byte[] Slink_list__get_or_fallback(byte[] abrv_wm) {[m
|
||||
[31m- Wdata_sitelink_itm rv = (Wdata_sitelink_itm)this.Slink_list().Get_by(abrv_wm);[m
|
||||
[31m- return rv == null ? null : rv.Name();[m
|
||||
}[m
|
||||
[31m- private byte[] Lang_text_list__get(Ordered_hash hash, byte[] lang_key) {[m
|
||||
[31m- Object rv_obj = hash.Get_by(lang_key); if (rv_obj == null) return null;[m
|
||||
[31m- Wdata_langtext_itm rv = (Wdata_langtext_itm)rv_obj;[m
|
||||
[31m- return rv.Text();[m
|
||||
[32m+[m [32mpublic byte[] Get_label_bry_or_null(byte[] lang_key) {[m[41m
[m
|
||||
[32m+[m [32mWdata_langtext_itm itm = (Wdata_langtext_itm)this.Label_list().Get_by(lang_key);[m[41m
[m
|
||||
[32m+[m [32mreturn itm == null ? null : itm.Text();[m[41m
[m
|
||||
}[m
|
||||
[31m- public byte[] Lang_text_list__get_or_fallback(Ordered_hash lang_text_list, Xol_lang_itm lang) {[m
|
||||
[31m- byte[] rv = Lang_text_list__get(lang_text_list, lang.Key_bry()); if (rv != null) return rv;[m
|
||||
[31m- byte[][] ary = lang.Fallback_bry_ary(); // NOTE: en is currently automatically being added by Xol_lang_itm[m
|
||||
[31m- int len = ary.length;[m
|
||||
[31m- for (int i = 0; i < len; ++i) {[m
|
||||
[31m- byte[] lang_key = ary[i];[m
|
||||
[31m- Object itm_obj = lang_text_list.Get_by(lang_key);[m
|
||||
[32m+[m [32mpublic Wdata_langtext_itm Get_label_itm_or_null(Xol_lang_itm lang) {return Get_langtext_itm_or_null(this.Label_list(), lang);}[m[41m
[m
|
||||
[32m+[m [32mpublic Wdata_langtext_itm Get_descr_itm_or_null(Xol_lang_itm lang) {return Get_langtext_itm_or_null(this.Descr_list(), lang);}[m[41m
[m
|
||||
[32m+[m [32mpublic Wdata_sitelink_itm Get_slink_itm_or_null(byte[] abrv_wm) {return (Wdata_sitelink_itm)this.Slink_list().Get_by(abrv_wm);}[m[41m
[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// helper method[m[41m
[m
|
||||
[32m+[m [32mprivate Wdata_langtext_itm Get_langtext_itm_or_null(Ordered_hash hash, Xol_lang_itm lang) {[m[41m
[m
|
||||
[32m+[m [32m// get itm by lang's key[m[41m
[m
|
||||
[32m+[m [32mWdata_langtext_itm itm = (Wdata_langtext_itm)hash.Get_by(lang.Key_bry());[m[41m
[m
|
||||
[32m+[m [32mif (itm != null) return itm;[m[41m
[m
|
||||
[32m+[m[41m
[m
|
||||
[32m+[m [32m// loop over fallback_langs[m[41m
[m
|
||||
[32m+[m [32mbyte[][] fallback_langs = lang.Fallback_bry_ary(); // NOTE: en is currently automatically being added by Xol_lang_itm[m[41m
[m
|
||||
[32m+[m [32mint len = fallback_langs.length;[m[41m
[m
|
||||
[32m+[m [32mfor (int i = 0; i < len; i++) {[m[41m
[m
|
||||
[32m+[m [32mbyte[] lang_key = fallback_langs[i];[m[41m
[m
|
||||
[32m+[m [32mObject itm_obj = hash.Get_by(lang_key);[m[41m
[m
|
||||
if (itm_obj != null) {[m
|
||||
[31m- Wdata_langtext_itm itm = (Wdata_langtext_itm)itm_obj;[m
|
||||
[31m- return itm.Text();[m
|
||||
[32m+[m [32mreturn (Wdata_langtext_itm)itm_obj;[m[41m
[m
|
||||
}[m
|
||||
}[m
|
||||
return null;[m
|
||||
}[m
|
||||
[32m+[m [32mpublic Wdata_doc Ctor_by_test(Ordered_hash slink_list, Ordered_hash label_list, Ordered_hash descr_list, Ordered_hash alias_list, Ordered_hash claim_list) {// TEST[m[41m
[m
|
||||
[32m+[m [32mthis.slink_list = slink_list; this.label_list = label_list; this.descr_list = descr_list; this.alias_list = alias_list; this.claim_list = claim_list;[m[41m
[m
|
||||
[32m+[m [32mreturn this;[m[41m
[m
|
||||
[32m+[m [32m}[m[41m
[m
|
||||
}[m
|
Loading…
Reference in New Issue
Block a user