diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity.java b/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity.java index d8a9fdccd..14e2675ad 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity.java @@ -32,27 +32,52 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib { public boolean Procs_exec(int key, Scrib_proc_args args, Scrib_proc_rslt rslt) { switch (key) { case Proc_getGlobalSiteId: return GetGlobalSiteId(args, rslt); + case Proc_getLanguageCode: return GetLanguageCode(args, rslt); +// case Proc_formatStatements: return FormatStatements(args, rslt); case Proc_formatPropertyValues: return FormatPropertyValues(args, rslt); default: throw Err_.new_unhandled(key); } } - private static final int Proc_getGlobalSiteId = 0, Proc_formatPropertyValues = 1; - public static final String Invk_getGlobalSiteId = "getGlobalSiteId", Invk_formatPropertyValues = "formatPropertyValues"; - private static final String[] Proc_names = String_.Ary(Invk_getGlobalSiteId, Invk_formatPropertyValues); + private static final int Proc_getGlobalSiteId = 0, Proc_getLanguageCode = 1, Proc_formatPropertyValues = 2; + public static final String Invk_getGlobalSiteId = "getGlobalSiteId", Invk_getLanguageCode = "getLanguageCode", Invk_formatPropertyValues = "formatPropertyValues"; + private static final String[] Proc_names = String_.Ary(Invk_getGlobalSiteId, Invk_getLanguageCode, Invk_formatPropertyValues); 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. 'itwiki'), as used in the sites table. Default: $wgDBname.; REF:/xtns/Wikibase/docs/options.wiki } + public boolean GetLanguageCode(Scrib_proc_args args, Scrib_proc_rslt rslt) { + return rslt.Init_obj(core.Wiki().Lang().Key_bry()); + } +// public boolean FormatStatements(Scrib_proc_args args, Scrib_proc_rslt rslt) { +// return FormatPropertyValues(args, rslt); // NOTE: implementation should be like Visit_entity but return [[A]] instead of +// } public boolean FormatPropertyValues(Scrib_proc_args args, Scrib_proc_rslt rslt) { + // get qid / pid byte[] qid = args.Pull_bry(0); byte[] pid = args.Pull_bry(1); + + // get wdata_mgr and lang Xoae_app app = core.App(); Xowe_wiki wiki = core.Wiki(); Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr(); byte[] lang = wiki.Wdata_wiki_lang(); - Wdata_doc wdoc = wdata_mgr.Doc_mgr.Get_by_bry_or_null(qid); if (wdoc == null) {Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), qid); return rslt.Init_str_empty();} // NOTE: return empty String, not nil; PAGE:fr.s:Henri_Bergson; DATE:2014-08-13 + + // get wdoc + Wdata_doc wdoc = wdata_mgr.Doc_mgr.Get_by_bry_or_null(qid); + if (wdoc == null) { + Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), qid); + return rslt.Init_str_empty(); // NOTE: return empty String, not nil; PAGE:fr.s:Henri_Bergson; DATE:2014-08-13 + } + + // get pid_int 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(); - Wbase_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty(); + + // get prop_grp + Wbase_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); + if (prop_grp == null) + return rslt.Init_str_empty(); + + // print it 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()); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity_tst.java b/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity_tst.java index a68f8f7bc..ebcd2cd31 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/libs/Scrib_lib_wikibase_entity_tst.java @@ -24,12 +24,19 @@ public class Scrib_lib_wikibase_entity_tst { @Test public void GetGlobalSiteId() { fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_getGlobalSiteId, Object_.Ary_empty, "enwiki"); } + @Test public void GetLanguageCode() { + fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_getLanguageCode, Object_.Ary_empty, "en"); + } @Test public void FormatPropertyValues() { Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false); + + // lookup by id 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 + fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3") , "P3_val"); + + // lookup by name 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 + fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3_val") , "P3_val"); } @Test public void FormatPropertyValues__not_found() { // PURPOSE: should return "" not null; PAGE:fr.s:Auteur:Henri_Bergson; DATE:2014-08-13 fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3"), ""); diff --git a/gplx.gflucene/src/gplx/gflucene/core/Gflucene_index_data.java b/gplx.gflucene/src/gplx/gflucene/core/Gflucene_index_data.java index 925e2c8a4..1170ad764 100644 --- a/gplx.gflucene/src/gplx/gflucene/core/Gflucene_index_data.java +++ b/gplx.gflucene/src/gplx/gflucene/core/Gflucene_index_data.java @@ -18,7 +18,7 @@ import gplx.gflucene.analyzers.*; public class Gflucene_index_data { public final Gflucene_analyzer_data analyzer_data; public final String index_dir; - public final float max_merged_segments = 500; // "limits" maximum file size approximately; limiting to 500 MB should limit file size to around 1 GB + public final float max_merged_segments = 1500; // "limits" maximum file size public Gflucene_index_data(Gflucene_analyzer_data analyzer_data, String index_dir) { this.analyzer_data = analyzer_data; this.index_dir = index_dir;