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:
@@ -163,11 +163,16 @@ public class Scrib_core {
|
||||
this.frame_parent = parent_frame; this.frame_current = current_frame;
|
||||
}
|
||||
public void Invoke(Xowe_wiki wiki, Xop_ctx ctx, byte[] src, Xot_invk parent_frame, Xot_invk current_frame, Bry_bfr bfr, byte[] mod_name, byte[] mod_text, byte[] fnc_name) {
|
||||
// save current values for restoring later
|
||||
Xot_invk old_frame_parent = this.frame_parent; Xot_invk old_frame_current = this.frame_current;
|
||||
byte[] old_src = cur_src;
|
||||
|
||||
// init
|
||||
this.wiki = wiki; this.ctx = ctx; this.cur_src = src;
|
||||
lib_mw.Invoke_bgn(wiki, ctx, src);
|
||||
Xot_invk old_frame_parent = this.frame_parent; Xot_invk old_frame_current = this.frame_current;
|
||||
this.frame_parent = parent_frame; this.frame_current = current_frame;
|
||||
parent_frame.Frame_tid_(Scrib_frame_.Tid_parent); current_frame.Frame_tid_(Scrib_frame_.Tid_current);
|
||||
|
||||
try {
|
||||
Scrib_lua_mod mod = Mods_get_or_new(mod_name, mod_text);
|
||||
Keyval[] func_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_u8(fnc_name));
|
||||
@@ -188,6 +193,7 @@ public class Scrib_core {
|
||||
lib_mw.Invoke_end();
|
||||
parent_frame.Frame_tid_(Scrib_frame_.Tid_null); current_frame.Frame_tid_(Scrib_frame_.Tid_null);
|
||||
this.frame_parent = old_frame_parent; this.frame_current = old_frame_current; // NOTE: reset template frame; PAGE:en.w:Constantine_the_Great {{Christianity}}; DATE:2014-06-26
|
||||
this.cur_src = old_src;
|
||||
frame_created_list.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,12 @@ public class Scrib_kv_utl_ {
|
||||
try {return (Keyval[])ary[idx].Val();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as Keyval[] failed", "ary", Keyval_.Ary_to_str(ary));}
|
||||
}
|
||||
public static Object Get_sub_by_key_or_null(Keyval[] ary, String key) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval sub = ary[i];
|
||||
if (String_.Eq(key, sub.Key())) return sub.Val();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,12 @@ public class Luaj_server implements Scrib_server {
|
||||
this.func_recv = func_recv;
|
||||
this.func_dbg = func_dbg;
|
||||
}
|
||||
private Globals luaj_globals;
|
||||
public Globals Luaj_globals() {return luaj_globals;} private Globals luaj_globals;
|
||||
public DebugLib Luaj_dbg() {return luaj_dbg;} private DebugLib luaj_dbg;
|
||||
public void Init(String... init_args) {
|
||||
luaj_dbg = new DebugLib(); // NOTE: needed for getfenv
|
||||
luaj_globals = JsePlatform.standardGlobals();
|
||||
luaj_globals.load(new DebugLib());
|
||||
luaj_globals.load(luaj_dbg);
|
||||
luaj_globals.load(new MWClient(luaj_globals, func_recv));
|
||||
luaj_globals.set("dbg", func_dbg);
|
||||
String root_str = init_args[2];
|
||||
|
||||
@@ -151,8 +151,10 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
private boolean Case_1st(Scrib_proc_args args, Scrib_proc_rslt rslt, boolean upper) {
|
||||
Xol_lang_itm lang = lang_(args);
|
||||
byte[] word = args.Pull_bry(1);
|
||||
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b128().Mkr_rls();
|
||||
return rslt.Init_obj(lang.Case_mgr().Case_build_1st(bfr, upper, word, 0, word.length));
|
||||
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b128();
|
||||
try {
|
||||
return rslt.Init_obj(lang.Case_mgr().Case_build_1st(bfr, upper, word, 0, word.length));
|
||||
} finally {bfr.Mkr_rls();}
|
||||
}
|
||||
public boolean Lc(Scrib_proc_args args, Scrib_proc_rslt rslt) {return Case_all(args, rslt, Bool_.N);}
|
||||
public boolean Uc(Scrib_proc_args args, Scrib_proc_rslt rslt) {return Case_all(args, rslt, Bool_.Y);}
|
||||
@@ -187,7 +189,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
Pft_fmt_itm[] fmt_ary = Pft_fmt_itm_.Parse(core.Ctx(), fmt_bry);
|
||||
DateAdp date = null;
|
||||
if (Bry_.Len_eq_0(date_bry))
|
||||
date = DateAdp_.Now();
|
||||
date = Datetime_now.Get();
|
||||
else {
|
||||
if (date_bry[0] == Byte_ascii.Plus) { // detect wikidata-style dates; EX: +00000002010-05-01T00:00:00Z; PAGE:en.w:Mountain_Province; DATE:2015-07-29
|
||||
int date_bry_len = date_bry.length;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class Scrib_lib_language_tst {
|
||||
}
|
||||
@Test public void FormatDate() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "2013-03-17", false), "2013-03-17");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d"), DateAdp_.Now().XtoStr_fmt_yyyy_MM_dd()); // empty date should default to today;
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d"), Datetime_now.Get().XtoStr_fmt_yyyy_MM_dd()); // empty date should default to today;
|
||||
}
|
||||
@Test public void FormatDate__ymd_12() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "201603160102", false), "2016-03-16"); // handle long numeric date (12 digits); PAGE:en.w:Boron; DATE:2015-07-29
|
||||
@@ -82,11 +82,11 @@ public class Scrib_lib_language_tst {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "+00000002010-05-01T00:00:00Z", false), "2010-05-01"); // handle Wikidata style dates; PAGE:en.w:Mountain_Province; DATE:2015-07-29
|
||||
}
|
||||
@Test public void FormatDate_date_omitted() { // PURPOSE: some calls skip the date; retrieve arg_4 by int; EX: pl.w:L._Frank_Baum
|
||||
Tfds.Now_enabled_y_();
|
||||
Tfds.Now_set(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
|
||||
Datetime_now.Manual_y_();
|
||||
Datetime_now.Manual_(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Keyval_.Ary(Keyval_.int_(1, "en"), Keyval_.int_(2, "Y-m-d"), Keyval_.int_(4, false)), "2013-12-19");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", ""), "2013-12-19");// PURPOSE: '' should return today, not fail; EX: th.w:สถานีรถไฟตรัง
|
||||
Tfds.Now_enabled_n_();
|
||||
Datetime_now.Manual_n_();
|
||||
}
|
||||
@Test public void Lc() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_lc, Object_.Ary("en", "ABC"), "abc");
|
||||
|
||||
@@ -268,7 +268,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
bfr.Mkr_rls();
|
||||
return rslt.Init_obj(bfr.To_str_and_clear());
|
||||
}
|
||||
private Keyval[] CallParserFunction_parse_args(Number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, Keyval[] args) {
|
||||
private Keyval[] CallParserFunction_parse_args(Gfo_number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, Keyval[] args) {
|
||||
List_adp rv = List_adp_.New();
|
||||
// flatten args
|
||||
int args_len = args.length;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
@@ -35,6 +35,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
case Proc_getLabel: return GetLabel(args, rslt);
|
||||
case Proc_getEntity: return GetEntity(args, rslt);
|
||||
case Proc_getSetting: return GetSetting(args, rslt);
|
||||
case Proc_getEntityUrl: return GetEntityUrl(args, rslt);
|
||||
case Proc_renderSnak: return RenderSnak(args, rslt);
|
||||
case Proc_renderSnaks: return RenderSnaks(args, rslt);
|
||||
case Proc_getEntityId: return GetEntityId(args, rslt);
|
||||
@@ -43,26 +44,42 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
case Proc_resolvePropertyId: return ResolvePropertyId(args, rslt);
|
||||
case Proc_getSiteLinkPageName: return GetSiteLinkPageName(args, rslt);
|
||||
case Proc_incrementExpensiveFunctionCount: return IncrementExpensiveFunctionCount(args, rslt);
|
||||
case Proc_getPropertyOrder: return GetPropertyOrder(args, rslt);
|
||||
case Proc_orderProperties: return OrderProperties(args, rslt);
|
||||
default: throw Err_.new_unhandled(key);
|
||||
}
|
||||
}
|
||||
private static final int Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_renderSnak = 3, Proc_renderSnaks = 4, Proc_getEntityId = 5, Proc_getUserLang = 6, Proc_getDescription = 7, Proc_resolvePropertyId = 8, Proc_getSiteLinkPageName = 9, Proc_incrementExpensiveFunctionCount = 10;
|
||||
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount);
|
||||
private static final int
|
||||
Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_getEntityUrl = 3, Proc_renderSnak = 4, Proc_renderSnaks = 5, Proc_getEntityId = 6, Proc_getUserLang = 7
|
||||
, Proc_getDescription = 8, Proc_resolvePropertyId = 9, Proc_getSiteLinkPageName = 10, Proc_incrementExpensiveFunctionCount = 11, Proc_getPropertyOrder = 12, Proc_orderProperties = 13;
|
||||
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_getEntityUrl = "getEntityUrl"
|
||||
, Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang"
|
||||
, Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount"
|
||||
, Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
||||
;
|
||||
private static final String[] Proc_names = String_.Ary
|
||||
( Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_getEntityUrl, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang
|
||||
, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount, Invk_getPropertyOrder, Invk_orderProperties
|
||||
);
|
||||
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);}
|
||||
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean GetEntity(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty(); // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry);
|
||||
return wdoc == null ? rslt.Init_ary_empty() : rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
||||
}
|
||||
public boolean GetEntityUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getEntityUrl not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String rv = Wdata_prop_val_visitor_.Render_snak(core.Wiki(), core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
public boolean RenderSnaks(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String rv = Wdata_prop_val_visitor_.Render_snaks(core.Wiki(), core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "renderSnak not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean RenderSnaks(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "renderSnaks not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean GetEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
@@ -74,18 +91,15 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
return rslt.Init_obj(core.App().Usere().Lang().Key_bry());
|
||||
}
|
||||
public boolean GetDescription(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Descr_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean ResolvePropertyId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] prop = args.Pull_bry(0); if (Bry_.Len_eq_0(prop)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(prop); if (wdoc == null) return rslt.Init_ary_empty(); // 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); 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
|
||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean GetSiteLinkPageName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); 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
|
||||
Xow_domain_itm domain_itm = core.Wiki().Domain_itm();
|
||||
return rslt.Init_obj(wdoc.Slink_list__get_or_fallback(domain_itm.Abrv_wm()));
|
||||
}
|
||||
@@ -93,10 +107,15 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
||||
}
|
||||
private Wdata_doc Get_wdoc(byte[] xid_bry) {
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Wdata_doc wdoc = wiki.Appe().Wiki_mgr().Wdata_mgr().Doc_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
||||
private static Wdata_doc Get_wdoc_or_null(Scrib_proc_args args, Scrib_core core) {
|
||||
// get qid / pid from scrib_arg[0]; if none, return null;
|
||||
byte[] xid_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(xid_bry)) return null; // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||
|
||||
// get wdoc
|
||||
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Doc_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
||||
if (wdoc == null) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), xid_bry);
|
||||
return wdoc;
|
||||
}
|
||||
public boolean GetPropertyOrder(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getPropertyOrder not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean OrderProperties(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "orderProperties not implemented", "url", core.Page().Url().To_str());}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ 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.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.core.*;
|
||||
import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
public Scrib_lib_wikibase_entity(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
@@ -42,7 +43,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
||||
}
|
||||
public boolean FormatPropertyValues(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
public boolean FormatPropertyValues(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] qid = args.Pull_bry(0);
|
||||
byte[] pid = args.Pull_bry(1);
|
||||
Xoae_app app = core.App(); Xowe_wiki wiki = core.Wiki();
|
||||
@@ -52,7 +53,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
int pid_int = Wbase_pid_mgr.To_int_or_null(pid); // parse as num; EX: p123 -> 123; PAGE:hr.w:Hepatitis DATE:2015-11-08
|
||||
if (pid_int == Wdata_wiki_mgr.Pid_null) pid_int = wdata_mgr.Pid_mgr.Get_or_null(lang, pid); // parse as name; EX: name > 123
|
||||
if (pid_int == Wdata_wiki_mgr.Pid_null) return rslt.Init_str_empty();
|
||||
Wdata_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty();
|
||||
Wbase_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang);
|
||||
return rslt.Init_obj(bfr.To_bry_and_rls());
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.xtns.wbases.*;
|
||||
public class Scrib_lib_wikibase_entity_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear_for_lib();
|
||||
@@ -28,7 +28,7 @@ public class Scrib_lib_wikibase_entity_tst {
|
||||
}
|
||||
@Test public void FormatPropertyValues() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_str(3, "P3_val")).Xto_wdoc());
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_string(3, "P3_val")).Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3") , "P3_val"); // lookup by id
|
||||
wdata_fxt.Init_pids_add("en", "P3_val", 3);
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3_val") , "P3_val"); // lookup by name
|
||||
|
||||
@@ -16,14 +16,14 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.xowa.xtns.wbases.*; 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.*;
|
||||
class Scrib_lib_wikibase_srl {
|
||||
public static Keyval[] Srl(Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
|
||||
int base_adj = legacy_style ? 0 : 1;
|
||||
List_adp rv = List_adp_.New();
|
||||
if (header_enabled) {
|
||||
rv.Add(Keyval_.new_("id", wdoc.Qid()));
|
||||
rv.Add(Keyval_.new_("type", Wdata_dict_value_entity_tid.Str_item));
|
||||
rv.Add(Keyval_.new_("type", Wbase_claim_entity_type_.Itm__item.Key_str()));
|
||||
rv.Add(Keyval_.new_("schemaVersion", base_adj + 1)); // NOTE: needed by mw.wikibase.lua
|
||||
}
|
||||
Srl_root(rv, Wdata_doc_parser_v2.Str_labels , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Label_list()));
|
||||
@@ -94,7 +94,7 @@ class Scrib_lib_wikibase_srl {
|
||||
int rv_len = legacy_style ? len * 2 : len; // NOTE: legacyStyle returns 2 sets of properties: official "P" and legacy "p"; DATE:2014-05-11
|
||||
Keyval[] rv = new Keyval[rv_len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wdata_claim_grp grp = (Wdata_claim_grp)claim_grps.Get_at(i);
|
||||
Wbase_claim_grp grp = (Wbase_claim_grp)claim_grps.Get_at(i);
|
||||
String pid_str = Int_.To_str(grp.Id());
|
||||
Keyval[] grp_val = Srl_claims_prop_grp(visitor, "P" + pid_str, grp, base_adj);
|
||||
rv[i] = Keyval_.new_("P" + pid_str, grp_val);
|
||||
@@ -103,57 +103,57 @@ class Scrib_lib_wikibase_srl {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_grp(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wdata_claim_grp grp, int base_adj) {
|
||||
private static Keyval[] Srl_claims_prop_grp(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wbase_claim_grp grp, int base_adj) {
|
||||
int len = grp.Len();
|
||||
Keyval[] rv = new Keyval[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wdata_claim_itm_core itm = grp.Get_at(i);
|
||||
Wbase_claim_base itm = grp.Get_at(i);
|
||||
rv[i] = Keyval_.int_(i + base_adj, Srl_claims_prop_itm(visitor, pid, itm, base_adj)); // NOTE: must be super 0 or super 1; DATE:2014-05-09
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_itm(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wdata_claim_itm_core itm, int base_adj) {
|
||||
private static Keyval[] Srl_claims_prop_itm(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wbase_claim_base itm, int base_adj) {
|
||||
List_adp list = List_adp_.New();
|
||||
list.Add(Keyval_.new_("id", pid));
|
||||
list.Add(Keyval_.new_("mainsnak", Srl_claims_prop_itm_core(visitor, pid, itm)));
|
||||
list.Add(Keyval_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid())));
|
||||
list.Add(Keyval_.new_(Wdata_dict_claim_v1.Str_rank, Wbase_claim_rank_.To_str_or_fail(itm.Rank_tid())));
|
||||
list.Add(Keyval_.new_("type", itm.Prop_type()));
|
||||
Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(visitor, itm.Qualifiers(), base_adj));
|
||||
return (Keyval[])list.To_ary_and_clear(Keyval.class);
|
||||
}
|
||||
private static Keyval[] Srl_qualifiers(Scrib_lib_wikibase_srl_visitor visitor, Wdata_claim_grp_list list, int base_adj) {
|
||||
private static Keyval[] Srl_qualifiers(Scrib_lib_wikibase_srl_visitor visitor, Wbase_claim_grp_list list, int base_adj) {
|
||||
if (list == null) return null;
|
||||
int list_len = list.Len(); if (list_len == 0) return Keyval_.Ary_empty;
|
||||
List_adp rv = List_adp_.New();
|
||||
List_adp pid_list = List_adp_.New();
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Wdata_claim_grp grp = list.Get_at(i);
|
||||
Wbase_claim_grp grp = list.Get_at(i);
|
||||
int grp_len = grp.Len();
|
||||
pid_list.Clear();
|
||||
String itm_pid = grp.Id_str();
|
||||
for (int j = 0; j < grp_len; ++j) {
|
||||
Wdata_claim_itm_core itm = grp.Get_at(j);
|
||||
Wbase_claim_base itm = grp.Get_at(j);
|
||||
pid_list.Add(Keyval_.int_(j + base_adj, Srl_claims_prop_itm_core(visitor, itm_pid, itm))); // NOTE: was originally "+ 1"; changed to base_adj; PAGE:ru.w:Tor ru.w:Кактусовые DATE:2014-10-25
|
||||
}
|
||||
rv.Add(Keyval_.new_(itm_pid, (Keyval[])pid_list.To_ary_and_clear(Keyval.class)));
|
||||
}
|
||||
return (Keyval[])rv.To_ary_and_clear(Keyval.class);
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_itm_core(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wdata_claim_itm_core itm) {
|
||||
boolean snak_is_valued = itm.Snak_tid() == Wdata_dict_snak_tid.Tid_value; // PURPOSE: was != Wdata_dict_snak_tid.Tid_novalue; PAGE:it.s:Autore:Anonimo DATE:2015-12-06
|
||||
private static Keyval[] Srl_claims_prop_itm_core(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wbase_claim_base itm) {
|
||||
boolean snak_is_valued = itm.Snak_tid() == Wbase_claim_value_type_.Tid__value; // PURPOSE: was != Wbase_claim_value_type_.Tid__novalue; PAGE:it.s:Autore:Anonimo DATE:2015-12-06
|
||||
int snak_is_valued_adj = snak_is_valued ? 1 : 0;
|
||||
Keyval[] rv = new Keyval[3 + snak_is_valued_adj];
|
||||
if (snak_is_valued) // NOTE: novalue must not return slot (no datavalue node in json); PAGE:ru.w:Лимонов,_Эдуард_Вениаминович; DATE:2015-02-16; ALSO: sv.w:Joseph_Jaquet; DATE:2015-07-31
|
||||
rv[0] = Keyval_.new_("datavalue", Srl_claims_prop_itm_core_val(visitor, itm));
|
||||
rv[0 + snak_is_valued_adj] = Keyval_.new_("property", pid);
|
||||
rv[1 + snak_is_valued_adj] = Keyval_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid()));
|
||||
rv[2 + snak_is_valued_adj] = Keyval_.new_("datatype", Wdata_dict_val_tid.To_str__srl(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
|
||||
rv[1 + snak_is_valued_adj] = Keyval_.new_("snaktype", Wbase_claim_value_type_.To_str_or_fail(itm.Snak_tid()));
|
||||
rv[2 + snak_is_valued_adj] = Keyval_.new_("datatype", Wbase_claim_type_.To_scrib_or_unknown(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_itm_core_val(Scrib_lib_wikibase_srl_visitor visitor, Wdata_claim_itm_core itm) {
|
||||
private static Keyval[] Srl_claims_prop_itm_core_val(Scrib_lib_wikibase_srl_visitor visitor, Wbase_claim_base itm) {
|
||||
switch (itm.Snak_tid()) {
|
||||
case Wdata_dict_snak_tid.Tid_somevalue: return Datavalue_somevalue;
|
||||
case Wdata_dict_snak_tid.Tid_novalue: return Datavalue_novalue; // TODO_OLD: throw exc
|
||||
case Wbase_claim_value_type_.Tid__somevalue: return Datavalue_somevalue;
|
||||
case Wbase_claim_value_type_.Tid__novalue: return Datavalue_novalue; // TODO_OLD: throw exc
|
||||
default:
|
||||
itm.Welcome(visitor);
|
||||
return visitor.Rv();
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; 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 Scrib_lib_wikibase_srl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Scrib_lib_wikibase_srl_fxt fxt = new Scrib_lib_wikibase_srl_fxt();
|
||||
@Test public void Label() {
|
||||
@@ -126,7 +126,7 @@ public class Scrib_lib_wikibase_srl_tst {
|
||||
);
|
||||
}
|
||||
@Test public void Claims_str() {
|
||||
fxt.Init_prop(fxt.Wdata_fxt().Make_claim_str(2, "Moon"));
|
||||
fxt.Init_prop(fxt.Wdata_fxt().Make_claim_string(2, "Moon"));
|
||||
fxt.Test
|
||||
( "claims:"
|
||||
, " P2:"
|
||||
@@ -327,7 +327,7 @@ public class Scrib_lib_wikibase_srl_tst {
|
||||
}
|
||||
@Test public void Qualifiers() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = fxt.Wdata_fxt();
|
||||
fxt.Init_prop(wdata_fxt.Make_claim_str(2, "Earth").Qualifiers_(wdata_fxt.Make_qualifiers(wdata_fxt.Make_qualifiers_grp(3, wdata_fxt.Make_claim_time(3, "2001-02-03 04:05:06")))));
|
||||
fxt.Init_prop(wdata_fxt.Make_claim_string(2, "Earth").Qualifiers_(wdata_fxt.Make_qualifiers(wdata_fxt.Make_qualifiers_grp(3, wdata_fxt.Make_claim_time(3, "2001-02-03 04:05:06")))));
|
||||
fxt.Test
|
||||
( "claims:"
|
||||
, " P2:"
|
||||
@@ -388,7 +388,7 @@ class Scrib_lib_wikibase_srl_fxt {
|
||||
wdoc_bldr.Add_alias(lang, ary);
|
||||
return this;
|
||||
}
|
||||
public Scrib_lib_wikibase_srl_fxt Init_prop(Wdata_claim_itm_core prop) {wdoc_bldr.Add_claims(prop); return this;}
|
||||
public Scrib_lib_wikibase_srl_fxt Init_prop(Wbase_claim_base prop) {wdoc_bldr.Add_claims(prop); return this;}
|
||||
public Scrib_lib_wikibase_srl_fxt Test(String... expd) {return Test(false, expd);}
|
||||
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, String... expd) {
|
||||
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(wdoc_bldr.Xto_wdoc(), header_enabled, base0);
|
||||
|
||||
@@ -16,80 +16,80 @@ 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.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.wdatas.core.*;
|
||||
class Scrib_lib_wikibase_srl_visitor implements Wdata_claim_visitor {
|
||||
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 Scrib_lib_wikibase_srl_visitor implements Wbase_claim_visitor {
|
||||
public Keyval[] Rv() {return rv;} Keyval[] rv;
|
||||
public void Visit_str(Wdata_claim_itm_str itm) {
|
||||
public void Visit_str(Wbase_claim_string itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Xto_str(itm.Val_tid()));
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.To_key_or_unknown(itm.Val_tid()));
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, String_.new_u8(itm.Val_str()));
|
||||
}
|
||||
public void Visit_entity(Wdata_claim_itm_entity itm) {
|
||||
public void Visit_entity(Wbase_claim_entity itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_entity);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__entity.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Entity_value(itm));
|
||||
}
|
||||
private static Keyval[] Entity_value(Wdata_claim_itm_core itm) {
|
||||
Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)itm;
|
||||
private static Keyval[] Entity_value(Wbase_claim_base itm) {
|
||||
Wbase_claim_entity claim_entity = (Wbase_claim_entity)itm;
|
||||
Keyval[] rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_entity.Str_entity_type, claim_entity.Entity_tid_str());
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.To_str(claim_entity.Entity_id()));
|
||||
rv[0] = Keyval_.new_(Wbase_claim_entity_.Itm__entity_type.Key_str(), claim_entity.Entity_tid_str());
|
||||
rv[1] = Keyval_.new_(Wbase_claim_entity_.Itm__numeric_id.Key_str(), Int_.To_str(claim_entity.Entity_id()));
|
||||
return rv;
|
||||
}
|
||||
public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {
|
||||
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_monolingualtext);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__monolingualtext.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm));
|
||||
}
|
||||
private static Keyval[] Monolingualtext_value(Wdata_claim_itm_monolingualtext itm) {
|
||||
private static Keyval[] Monolingualtext_value(Wbase_claim_monolingualtext itm) {
|
||||
Keyval[] rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_u8(itm.Text()));
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_u8(itm.Lang()));
|
||||
rv[0] = Keyval_.new_(Wbase_claim_monolingualtext_.Itm__text.Key_str() , String_.new_u8(itm.Text()));
|
||||
rv[1] = Keyval_.new_(Wbase_claim_monolingualtext_.Itm__language.Key_str() , String_.new_u8(itm.Lang()));
|
||||
return rv;
|
||||
}
|
||||
public void Visit_quantity(Wdata_claim_itm_quantity itm) {
|
||||
public void Visit_quantity(Wbase_claim_quantity itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_quantity);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__quantity.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Quantity_value(itm));
|
||||
}
|
||||
private static Keyval[] Quantity_value(Wdata_claim_itm_quantity itm) {
|
||||
private static Keyval[] Quantity_value(Wbase_claim_quantity itm) {
|
||||
Keyval[] rv = new Keyval[4];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_quantity.Str_amount , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_u8(itm.Unit()));
|
||||
rv[2] = Keyval_.new_(Wdata_dict_value_quantity.Str_upperbound , itm.Ubound_as_num().To_str());
|
||||
rv[3] = Keyval_.new_(Wdata_dict_value_quantity.Str_lowerbound , itm.Lbound_as_num().To_str());
|
||||
rv[0] = Keyval_.new_(Wbase_claim_quantity_.Itm__amount.Key_str() , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
|
||||
rv[1] = Keyval_.new_(Wbase_claim_quantity_.Itm__unit.Key_str() , String_.new_u8(itm.Unit()));
|
||||
rv[2] = Keyval_.new_(Wbase_claim_quantity_.Itm__upperbound.Key_str() , itm.Ubound_as_num().To_str());
|
||||
rv[3] = Keyval_.new_(Wbase_claim_quantity_.Itm__lowerbound.Key_str() , itm.Lbound_as_num().To_str());
|
||||
return rv;
|
||||
}
|
||||
public void Visit_time(Wdata_claim_itm_time itm) {
|
||||
public void Visit_time(Wbase_claim_time itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_time);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__time.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Time_value(itm));
|
||||
}
|
||||
private static Keyval[] Time_value(Wdata_claim_itm_time itm) {
|
||||
private static Keyval[] Time_value(Wbase_claim_time itm) {
|
||||
Keyval[] rv = new Keyval[6];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_time.Str_time , String_.new_a7(itm.Time()));
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_time.Str_precision , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
|
||||
rv[2] = Keyval_.new_(Wdata_dict_value_time.Str_before , itm.Before_int());
|
||||
rv[3] = Keyval_.new_(Wdata_dict_value_time.Str_after , itm.After_int());
|
||||
rv[4] = Keyval_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
|
||||
rv[5] = Keyval_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str);
|
||||
rv[0] = Keyval_.new_(Wbase_claim_time_.Itm__time.Key_str() , String_.new_a7(itm.Time()));
|
||||
rv[1] = Keyval_.new_(Wbase_claim_time_.Itm__precision.Key_str() , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
|
||||
rv[2] = Keyval_.new_(Wbase_claim_time_.Itm__before.Key_str() , itm.Before_int());
|
||||
rv[3] = Keyval_.new_(Wbase_claim_time_.Itm__after.Key_str() , itm.After_int());
|
||||
rv[4] = Keyval_.new_(Wbase_claim_time_.Itm__timezone.Key_str() , Wbase_claim_time_.Dflt__timezone.Val_str()); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
|
||||
rv[5] = Keyval_.new_(Wbase_claim_time_.Itm__calendarmodel.Key_str() , Wbase_claim_time_.Dflt__calendarmodel.Val_str());
|
||||
return rv;
|
||||
}
|
||||
public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) {
|
||||
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_globecoordinate);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__globecoordinate.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Globecoordinate_value(itm));
|
||||
}
|
||||
private static Keyval[] Globecoordinate_value(Wdata_claim_itm_globecoordinate itm) {
|
||||
private static Keyval[] Globecoordinate_value(Wbase_claim_globecoordinate itm) {
|
||||
Keyval[] rv = new Keyval[5];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse(String_.new_a7(itm.Lat())));
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse(String_.new_a7(itm.Lng())));
|
||||
rv[2] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_altitude , String_.new_u8(itm.Alt()));
|
||||
rv[3] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_globe , String_.new_u8(itm.Glb()));
|
||||
rv[4] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_precision , itm.Prc_as_num().To_double());
|
||||
rv[0] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__latitude.Key_str() , Double_.parse(String_.new_a7(itm.Lat())));
|
||||
rv[1] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__longitude.Key_str() , Double_.parse(String_.new_a7(itm.Lng())));
|
||||
rv[2] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__altitude.Key_str() , String_.new_u8(itm.Alt()));
|
||||
rv[3] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__globe.Key_str() , String_.new_u8(itm.Glb()));
|
||||
rv[4] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__precision.Key_str() , itm.Prc_as_num().To_double());
|
||||
return rv;
|
||||
}
|
||||
public void Visit_system(Wdata_claim_itm_system itm) {
|
||||
public void Visit_system(Wbase_claim_value itm) {
|
||||
rv = Keyval_.Ary_empty;
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
import org.junit.*; 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 Scrib_lib_wikibase_tst {
|
||||
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
|
||||
@@ -89,4 +88,58 @@ public class Scrib_lib_wikibase_tst {
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("zh-hans", "prop_a").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_resolvePropertyId, Object_.Ary("p2"), "prop_a");
|
||||
}
|
||||
}
|
||||
@Test public void RenderSnaks() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snaks_ary(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "P3_en"), wdata_fxt.Make_claim_monolingual(3, "de", "P3_de"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnaks, args, "P3_en, P3_de");
|
||||
}
|
||||
@Test public void RenderSnak__str() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_string(3, "test_str"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "test_str");
|
||||
}
|
||||
@Test public void RenderSnak__quantity() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_quantity(3, "123", "2", "125", "121"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "123±2");
|
||||
}
|
||||
@Test public void RenderSnak__time() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_time(3, "2012-01-02 03:04:05"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "30405 2 Jan 2012"); // NOTE: format is missing ":" b/c test does not init messages for html_wtr; DATE:2015-08-03
|
||||
}
|
||||
@Test public void RenderSnak__geo() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_geo(3, "3.4", "1.2"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "1.2, 3.4");
|
||||
}
|
||||
@Test public void RenderSnak__monolingual() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "abc_en"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "abc_en");
|
||||
}
|
||||
}
|
||||
class Wbase_snak_utl_ {
|
||||
public static Keyval[] Get_snaks_ary(Wdata_wiki_mgr_fxt wdata_fxt, Wbase_claim_base... ary) {
|
||||
Wdata_doc wdoc = wdata_fxt.Wdoc_bldr("q2").Add_claims(ary).Xto_wdoc();
|
||||
return Keyval_.Ary(Keyval_.int_(1, Get_snaks(wdoc)));
|
||||
}
|
||||
public static Keyval[] Get_snak(Wdata_wiki_mgr_fxt wdata_fxt, Wbase_claim_base itm) {
|
||||
Wdata_doc wdoc = wdata_fxt.Wdoc_bldr("q2").Add_claims(itm).Xto_wdoc();
|
||||
Keyval[] snak_props = Get_subs_by_path(Get_snaks(wdoc), 0);
|
||||
return Keyval_.Ary(Keyval_.int_(1, snak_props));
|
||||
}
|
||||
private static Keyval[] Get_snaks(Wdata_doc wdoc) {
|
||||
Keyval[] wdoc_root = Scrib_lib_wikibase_srl.Srl(wdoc, false, false);
|
||||
Keyval[] snaks = Get_subs_by_path(wdoc_root, 0, 0);
|
||||
int snaks_len = snaks.length;
|
||||
Keyval[] rv = new Keyval[snaks_len];
|
||||
for (int i = 0; i < snaks_len; ++i) {
|
||||
rv[i] = Keyval_.int_(i + List_adp_.Base1, Get_subs_by_path(snaks, i, 1));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Get_subs_by_path(Keyval[] root, int... levels) {
|
||||
int len = levels.length;
|
||||
Keyval[] rv = root;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int idx = levels[i];
|
||||
rv = (Keyval[])rv[idx].Val();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.regxs.*;
|
||||
public class Scrib_regx_converter {
|
||||
private List_adp capt_list = List_adp_.New(), grps_parens = List_adp_.New(); private List_adp grps_open = List_adp_.New();
|
||||
private final List_adp capt_list = List_adp_.New(), grps_parens = List_adp_.New(); private final List_adp grps_open = List_adp_.New();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public Scrib_regx_converter() {Init();}
|
||||
public String Regx() {return regx;} private String regx;
|
||||
public List_adp Capt_list() {return capt_list;}
|
||||
@@ -100,9 +101,8 @@ public class Scrib_regx_converter {
|
||||
++i;
|
||||
if (i + 1 >= len || src[i] != Byte_ascii.Brack_bgn) throw Err_.new_("scribunto", "missing '[' after %f in pattern at pattern character $ii");
|
||||
// %f always followed by bracketed term; convert lua bracketed term to regex
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
i = bracketedCharSetToRegex(tmp_bfr, src, i, len);
|
||||
byte[] bracketed_regx = tmp_bfr.To_bry_and_rls();
|
||||
byte[] bracketed_regx = tmp_bfr.To_bry_and_clear();
|
||||
|
||||
// scrib has following comment: 'Because %f considers the beginning and end of the String to be \0, determine if $re2 matches that and take it into account with "^" and "$".'
|
||||
// if the bracketed_regx is a negative class it will match \0; so, \W means anything not a word char, which will match \0; \w means word char which will not match \0
|
||||
|
||||
Reference in New Issue
Block a user