diff --git a/100_core/src_110_primitive/gplx/Bry_.java b/100_core/src_110_primitive/gplx/Bry_.java index 19726494a..912dd9441 100644 --- a/100_core/src_110_primitive/gplx/Bry_.java +++ b/100_core/src_110_primitive/gplx/Bry_.java @@ -208,6 +208,32 @@ public class Bry_ { if (b == find) src[i] = repl; } } + public static byte[] Add_w_dlm(byte[] dlm, byte[]... ary) { + int ary_len = ary.length; + if (ary_len == 0) return Bry_.Empty; + int dlm_len = dlm.length; + int rv_len = dlm_len * (ary_len - 1); // rv will have at least as many dlms as itms - 1 + for (int i = 0; i < ary_len; i++) { + byte[] itm = ary[i]; + if (itm != null) rv_len += itm.length; + } + int rv_pos = 0; + byte[] rv = new byte[rv_len]; + for (int i = 0; i < ary_len; i++) { + byte[] itm = ary[i]; + if (i != 0) { + for (int j = 0; j < dlm_len; j++) { + rv[rv_pos++] = dlm[j]; + } + } + if (itm == null) continue; + int itm_len = itm.length; + for (int j = 0; j < itm_len; j++) { + rv[rv_pos++] = itm[j]; + } + } + return rv; + } public static byte[] Add_w_dlm(byte dlm, byte[]... ary) { int ary_len = ary.length; if (ary_len == 0) return Bry_.Empty; diff --git a/100_core/src_110_primitive/gplx/Bry__tst.java b/100_core/src_110_primitive/gplx/Bry__tst.java index a899c7a83..0657c6a24 100644 --- a/100_core/src_110_primitive/gplx/Bry__tst.java +++ b/100_core/src_110_primitive/gplx/Bry__tst.java @@ -228,15 +228,6 @@ public class Bry__tst { rv[i] = String_.new_utf8_(lines[i]); return rv; } - @Test public void Add_w_dlm() { - Tst_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic - Tst_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item - Tst_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null - } - void Tst_add_w_dlm(byte dlm, String[] itms, String expd) { - byte[] actl = Bry_.Add_w_dlm(dlm, Bry_.Ary(itms)); - Tfds.Eq(expd, String_.new_ascii_(actl)); - } @Test public void Match_bwd_any() { Tst_match_bwd_any("abc", 2, 0, "c", true); Tst_match_bwd_any("abc", 2, 0, "b", false); @@ -268,6 +259,14 @@ public class Bry__tst { fxt.Test_new_utf8_("€" , Bry_.ints_(226, 130, 172)); // bry_len=3; euro fxt.Test_new_utf8_("𤭢" , Bry_.ints_(240, 164, 173, 162)); // bry_len=3; example from en.w:UTF-8 } + @Test public void Add_w_dlm() { + fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", "b", "c") , "a|b|c"); // basic + fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a") , "a"); // one item + fxt.Test_add_w_dlm(Byte_ascii.Pipe, String_.Ary("a", null, "c") , "a||c"); // null + } + @Test public void Add_w_dlm_bry() { + fxt.Test_add_w_dlm("<>", String_.Ary("a","b","c"), "a<>b<>c"); + } } class Bry__fxt { public void Test_trim_end(String raw, byte trim, String expd) { @@ -276,4 +275,6 @@ class Bry__fxt { } public void Test_new_utf8_(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_utf8_(raw));} public void Test_new_ascii_(String raw, byte[] expd) {Tfds.Eq_ary(expd, Bry_.new_ascii_(raw));} + public void Test_add_w_dlm(String dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_utf8_(Bry_.Add_w_dlm(Bry_.new_utf8_(dlm), Bry_.Ary(itms))));} + public void Test_add_w_dlm(byte dlm, String[] itms, String expd) {Tfds.Eq(expd, String_.new_utf8_(Bry_.Add_w_dlm(dlm, Bry_.Ary(itms))));} } diff --git a/100_core/src_110_primitive/gplx/Byte_ascii.java b/100_core/src_110_primitive/gplx/Byte_ascii.java index 8b3714fda..c7724dc7e 100644 --- a/100_core/src_110_primitive/gplx/Byte_ascii.java +++ b/100_core/src_110_primitive/gplx/Byte_ascii.java @@ -76,6 +76,7 @@ public class Byte_ascii { , Dot_bry = new byte[] {Byte_ascii.Dot} , Comma_bry = new byte[] {Byte_ascii.Comma} , Colon_bry = new byte[] {Byte_ascii.Colon} + , Amp_bry = new byte[] {Byte_ascii.Amp} , Lt_bry = new byte[] {Byte_ascii.Lt} , Gt_bry = new byte[] {Byte_ascii.Gt} , Brack_bgn_bry = new byte[] {Byte_ascii.Brack_bgn} diff --git a/100_core/src_200_io/gplx/Io_mgr.java b/100_core/src_200_io/gplx/Io_mgr.java index 32448f511..88b0f4acf 100644 --- a/100_core/src_200_io/gplx/Io_mgr.java +++ b/100_core/src_200_io/gplx/Io_mgr.java @@ -66,7 +66,6 @@ public class Io_mgr { // exists primarily to gather all cmds under gplx namespac } public void AliasDir_sysEngine(String srcRoot, String trgRoot) {AliasDir(srcRoot, trgRoot, IoEngine_.SysKey);} public void AliasDir(String srcRoot, String trgRoot, String engineKey) {IoUrlInfoRegy._.Reg(IoUrlInfo_.alias_(srcRoot, trgRoot, engineKey));} -// public IoStream OpenStreamRead2(Io_url url) {return IoEngine_xrg_openRead.new_(url).ExecAsIoStreamOrFail();} public IoStream OpenStreamRead(Io_url url) {return OpenStreamRead_args(url).ExecAsIoStreamOrFail();} public IoEngine_xrg_openRead OpenStreamRead_args(Io_url url) {return IoEngine_xrg_openRead.new_(url);} public String LoadFilStr(String url) {return LoadFilStr_args(Io_url_.new_fil_(url)).Exec();} diff --git a/400_xowa/src/gplx/html/Html_entity_.java b/400_xowa/src/gplx/html/Html_entity_.java index b3b883265..7a4df4f93 100644 --- a/400_xowa/src/gplx/html/Html_entity_.java +++ b/400_xowa/src/gplx/html/Html_entity_.java @@ -30,5 +30,6 @@ public class Html_entity_ { , Pipe_bry = Bry_.new_ascii_("|") , Colon_bry = Bry_.new_ascii_(":"), Underline_bry = Bry_.new_ascii_("_"), Asterisk_bry = Bry_.new_ascii_("*") , Brack_bgn_bry = Bry_.new_ascii_("["), Brack_end_bry = Bry_.new_ascii_("]") + , Nbsp_bry = Bry_.new_ascii_(" ") ; } diff --git a/400_xowa/src/gplx/html/Html_tag_.java b/400_xowa/src/gplx/html/Html_tag_.java index 5b416769a..5b8d7a7bb 100644 --- a/400_xowa/src/gplx/html/Html_tag_.java +++ b/400_xowa/src/gplx/html/Html_tag_.java @@ -20,6 +20,10 @@ public class Html_tag_ { public static final byte[] Ul_name_bry = Bry_.new_ascii_("ul") , A_name_bry = Bry_.new_ascii_("a") + , Code_name_bry = Bry_.new_ascii_("code") + , Tr_name_bry = Bry_.new_ascii_("tr") + , Td_name_bry = Bry_.new_ascii_("td") + , Table_name_bry = Bry_.new_ascii_("table") ; public static final byte[] Br_inl = Bry_.new_ascii_("
") diff --git a/400_xowa/src/gplx/xowa/Xoa_app_.java b/400_xowa/src/gplx/xowa/Xoa_app_.java index bda98ebd6..a1a77483e 100644 --- a/400_xowa/src/gplx/xowa/Xoa_app_.java +++ b/400_xowa/src/gplx/xowa/Xoa_app_.java @@ -24,7 +24,7 @@ public class Xoa_app_ { boot_mgr.Run(args); } public static final String Name = "xowa"; - public static final String Version = "1.9.4.1"; + public static final String Version = "1.9.5.1"; public static String Build_date = "2012-12-30 00:00:00"; public static String Op_sys; public static String User_agent = ""; diff --git a/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__html_entity_tst.java b/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__html_entity_tst.java index 5edfb0244..d4263b677 100644 --- a/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__html_entity_tst.java +++ b/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__html_entity_tst.java @@ -19,9 +19,10 @@ package gplx.xowa.apps.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa import org.junit.*; public class Xoa_ttl__html_entity_tst { @Before public void init() {fxt.Reset();} private Xoa_ttl_fxt fxt = new Xoa_ttl_fxt(); - @Test public void Eacute() {fxt.Init_ttl("é").Expd_page_txt("é").Test();} //É - @Test public void Amp_at_end() {fxt.Init_ttl("Bisc &").Expd_page_txt("Bisc &").Test();} - @Test public void Ncr_dec() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();} - @Test public void Ncr_hex() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();} - @Test public void Nbsp() {fxt.Init_ttl("A b").Expd_page_txt("A b").Test();} // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]] + @Test public void Eacute() {fxt.Init_ttl("é").Expd_page_txt("é").Test();} //É + @Test public void Amp_at_end() {fxt.Init_ttl("Bisc &").Expd_page_txt("Bisc &").Test();} + @Test public void Ncr_dec() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();} + @Test public void Ncr_hex() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();} + @Test public void Nbsp() {fxt.Init_ttl("A b").Expd_page_txt("A b").Test();} // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]] + @Test public void Amp() {fxt.Init_ttl("A&b").Expd_page_txt("A&b").Test();} // PURPOSE: A&B -> A&B; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23 } \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__ws_tst.java b/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__ws_tst.java index 79cfe1aaa..bd9ab164e 100644 --- a/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__ws_tst.java +++ b/400_xowa/src/gplx/xowa/apps/ttls/Xoa_ttl__ws_tst.java @@ -24,4 +24,6 @@ public class Xoa_ttl__ws_tst { @Test public void Nl() {fxt.Init_ttl("\n\na\n\n") .Expd_page_txt("A").Test();} @Test public void Nl_end() {fxt.Init_ttl("a\nb") .Expd_page_txt("A b").Test();} @Test public void Tab() {fxt.Init_ttl("\ta\t") .Expd_page_txt("A").Test();} + @Test public void Nbsp() {fxt.Init_ttl("A bc") .Expd_page_url("A_bc").Expd_page_txt("A bc").Test();} // PURPOSE:convert " " to " "; DATE:2014-09-25 + @Test public void Nbsp_mix() {fxt.Init_ttl("A   bc") .Expd_page_url("A_bc").Expd_page_txt("A bc").Test();} // PURPOSE:convert multiple " " to " "; PAGE:en.w:Greek_government-debt_crisis; DATE:2014-09-25 } diff --git a/400_xowa/src/gplx/xowa/ctgs/Xoctg_fmtr_grp.java b/400_xowa/src/gplx/xowa/ctgs/Xoctg_fmtr_grp.java index e52eacd5e..250934332 100644 --- a/400_xowa/src/gplx/xowa/ctgs/Xoctg_fmtr_grp.java +++ b/400_xowa/src/gplx/xowa/ctgs/Xoctg_fmtr_grp.java @@ -32,7 +32,7 @@ class Xoctg_fmtr_grp implements Bry_fmtr_arg { byte[] ttl_char_0_new = gplx.intl.Utf8_.Get_char_at_pos_as_bry(itm_sortkey, 0); byte[] grp_name = ttl_char_0_new; if (Bry_.Eq(ttl_char_0, ttl_char_0_new)) { - grp_name = Bry_.Add(ttl_char_0, Bry_space, wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_list_continues)); + grp_name = Bry_.Add(ttl_char_0, Byte_ascii.Space_bry, wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_list_continues)); } ttl_char_0 = ttl_char_0_new; if (col_bgn_needed) { @@ -79,5 +79,4 @@ class Xoctg_fmtr_grp implements Bry_fmtr_arg { int col_max = ((len - 1) / cols_total) + 1; // NOTE: example is easiest explanation; EX: 4, 5, 6 should have max of 2, so (a) subtract 1; (b) divide by 3; (c) add 1 return col_idx <= ((len - 1) % cols_total) ? col_max : col_max - 1; // NOTE: example is easiest explanation; EX: 4=2,1,1; 5=2,2,1; 6=2,2,2 } - private static final byte[] Bry_space = new byte[] {Byte_ascii.Space}; } diff --git a/400_xowa/src/gplx/xowa/gui/bnds/Xog_bnd_mgr.java b/400_xowa/src/gplx/xowa/gui/bnds/Xog_bnd_mgr.java index 57b9caf7a..7197bcbc1 100644 --- a/400_xowa/src/gplx/xowa/gui/bnds/Xog_bnd_mgr.java +++ b/400_xowa/src/gplx/xowa/gui/bnds/Xog_bnd_mgr.java @@ -123,7 +123,7 @@ public class Xog_bnd_mgr { Init_itm(Xog_cmd_itm_.Key_gui_page_view_mode_read , Xog_bnd_box_.Tid_browser , "mod.c+key.m,mod.c+key.r"); Init_itm(Xog_cmd_itm_.Key_gui_page_view_mode_edit , Xog_bnd_box_.Tid_browser , "mod.c+key.m,mod.c+key.e"); - Init_itm(Xog_cmd_itm_.Key_gui_page_view_mode_html , Xog_bnd_box_.Tid_browser , "mod.c+key.m,mod.c+key.h"); + Init_itm(Xog_cmd_itm_.Key_gui_page_view_mode_html , Xog_bnd_box_.Tid_browser , "mod.c+key.m,mod.c+key.h", "mod.c+key.u"); Init_itm(Xog_cmd_itm_.Key_gui_page_view_reload , Xog_bnd_box_.Tid_browser , "mod.s+key.f5"); Init_itm(Xog_cmd_itm_.Key_gui_page_view_refresh , Xog_bnd_box_.Tid_browser , "key.f5"); Init_itm(Xog_cmd_itm_.Key_gui_page_view_save_as , Xog_bnd_box_.Tid_browser , ""); diff --git a/400_xowa/src/gplx/xowa/gui/views/Xog_html_js_cbk_wdata_labels_tst.java b/400_xowa/src/gplx/xowa/gui/views/Xog_html_js_cbk_wdata_labels_tst.java index b13109582..51d1a0570 100644 --- a/400_xowa/src/gplx/xowa/gui/views/Xog_html_js_cbk_wdata_labels_tst.java +++ b/400_xowa/src/gplx/xowa/gui/views/Xog_html_js_cbk_wdata_labels_tst.java @@ -20,13 +20,13 @@ import org.junit.*; import gplx.xowa.xtns.wdatas.*; public class Xog_html_js_cbk_wdata_labels_tst { @Before public void init() {fxt.Init();} Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt(); @Test public void Basic() { - fxt.Init_pages_add(fxt.page_bldr_("q1").Label_add("en", "en_q1").Xto_page_doc()); - fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "en_q2").Xto_page_doc()); - fxt.Init_pages_add(fxt.page_bldr_("Property:P1").Label_add("en", "en_property_p1").Xto_page_doc()); + fxt.Init_pages_add(fxt.Wdoc_bldr("q1").Add_label("en", "en_q1").Xto_wdoc()); + fxt.Init_pages_add(fxt.Wdoc_bldr("q2").Add_label("en", "en_q2").Xto_wdoc()); + fxt.Init_pages_add(fxt.Wdoc_bldr("Property:P1").Add_label("en", "en_property_p1").Xto_wdoc()); Tst_wikidata_label_get(String_.Ary("en", "q1", "q2", "Property:P1"), String_.Ary("en_q1", "en_q2", "en_property_p1")); } @Test public void Outliers() { - fxt.Init_pages_add(fxt.page_bldr_("q1").Label_add("en", "en_q1").Label_add("de", "de_q1").Xto_page_doc()); + fxt.Init_pages_add(fxt.Wdoc_bldr("q1").Add_label("en", "en_q1").Add_label("de", "de_q1").Xto_wdoc()); Tst_wikidata_label_get(String_.Ary("fr", "q1"), String_.Ary((String)null)); Tst_wikidata_label_get(String_.Ary("de", "q1"), String_.Ary("de_q1")); Tst_wikidata_label_get(String_.Ary("xowa_title", "q1"), String_.Ary("q1")); diff --git a/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_mgr.java b/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_mgr.java index de708f202..a7ddc2604 100644 --- a/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_mgr.java +++ b/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_mgr.java @@ -51,7 +51,7 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble { public byte[] Css_wiki_bry() {return css_wiki_bry;} public Xoh_page_wtr_mgr Css_wiki_bry_(Io_url v) {css_wiki_bry = app.Encoder_mgr().Fsys().Encode_http(v); return this;} private byte[] css_wiki_bry; private Bry_fmtr page_read_fmtr = Bry_fmtr.new_("" , "page_id", "page_name", "page_title", "page_content_sub", "page_jumpto", "page_data", "page_langs", "page_modified_on_msg", "page_lang_ltr" - , "html_css_common_path", "html_css_wiki_path", "html_content_editable" + , "html_css_common_path", "html_css_wiki_path", "page_body_cls", "html_content_editable" , "xowa_head" , "portal_div_personal", "portal_div_ns", "portal_div_view" , "portal_div_logo", "portal_div_home", "portal_div_xtn", "portal_div_wikis", "portal_sidebar" @@ -60,7 +60,7 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble { ); public Bry_fmtr Page_edit_fmtr() {return page_edit_fmtr;} private Bry_fmtr page_edit_fmtr = Bry_fmtr.new_("" , "page_id", "page_name", "page_title", "page_content_sub", "page_jumpto", "page_data", "page_langs", "page_modified_on_msg", "page_lang_ltr" - , "html_css_common_path", "html_css_wiki_path", "html_content_editable" + , "html_css_common_path", "html_css_wiki_path", "page_body_cls", "html_content_editable" , "xowa_head" , "portal_div_personal", "portal_div_ns", "portal_div_view" , "portal_div_logo", "portal_div_home", "portal_div_xtn", "portal_div_wikis", "portal_sidebar" @@ -69,7 +69,7 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble { ); public Bry_fmtr Page_html_fmtr() {return page_html_fmtr;} private Bry_fmtr page_html_fmtr = Bry_fmtr.new_("" , "page_id", "page_name", "page_title", "page_content_sub", "page_jumpto", "page_data", "page_langs", "page_modified_on_msg", "page_lang_ltr" - , "html_css_common_path", "html_css_wiki_path", "html_content_editable" + , "html_css_common_path", "html_css_wiki_path", "page_body_cls", "html_content_editable" , "xowa_head" , "portal_div_personal", "portal_div_ns", "portal_div_view" , "portal_div_logo", "portal_div_home", "portal_div_xtn", "portal_div_wikis", "portal_sidebar" diff --git a/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java b/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java index f171f6176..89473720f 100644 --- a/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java +++ b/400_xowa/src/gplx/xowa/html/Xoh_page_wtr_wkr.java @@ -58,6 +58,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg { } DateAdp page_modified_on_dte = page.Revision_data().Modified_on(); byte[] page_modified_on_msg = wiki.Msg_mgr().Val_by_id_args(Xol_msg_itm_.Id_portal_lastmodified, page_modified_on_dte.XtoStr_fmt_yyyy_MM_dd(), page_modified_on_dte.XtoStr_fmt_HHmm()); + byte[] page_body_class = Xoh_page_body_cls.Calc(tmp_bfr, page.Ttl()); byte[] html_content_editable = wiki.Gui_mgr().Cfg_browser().Content_editable() ? Content_editable_bry : Bry_.Empty; byte[] page_content_sub = Xoh_page_wtr_wkr_.Bld_page_content_sub(app, wiki, page, tmp_bfr); byte[] js_wikidata_bry = Wdata_wiki_mgr.Wiki_page_is_json(wiki.Domain_tid(), page.Ttl().Ns().Id()) ? app.User().Lang().Fragment_mgr().Html_js_wikidata() : Bry_.Empty; @@ -69,7 +70,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg { , page_content_sub , wiki.Html_mgr().Portal_mgr().Div_jump_to() , page_data, wtr_page_lang, page_modified_on_msg, page.Lang().Dir_bry() - , mgr.Css_common_bry(), mgr.Css_wiki_bry(), html_content_editable + , mgr.Css_common_bry(), mgr.Css_wiki_bry(), page_body_class, html_content_editable , page.Html_data().Module_mgr().Init(app, wiki, page).Init_dflts() , portal_mgr.Div_personal_bry(), portal_mgr.Div_ns_bry(app.Utl_bry_bfr_mkr(), page.Ttl(), wiki.Ns_mgr()), portal_mgr.Div_view_bry(app.Utl_bry_bfr_mkr(), view_tid, page.Html_data().Xtn_search_text()) , portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar), portal_mgr.Div_wikis_bry(app.Utl_bry_bfr_mkr()), portal_mgr.Sidebar_mgr().Html_bry() diff --git a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr__basic.java b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr__basic.java index 11467a5fd..8308a1c08 100644 --- a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr__basic.java +++ b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr__basic.java @@ -50,6 +50,9 @@ public class Xoh_file_wtr__basic { byte[] img_orig_src = xfer_itm.Html_orig_src(); byte[] lnki_ttl = lnki.Ttl().Page_txt(); Xof_ext lnki_ext = xfer_itm.Lnki_ext(); + boolean lnki_is_thumbable = Xop_lnki_type.Id_is_thumbable(lnki.Lnki_type()); + if (lnki_is_thumbable && !xfer_itm.File_found()) // "non-found" thumbs should default to 220; otherwise large "non-found" thumbs will create large boxes; PAGE:en.w:Wikipedia:Featured_picture_candidates/September_Morn "|1000000x260px"; DATE:2014-09-24 + div_width = Xof_img_size.Thumb_width_img; if ( html_mgr.Img_suppress_missing_src() // option to suppress src when file is missing && !xfer_itm.Html_pass() // file is missing; wipe values and wait for "correct" info before regenerating; mostly to handle unknown redirects && !lnki_ext.Id_is_media() // file is media; never suppress; src needs to be available for "click" on play; note that most media will be missing (not downloaded) @@ -74,7 +77,7 @@ public class Xoh_file_wtr__basic { else if (lnki_ext.Id_is_audio()) // audio this.Write_file_audio(bfr, ctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_orig_src, img_alt); else // image - this.Write_file_image(bfr, ctx, hctx, src, lnki, xfer_itm, uid, div_width, lnki_halign, lnki_halign_bry, lnki_ttl, lnki_ext, lnki_href, img_view_src, img_orig_src, img_alt); + this.Write_file_image(bfr, ctx, hctx, src, lnki, xfer_itm, uid, lnki_is_thumbable, div_width, lnki_halign, lnki_halign_bry, lnki_ttl, lnki_ext, lnki_href, img_view_src, img_orig_src, img_alt); } if (hctx.Mode_is_hdump() && Xof_html_elem.Tid_is_file(xfer_itm.Html_elem_tid())) { page.Hdump_data().Data_add_img(new Hdump_data_img__basic(), xfer_itm, Hdump_data_img__gallery.Tid_basic); @@ -99,7 +102,7 @@ public class Xoh_file_wtr__basic { else bfr.Add(content); } - private void Write_file_image(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int uid, int div_width, int lnki_halign, byte[] lnki_halign_bry + private void Write_file_image(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int uid, boolean lnki_is_thumbable, int div_width, int lnki_halign, byte[] lnki_halign_bry , byte[] lnki_ttl, Xof_ext lnki_ext, byte[] lnki_href, byte[] img_view_src, byte[] img_orig_src, byte[] alt) { if (lnki_halign == Xop_lnki_align_h.Center) bfr.Add(Div_center_bgn); Bry_bfr tmp_bfr = bfr_mkr.Get_k004(); @@ -107,7 +110,7 @@ public class Xoh_file_wtr__basic { ? Arg_anchor_title(tmp_bfr, src, lnki, lnki_ttl, anchor_title_wkr) // NOTE: Arg_anchor_title should only be called if there is no caption, else refs may not show; DATE:2014-03-05 : Bry_.Empty; Xoh_file_img_wkr lnki_file_wkr = lnki.Lnki_file_wkr(); if (lnki_file_wkr == null) lnki_file_wkr = html_fmtr; - if (Xop_lnki_type.Id_is_thumbable(lnki.Lnki_type())) { // is "thumb" + if (lnki_is_thumbable) { // is "thumb" if (bfr.Len() > 0) bfr.Add_byte_nl(); byte[] content = Arg_content_thumb(lnki_file_wkr, ctx, hctx, src, lnki, xfer_itm, uid, lnki_href, img_view_src, img_orig_src, alt, lnki_ttl, anchor_title); html_fmtr.Html_thumb_core(bfr, uid, lnki_halign_bry, div_width, content); diff --git a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr_audio_video_tst.java b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr_audio_video_tst.java index 3fbceed60..afa7fb4f0 100644 --- a/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr_audio_video_tst.java +++ b/400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr_audio_video_tst.java @@ -149,7 +149,7 @@ public class Xoh_file_wtr_audio_video_tst { fxt.Test_parse_page_wiki_str ( "[[File:A.ogv|thumb|400px|a|alt=b]]", String_.Concat_lines_nl_skip_last ( "
" - , "
" + , "
" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 , "
" , "
" , " " @@ -183,7 +183,7 @@ public class Xoh_file_wtr_audio_video_tst { fxt.Test_parse_page_wiki_str ( "[[File:A.webm|thumb|400px|a|alt=b]]", String_.Concat_lines_nl_skip_last ( "
" - , "
" + , "
" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 , "
" , "
" , " " diff --git a/400_xowa/src/gplx/xowa/html/modules/Xoh_module_itm__globals.java b/400_xowa/src/gplx/xowa/html/modules/Xoh_module_itm__globals.java index e86a2b771..834ede971 100644 --- a/400_xowa/src/gplx/xowa/html/modules/Xoh_module_itm__globals.java +++ b/400_xowa/src/gplx/xowa/html/modules/Xoh_module_itm__globals.java @@ -56,7 +56,7 @@ public class Xoh_module_itm__globals implements Xoh_module_itm { wtr.Write_js_global_ini_atr_obj(Key_wgMonthNames , months_long); wtr.Write_js_global_ini_atr_obj(Key_wgMonthNamesShort , months_short); } - private static final byte[] + public static final byte[] Key_mode_is_gui = Bry_.new_ascii_("mode_is_gui") , Key_mode_is_http = Bry_.new_ascii_("mode_is_http") , Key_http_port = Bry_.new_ascii_("http-port") diff --git a/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls.java b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls.java new file mode 100644 index 000000000..ab9d13e90 --- /dev/null +++ b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls.java @@ -0,0 +1,109 @@ +/* +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 . +*/ +package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; +public class Xoh_page_body_cls { // REF.MW:Skin.php|getPageClasses + public static byte[] Calc(Bry_bfr tmp_bfr, Xoa_ttl ttl) { + tmp_bfr.Add(Bry_id_prefix).Add_int_variable(ttl.Ns().Id()); // ns-0; note that special is ns--1 DATE:2014-09-24 + Add_type(tmp_bfr, ttl); // ns-special || ns-talk || ns-subject + tmp_bfr.Add_byte_space().Add(Bry_page_prefix).Add(Escape_cls(ttl.Full_db())); // page-Page_title + return tmp_bfr.XtoAryAndClear(); + } + private static void Add_type(Bry_bfr tmp_bfr, Xoa_ttl ttl) { + tmp_bfr.Add_byte_space(); + if (ttl.Ns().Id_special()) { + tmp_bfr.Add(Bry_type_special); // MW_TODO: add " mw-special-$canonicalName" + } + else if (ttl.Ns().Id_talk()) + tmp_bfr.Add(Bry_type_talk); + else + tmp_bfr.Add(Bry_type_subject); + } + public static byte[] Escape_cls(byte[] src) { // REF.MW:Sanitizer.php|escapeClass; return rtrim( preg_replace(array( '/(^[0-9\\-])|[\\x00-\\x20!"#$%&\'()*+,.\\/:;<=>?@[\\]^`{|}~]|\\xC2\\xA0/', '/_+/' ), '_', $class ), '_' ); + Bry_bfr trg_bfr = null; + int src_len = src.length; int bgn = -1; + for (int i = 0; i < src_len; ++i) { + byte b = src[i]; + switch (b) { + case Byte_ascii.Tab: case Byte_ascii.NewLine: case Byte_ascii.Space: + case Byte_ascii.Bang: case Byte_ascii.Quote: case Byte_ascii.Hash: case Byte_ascii.Dollar: case Byte_ascii.Percent: + case Byte_ascii.Amp: case Byte_ascii.Apos: case Byte_ascii.Paren_bgn: case Byte_ascii.Paren_end: case Byte_ascii.Asterisk: + case Byte_ascii.Plus: case Byte_ascii.Comma: case Byte_ascii.Dot: case Byte_ascii.Backslash: case Byte_ascii.Slash: + case Byte_ascii.Colon: case Byte_ascii.Semic: case Byte_ascii.Gt: case Byte_ascii.Eq: case Byte_ascii.Lt: + case Byte_ascii.Question: case Byte_ascii.At: case Byte_ascii.Brack_bgn: case Byte_ascii.Brack_end: + case Byte_ascii.Pow: case Byte_ascii.Tick: + case Byte_ascii.Curly_bgn: case Byte_ascii.Pipe: case Byte_ascii.Curly_end: case Byte_ascii.Tilde: + if (trg_bfr == null) + src[i] = Byte_ascii.Underline; + else { + if (bgn != -1) { + trg_bfr.Add_mid(src, bgn, i); + bgn = -1; + } + trg_bfr.Add_byte(Byte_ascii.Underline); + } + break; + case Byte_ascii.Underline: + if (trg_bfr == null) { + trg_bfr = Bry_bfr.new_(src_len); + trg_bfr.Add_mid(src, 0, i); + } + if (bgn != -1) { + trg_bfr.Add_mid(src, bgn, i); + bgn = -1; + } + int repeat = 0; + for (int j = i + 1; j < src_len; ++j) { + if (src[j] == Byte_ascii.Underline) + ++repeat; + else + break; + } + trg_bfr.Add_byte(Byte_ascii.Underline); + i += repeat; + break; + case -62: + int next = i + 1; + if (next < src_len && src[next] == -96) { + if (trg_bfr == null) { + trg_bfr = Bry_bfr.new_(src_len); + trg_bfr.Add_mid(src, 0, i); + } + trg_bfr.Add_byte(Byte_ascii.Underline); + ++i; + continue; + } + if (trg_bfr != null && bgn == -1) + bgn = i; + break; + default: + if (trg_bfr != null && bgn == -1) + bgn = i; + break; + } + } + if (bgn != -1) trg_bfr.Add_mid(src, bgn, src_len); + return trg_bfr == null ? src : trg_bfr.XtoAryAndClear(); + } + private static final byte[] + Bry_id_prefix = Bry_.new_ascii_("ns-") + , Bry_type_special = Bry_.new_ascii_("ns-special") + , Bry_type_talk = Bry_.new_ascii_("ns-talk") + , Bry_type_subject = Bry_.new_ascii_("ns-subject") + , Bry_page_prefix = Bry_.new_ascii_("page-") + ; +} diff --git a/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls_tst.java b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls_tst.java new file mode 100644 index 000000000..ce05afc0a --- /dev/null +++ b/400_xowa/src/gplx/xowa/html/portal/Xoh_page_body_cls_tst.java @@ -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 . +*/ +package gplx.xowa.html.portal; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*; +import org.junit.*; +public class Xoh_page_body_cls_tst { + @Before public void init() {} private Xoh_page_body_cls_fxt fxt = new Xoh_page_body_cls_fxt(); + @Test public void Escape_cls() { + fxt.Test_escape_cls("0123456789", "0123456789"); // noop: num + fxt.Test_escape_cls("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // noop: ucase + fxt.Test_escape_cls("abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz"); // noop: lcase + fxt.Test_escape_cls("!\"#$%&'()*+,.\\/:;<=>?@[]^`{|}~", "______________________________"); // underline: syms + fxt.Test_escape_cls("a.bcd..ef.", "a_bcd__ef_"); // letters + syms + fxt.Test_escape_cls("a__b___c" , "a_b_c"); // multiple underlines + fxt.Test_escape_cls("a b", "a_b"); // nbsp + } + @Test public void Calc() { + fxt.Test_calc("A" , "ns-0 ns-subject page-A"); + fxt.Test_calc("Talk:A" , "ns-1 ns-talk page-Talk_A"); + fxt.Test_calc("Wikipedia:Página principal" , "ns-4 ns-subject page-Wikipedia_Página_principal"); + } +} +class Xoh_page_body_cls_fxt { + private Bry_bfr tmp_bfr; private Xoa_app app; private Xow_wiki wiki; + public void Test_escape_cls(String raw, String expd) { + Tfds.Eq(expd, String_.new_utf8_(Xoh_page_body_cls.Escape_cls(Bry_.new_utf8_(raw)))); + } + public void Test_calc(String ttl_str, String expd) { + if (app == null) { + app = Xoa_app_fxt.app_(); + wiki = Xoa_app_fxt.wiki_tst_(app); + tmp_bfr = Bry_bfr.reset_(255); + } + Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_utf8_(ttl_str)); + Tfds.Eq(expd, String_.new_utf8_(Xoh_page_body_cls.Calc(tmp_bfr, ttl))); + } +} diff --git a/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java b/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java index 5783ba2a8..fe89963b7 100644 --- a/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java +++ b/400_xowa/src/gplx/xowa/servers/http/Http_server_mgr.java @@ -199,12 +199,14 @@ class Http_server_wkr implements Runnable { } } class HttpRequest implements Runnable{ - final static String CRLF = "\r\n"; - Socket socket; - Xoa_app app; + private static final String CRLF = "\r\n"; + private Socket socket; + private Xoa_app app; + private String app_root_dir; public HttpRequest(Socket socket, Xoa_app app){ this.socket = socket; this.app = app; + this.app_root_dir = app.Fsys_mgr().Root_dir().To_http_file_str(); } public void run(){ try { @@ -218,8 +220,15 @@ class HttpRequest implements Runnable{ String page_name = "Main_Page"; if(!req.contains("%file%")){ - if(req.equals("/")){ - req += app.Http_server().Home(); + if(req.equals("/")) { // no page; EX:"localhost:8080" vs "localhost:8080/en.wikipedia.org/wiki/Earth" + String home_url = app.Http_server().Home();; + if (String_.HasAtBgn(home_url, "file://")) { + Io_url file_url = Io_url_.http_any_(home_url, Op_sys.Cur().Tid_is_wnt()); + String page_html = Io_mgr._.LoadFilStr(file_url); + Write_page(dos, page_html, app_root_dir, wiki_domain); + } + else + req += app.Http_server().Home(); } if(req.endsWith("wiki/")) req+="Main_Page"; if(req.endsWith("wiki")) req+="/Main_Page"; @@ -238,8 +247,8 @@ class HttpRequest implements Runnable{ dos.close(); }else if(req.contains("%file%")){ - String path = req.replace("/%file%/", app.Fsys_mgr().Root_dir().To_http_file_str()); - path = path.substring(path.indexOf(app.Fsys_mgr().Root_dir().To_http_file_str())+5); + String path = req.replace("/%file%/", app_root_dir); + path = path.substring(path.indexOf(app_root_dir)+5); Url_encoder url_converter = Url_encoder.new_http_url_(); path = url_converter.Decode_str(path); if(path.contains("?")){ @@ -271,22 +280,10 @@ class HttpRequest implements Runnable{ Url_encoder url_converter = Url_encoder.new_http_url_(); page_name = url_converter.Decode_str(page_name); //page_name = app.Url_converter_url().Decode_str(page_name); - } - dos.writeBytes("HTTP/1.1 200 OK: "); - dos.writeBytes("Content-Type: text/html; charset=utf-8" + CRLF); - dos.writeBytes(CRLF); - try{ String page_html = app.Http_server().Parse_page_to_html(app, wiki_domain, page_name); - page_html = page_html.replaceAll(app.Fsys_mgr().Root_dir().To_http_file_str(),"%file%/"); - page_html = page_html.replaceAll("xowa-cmd", "%xowa-cmd%/xowa-cmd"); - page_html = page_html.replaceAll("" ), String_.Concat_lines_nl_skip_last ( "
" - , "
" + , "
" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 , "
" , " " , " \"b1\"" @@ -60,7 +60,7 @@ public class Imap_xnde_html_all_tst { , "" ), String_.Concat_lines_nl_skip_last ( "
" - , "
" + , "
" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 , "
" , " " , " " @@ -108,7 +108,7 @@ public class Imap_xnde_html_all_tst { , "" ), String_.Concat_lines_nl_skip_last ( "
" - , "
" + , "
" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 , "
" , " " , " \"b1\"" @@ -179,7 +179,7 @@ public class Imap_xnde_html_all_tst { , "" ), String_.Concat_lines_nl_skip_last ( "
" - , "
" + , "
" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24 , "
" , " " , " \"b1\"" diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_basic_tst.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_basic_tst.java index 848fdb3b2..b17f4947a 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_basic_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_basic_tst.java @@ -17,86 +17,85 @@ along with this program. If not, see . */ package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*; import org.junit.*; -public class Pft_func_time_basic_tst { - private Xop_fxt fxt = new Xop_fxt(); - @Before public void init() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} +public class Pft_func_time_basic_tst { + @Before public void init() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private Xop_fxt fxt = new Xop_fxt(); @After public void term() {Tfds.Now_enabled_n_();} - @Test public void Utc_date() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2012-01-02 03:04:05}}" , "{{test}}" , "2012-01-02");} - @Test public void Utc_time() {fxt.Test_parse_tmpl_str_test("{{#time:h:i:s A|2012-01-02 03:04:05}}" , "{{test}}" , "03:04:05 AM");} - @Test public void Utc_dayOfYear() {fxt.Test_parse_tmpl_str_test("{{#time:z|2012-01-01 03:04:05}}" , "{{test}}" , "0");} - @Test public void Utc_escape_basic() {fxt.Test_parse_tmpl_str_test("{{#time:\\Y Y|2012-01-02 03:04:05}}" , "{{test}}" , "Y 2012");} - @Test public void Utc_escape_double() {fxt.Test_parse_tmpl_str_test("{{#time:\\\\ Y|2012-01-02 03:04:05}}" , "{{test}}" , "\\ 2012");} - @Test public void Utc_escape_eos() {fxt.Test_parse_tmpl_str_test("{{#time:b\\|2012-01-02 03:04:05}}" , "{{test}}" , "b\\");} - @Test public void Utc_escape_newLine() {fxt.Test_parse_tmpl_str_test("{{#time:b\\\nb|2012-01-02 03:04:05}}" , "{{test}}" , "b\nb");} - @Test public void Utc_quote_basic() {fxt.Test_parse_tmpl_str_test("{{#time:b \"Y m d\" b|2012-01-02 03:04:05}}" , "{{test}}" , "b Y m d b");} - @Test public void Utc_quote_double() {fxt.Test_parse_tmpl_str_test("{{#time:b \"\" b|2012-01-02 03:04:05}}" , "{{test}}" , "b \" b");} - @Test public void Utc_quote_eos() {fxt.Test_parse_tmpl_str_test("{{#time:b \"|2012-01-02 03:04:05}}" , "{{test}}" , "b \"");} - @Test public void Utc_ws() {fxt.Test_parse_tmpl_str_test("{{#time: Y-m-d |2012-01-02 03:04:05}}" , "{{test}}" , "2012-01-02");} - @Test public void Lcl_date() {fxt.Test_parse_tmpl_str_test("{{#timel:Y-m-d|2012-01-02 03:04:05}}" , "{{test}}" , "2012-01-02");} - @Test public void Utc_dow_abrv() {fxt.Test_parse_tmpl_str_test("{{#time:D|20120301}}" , "{{test}}" , "Thu");} - @Test public void Utc_ymd() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|20120102}}" , "{{test}}" , "2012-01-02");} - @Test public void Utc_ym() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|201201}}" , "{{test}}" , "2012-01-01");} - @Test public void Utc_md() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2-13}}" , "{{test}}" , "2012-02-13");} // PURPOSE.fix: m-d failed - @Test public void Slashes() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2/13/12}}" , "{{test}}" , "2012-02-13");} // PURPOSE: assert slashes work - @Test public void Utc_day() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|March 27}}" , "{{test}}" , "2012-03-27");} - @Test public void Parse_day() {fxt.Test_parse_tmpl_str_test("{{#time:m d|March 27}}" , "{{test}}" , "03 27");} - @Test public void Month_name() {fxt.Test_parse_tmpl_str_test("{{#time:M|May 1 2012}}" , "{{test}}" , "May");} - @Test public void Error() {fxt.Test_parse_tmpl_str_test("{{#time:M|2}}" , "{{test}}" , "Invalid year: 2");} - @Test public void Error2() {fxt.Test_parse_tmpl_str_test("{{#time:Y|July 28 - August 1, 1975}}" , "{{test}}" , "Invalid time");} - @Test public void Error3() {fxt.Test_parse_tmpl_str_test("{{#time:Y|106BC-43BC}}" , "{{test}}" , "Invalid time");} - @Test public void Timestamp() {fxt.Test_parse_tmpl_str_test("{{#time:F j, Y|20060827072854}}" , "{{test}}" , "August 27, 2006");} // PAGE:en.w:Great Fire of London - @Test public void Unixtime_read() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d h:i:s A|@0}}" , "{{test}}" , "1970-01-01 12:00:00 AM");} // EX:w:Wikipedia:WikiProject_Articles_for_creation/BLD_Preload - @Test public void Unixtime_read_neg() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d h:i:s A|@-3600}}" , "{{test}}" , "1969-12-31 11:00:00 PM");} // EX:w:Wikipedia:WikiProject_Articles_for_creation/October_-_November_2012_Backlog_Elimination_Drive; DATE:2014-05-10 - @Test public void Unixtime_8_digit() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d h:i:s A|@20120304}}" , "{{test}}" , "1970-08-21 08:58:24 PM");} // PURPOSE: make sure yyyy-MM-dd is gobbled by "@" and not evaluated again as date; EX:w:Wikipedia:WikiProject_Articles_for_creation/October_-_November_2012_Backlog_Elimination_Drive; DATE:2014-05-10 - @Test public void Unixtime_write() {fxt.Test_parse_tmpl_str_test("{{#time:U|2012-08-02}}" , "{{test}}" , "1343865600");} // PAGE:en.w:Opa (programming language) - @Test public void Year_4_digit() {fxt.Test_parse_tmpl_str_test("{{#time:Y|June 20, 451}}" , "{{test}}" , "0451");} // PAGE:en.w:Battle of the Catalaunian Plains - @Test public void Year_month() {fxt.Test_parse_tmpl_str_test("{{#time:F Y|November 2012}}" , "{{test}}" , "November 2012");} // PAGE:en.w:Project:Current events - @Test public void Day_addition_with_dash(){fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2011-11-13 +1 day}}" , "{{test}}" , "2011-11-14");} // PURPOSE: +1 day was becoming -1 day b/c it was picking up - at -13; PAGE:en.w:Template:POTD/2012-10-09 - @Test public void Fmt_time_before_day() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i|04:50, 17 December 2010}}" , "{{test}}" , "2010-12-17 04:50");} // PURPOSE: strange day time format; PAGE:en.w:Talk:Battle of Fort Washington - @Test public void Fmt_time_before_day_2() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i|04:50, December 11, 2010}}", "{{test}}" , "2010-12-11 04:50");} // PURPOSE: handle hh:nn ymd; PAGE:en.w:Wikipedia:WikiProject_Maine/members; DATE:2014-06-25 - @Test public void Hour_zero() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i|August 18 2006 00:14}}" , "{{test}}" , "2006-08-18 00:14");} // PURPOSE: fix; invalid hour; PAGE:en.w:Talk:Martin Luther - @Test public void Iso() {fxt.Test_parse_tmpl_str_test("{{#time:c|2012-01-02 03:04:05}}" , "{{test}}" , "2012-01-02T03:04:05-05:00");} - @Test public void Ymdh() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2012-01-02-99}}" , "{{test}}" , "2012-01-06");} // PURPOSE: "99" is treated as 99th hour; EX:w:LimeWire; DATE:2014-03-24 - @Test public void Ymdh_noop() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2012-01-02-100}}" , "{{test}}" , "2012-01-02");} // PURPOSE: "100" is ignored - @Test public void Month_is_0() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2012-00-01}}" , "{{test}}" , "2011-12-01");} // PURPOSE: "0" for month is treated as -1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 - @Test public void Day_is_0() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|2012-12-00}}" , "{{test}}" , "2012-11-30");} // PURPOSE: "0" for day is treated as -1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 - @Test public void Day_suffix_y() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|11th Dec 2013}}" , "{{test}}" , "2013-12-11");} // PURPOSE: ignore suffix days; EX:11th; DATE:2014-03-25 - @Test public void Day_suffix_n() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|32nd Dec 2013}}" , "{{test}}" , "Invalid day: 32");} - @Test public void Day_rel_today() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|today}}" , "{{test}}" , "2012-01-02");} - @Test public void Day_rel_tomorrow() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|tomorrow}}" , "{{test}}" , "2012-01-03");} - @Test public void Day_rel_yesterday() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|yesterday}}" , "{{test}}" , "2012-01-01");} - @Test public void Unit_rel_year_next() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|next year}}" , "{{test}}" , "2013-01-02");} // DATE:2014-05-02 - @Test public void Unit_rel_year_last() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|last year}}" , "{{test}}" , "2011-01-02");} - @Test public void Unit_rel_year_previous(){fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|previous year}}" , "{{test}}" , "2011-01-02");} - @Test public void Unit_rel_year_this() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|this year}}" , "{{test}}" , "2012-01-02");} - @Test public void Time_rel_now() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d h:i:s A|now}}" , "{{test}}" , "2012-01-02 03:05:05 AM");} // NOTE: minute is 5, not 4, b/c each call to DateAdp_.Now() automatically increments by 1 minute; DATE:2014-04-13 - @Test public void Empty_is_today() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|}}" , "{{test}}" , "2012-01-02");} // tested on MW - @Test public void Day_name_today() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|Monday}}" , "{{test}}" , "2012-01-02");} // 2012-01-02 is Monday, so return Monday; DATE:2014-05-02 - @Test public void Day_name_future_1() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|Saturday}}" , "{{test}}" , "2012-01-07");} // return next Sunday; DATE:2014-05-02 - @Test public void Day_name_future_2() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|Sunday}}" , "{{test}}" , "2012-01-08");} // return next Saturday; DATE:2014-05-02 - @Test public void Day_name_dow() {fxt.Test_parse_tmpl_str_test("{{#time:w|Monday}}" , "{{test}}" , "1");} + @Test public void Utc_date() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-01-02 03:04:05}}" , "2012-01-02");} + @Test public void Utc_time() {fxt.Test_parse_tmpl_str("{{#time:h:i:s A|2012-01-02 03:04:05}}" , "03:04:05 AM");} + @Test public void Utc_dayOfYear() {fxt.Test_parse_tmpl_str("{{#time:z|2012-01-01 03:04:05}}" , "0");} + @Test public void Utc_escape_basic() {fxt.Test_parse_tmpl_str("{{#time:\\Y Y|2012-01-02 03:04:05}}" , "Y 2012");} + @Test public void Utc_escape_double() {fxt.Test_parse_tmpl_str("{{#time:\\\\ Y|2012-01-02 03:04:05}}" , "\\ 2012");} + @Test public void Utc_escape_eos() {fxt.Test_parse_tmpl_str("{{#time:b\\|2012-01-02 03:04:05}}" , "b\\");} + @Test public void Utc_escape_newLine() {fxt.Test_parse_tmpl_str("{{#time:b\\\nb|2012-01-02 03:04:05}}" , "b\nb");} + @Test public void Utc_quote_basic() {fxt.Test_parse_tmpl_str("{{#time:b \"Y m d\" b|2012-01-02 03:04:05}}" , "b Y m d b");} + @Test public void Utc_quote_double() {fxt.Test_parse_tmpl_str("{{#time:b \"\" b|2012-01-02 03:04:05}}" , "b \" b");} + @Test public void Utc_quote_eos() {fxt.Test_parse_tmpl_str("{{#time:b \"|2012-01-02 03:04:05}}" , "b \"");} + @Test public void Utc_ws() {fxt.Test_parse_tmpl_str("{{#time: Y-m-d |2012-01-02 03:04:05}}" , "2012-01-02");} + @Test public void Lcl_date() {fxt.Test_parse_tmpl_str("{{#timel:Y-m-d|2012-01-02 03:04:05}}" , "2012-01-02");} + @Test public void Utc_dow_abrv() {fxt.Test_parse_tmpl_str("{{#time:D|20120301}}" , "Thu");} + @Test public void Utc_ymd() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|20120102}}" , "2012-01-02");} + @Test public void Utc_ym() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|201201}}" , "2012-01-01");} + @Test public void Utc_md() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2-13}}" , "2012-02-13");} // PURPOSE.fix: m-d failed + @Test public void Slashes() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2/13/12}}" , "2012-02-13");} // PURPOSE: assert slashes work + @Test public void Utc_day() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|March 27}}" , "2012-03-27");} + @Test public void Parse_day() {fxt.Test_parse_tmpl_str("{{#time:m d|March 27}}" , "03 27");} + @Test public void Month_name() {fxt.Test_parse_tmpl_str("{{#time:M|May 1 2012}}" , "May");} + @Test public void Time_before_date__dmy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|04:50, 17 December 2010}}" , "2010-12-17 04:50");} // PAGE:en.w:Talk:Battle of Fort Washington + @Test public void Time_before_date__mdy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|04:50, December 11, 2010}}" , "2010-12-11 04:50");} // PAGE:en.w:Wikipedia:WikiProject_Maine/members; DATE:2014-06-25 + @Test public void Error() {fxt.Test_parse_tmpl_str("{{#time:M|2}}" , "Invalid year: 2");} + @Test public void Error2() {fxt.Test_parse_tmpl_str("{{#time:Y|July 28 - August 1, 1975}}" , "Invalid time");} + @Test public void Error3() {fxt.Test_parse_tmpl_str("{{#time:Y|106BC-43BC}}" , "Invalid time");} + @Test public void Timestamp() {fxt.Test_parse_tmpl_str("{{#time:F j, Y|20060827072854}}" , "August 27, 2006");} // PAGE:en.w:Great Fire of London + @Test public void Unixtime_read() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|@0}}" , "1970-01-01 12:00:00 AM");} // EX:w:Wikipedia:WikiProject_Articles_for_creation/BLD_Preload + @Test public void Unixtime_read_neg() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|@-3600}}" , "1969-12-31 11:00:00 PM");} // EX:w:Wikipedia:WikiProject_Articles_for_creation/October_-_November_2012_Backlog_Elimination_Drive; DATE:2014-05-10 + @Test public void Unixtime_8_digit() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|@20120304}}" , "1970-08-21 08:58:24 PM");} // PURPOSE: make sure yyyy-MM-dd is gobbled by "@" and not evaluated again as date; EX:w:Wikipedia:WikiProject_Articles_for_creation/October_-_November_2012_Backlog_Elimination_Drive; DATE:2014-05-10 + @Test public void Unixtime_write() {fxt.Test_parse_tmpl_str("{{#time:U|2012-08-02}}" , "1343865600");} // PAGE:en.w:Opa (programming language) + @Test public void Year_4_digit() {fxt.Test_parse_tmpl_str("{{#time:Y|June 20, 451}}" , "0451");} // PAGE:en.w:Battle of the Catalaunian Plains + @Test public void Year_month() {fxt.Test_parse_tmpl_str("{{#time:F Y|November 2012}}" , "November 2012");} // PAGE:en.w:Project:Current events + @Test public void Day_addition_with_dash(){fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2011-11-13 +1 day}}" , "2011-11-14");} // PURPOSE: +1 day was becoming -1 day b/c it was picking up - at -13; PAGE:en.w:Template:POTD/2012-10-09 + @Test public void Hour_zero() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|August 18 2006 00:14}}" , "2006-08-18 00:14");} // PURPOSE: fix; invalid hour; PAGE:en.w:Talk:Martin Luther + @Test public void Iso() {fxt.Test_parse_tmpl_str("{{#time:c|2012-01-02 03:04:05}}" , "2012-01-02T03:04:05-05:00");} + @Test public void Ymdh() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-01-02-99}}" , "2012-01-06");} // PURPOSE: "99" is treated as 99th hour; EX:w:LimeWire; DATE:2014-03-24 + @Test public void Ymdh_noop() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-01-02-100}}" , "2012-01-02");} // PURPOSE: "100" is ignored + @Test public void Month_is_0() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-00-01}}" , "2011-12-01");} // PURPOSE: "0" for month is treated as -1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 + @Test public void Day_is_0() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|2012-12-00}}" , "2012-11-30");} // PURPOSE: "0" for day is treated as -1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 + @Test public void Day_suffix_y() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|11th Dec 2013}}" , "2013-12-11");} // PURPOSE: ignore suffix days; EX:11th; DATE:2014-03-25 + @Test public void Day_suffix_n() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|32nd Dec 2013}}" , "Invalid day: 32");} + @Test public void Day_rel_today() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|today}}" , "2012-01-02");} + @Test public void Day_rel_tomorrow() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|tomorrow}}" , "2012-01-03");} + @Test public void Day_rel_yesterday() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|yesterday}}" , "2012-01-01");} + @Test public void Unit_rel_year_next() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|next year}}" , "2013-01-02");} // DATE:2014-05-02 + @Test public void Unit_rel_year_last() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|last year}}" , "2011-01-02");} + @Test public void Unit_rel_year_previous(){fxt.Test_parse_tmpl_str("{{#time:Y-m-d|previous year}}" , "2011-01-02");} + @Test public void Unit_rel_year_this() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|this year}}" , "2012-01-02");} + @Test public void Time_rel_now() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|now}}" , "2012-01-02 03:05:05 AM");} // NOTE: minute is 5, not 4, b/c each call to DateAdp_.Now() automatically increments by 1 minute; DATE:2014-04-13 + @Test public void Empty_is_today() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|}}" , "2012-01-02");} // tested on MW + @Test public void Day_name_today() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|Monday}}" , "2012-01-02");} // 2012-01-02 is Monday, so return Monday; DATE:2014-05-02 + @Test public void Day_name_future_1() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|Saturday}}" , "2012-01-07");} // return next Sunday; DATE:2014-05-02 + @Test public void Day_name_future_2() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d|Sunday}}" , "2012-01-08");} // return next Saturday; DATE:2014-05-02 + @Test public void Day_name_dow() {fxt.Test_parse_tmpl_str("{{#time:w|Monday}}" , "1");} @Test public void Timezone_offset() { DateAdp.Timezone_offset_test = -18000; - fxt.Test_parse_tmpl_str_test("{{#time:Z|}}" , "{{test}}" , "-18000"); + fxt.Test_parse_tmpl_str("{{#time:Z|}}" , "-18000"); DateAdp.Timezone_offset_test = Int_.MinValue; } // Z=timezone offset in seconds; http://php.net/manual/en/function.date.php; - @Test public void Timezone_plus() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i:s|2012-01-02 03:04:05+06:30}}" , "{{test}}" , "2012-01-02 09:34:05");} // PURPOSE: handle timezone plus ; EX: +01:30; DATE:2014-08-26 - @Test public void Timezone_minus() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i:s|2012-01-02 09:34:05-06:30}}" , "{{test}}" , "2012-01-02 03:04:05");} // PURPOSE: handle timezone minus; EX: -01:30; DATE:2014-08-26 - @Test public void Timezone_wrap() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d H:i:s|2012-01-31 22:30:05+01:30}}" , "{{test}}" , "2012-02-01 00:00:05");} // PURPOSE: handle timezone wrap ; DATE:2014-08-26 - @Test public void Rfc5322() {fxt.Test_parse_tmpl_str_test("{{#time:r|}}" , "{{test}}" , "Mon, 02 Jan 2012 08:04:05 +0000");} + @Test public void Timezone_plus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 03:04:05+06:30}}" , "2012-01-02 09:34:05");} // PURPOSE: handle timezone plus ; EX: +01:30; DATE:2014-08-26 + @Test public void Timezone_minus() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-02 09:34:05-06:30}}" , "2012-01-02 03:04:05");} // PURPOSE: handle timezone minus; EX: -01:30; DATE:2014-08-26 + @Test public void Timezone_wrap() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i:s|2012-01-31 22:30:05+01:30}}" , "2012-02-01 00:00:05");} // PURPOSE: handle timezone wrap ; DATE:2014-08-26 + @Test public void Rfc5322() {fxt.Test_parse_tmpl_str("{{#time:r|}}" , "Mon, 02 Jan 2012 08:04:05 +0000");} @Test public void Lang() { Xol_lang fr_lang = fxt.App().Lang_mgr().Get_by_key_or_new(Bry_.new_ascii_("fr")); Xol_msg_itm msg_itm = fr_lang.Msg_mgr().Itm_by_key_or_new(Bry_.new_ascii_("January")); msg_itm.Atrs_set(Bry_.new_ascii_("Janvier"), false, false); - fxt.Test_parse_tmpl_str_test("{{#time:F|2012-01|fr}}" , "{{test}}" , "Janvier"); -// fxt.Test_parse_tmpl_str_test("{{#time:F|2012-01|fr_bad}}" , "{{test}}" , "January"); // default to english // commented out; fails when running all at once + fxt.Test_parse_tmpl_str("{{#time:F|2012-01|fr}}" , "Janvier"); +// fxt.Test_parse_tmpl_str("{{#time:F|2012-01|fr_bad}}" , "January"); // default to english // commented out; fails when running all at once } - @Test public void Hour_with_dash() {fxt.Test_parse_tmpl_str_test("{{#time:c|January 2, 2001-06}}" , "{{test}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor) generates this during {{time ago|November 2, 1991-06-19|min_magnitude=days}}; DATE:2013-06-19 - @Test public void Multiple_dates_gt_12() {fxt.Test_parse_tmpl_str_test("{{#time:c|January 2, 2001-06-19}}" , "{{test}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor) - @Test public void Multiple_dates_lt_12() {fxt.Test_parse_tmpl_str_test("{{#time:c|January 2, 2001-06-11}}" , "{{test}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor) - @Test public void Raw_H() {fxt.Test_parse_tmpl_str_test("{{#time:xnH}}" , "{{test}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31 - @Test public void Raw_h() {fxt.Test_parse_tmpl_str_test("{{#time:xnh}}" , "{{test}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31 - @Test public void Iso8601_T() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d h:i:s A|T1:23}}" , "{{test}}" , "2012-01-01 01:23:00 AM");} // handle "T" flag; PAGE:pl.w:StarCraft_II:_Wings_of_Liberty - @Test public void Iso8601_T_ws() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d h:i:s A|T 1:23}}" , "{{test}}" , "2012-01-01 01:23:00 AM");} // handle "T" flag and ws - @Test public void Iso8601_T_fail() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d h:i:s A|T2012-01-02}}" , "{{test}}" , "Invalid hour: T");} // handle "T" flag and ws + @Test public void Hour_with_dash() {fxt.Test_parse_tmpl_str("{{#time:c|January 2, 2001-06}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor) generates this during {{time ago|November 2, 1991-06-19|min_magnitude=days}}; DATE:2013-06-19 + @Test public void Multiple_dates_gt_12() {fxt.Test_parse_tmpl_str("{{#time:c|January 2, 2001-06-19}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor) + @Test public void Multiple_dates_lt_12() {fxt.Test_parse_tmpl_str("{{#time:c|January 2, 2001-06-11}}" , "2001-01-02T06:00:00-05:00");} // PURPOSE.fix: w:Vim_(text_editor) + @Test public void Raw_H() {fxt.Test_parse_tmpl_str("{{#time:xnH}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31 + @Test public void Raw_h() {fxt.Test_parse_tmpl_str("{{#time:xnh}}" , "08");} // PURPOSE: ignore "xn" for now; chk 0-padded number is generated; DATE:2013-12-31 + @Test public void Iso8601_T() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T1:23}}" , "2012-01-01 01:23:00 AM");} // handle "T" flag; PAGE:pl.w:StarCraft_II:_Wings_of_Liberty + @Test public void Iso8601_T_ws() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T 1:23}}" , "2012-01-01 01:23:00 AM");} // handle "T" flag and ws + @Test public void Iso8601_T_fail() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d h:i:s A|T2012-01-02}}" , "Invalid hour: T");} // handle "T" flag and ws } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_grp.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_int_tst.java similarity index 50% rename from 400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_grp.java rename to 400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_int_tst.java index e91adcf2d..9ff225298 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_grp.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pft_func_time_int_tst.java @@ -15,16 +15,10 @@ 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 . */ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -public class Wdata_prop_grp { - public Wdata_prop_grp(Int_obj_ref id_ref) {this.id_ref = id_ref;} - public Int_obj_ref Id_ref() {return id_ref;} Int_obj_ref id_ref; - public int Id() {return id_ref.Val();} - public int Itms_len() {return itms.length;} Wdata_prop_itm_core[] itms; - public Wdata_prop_itm_core Itms_get_at(int i) {return itms[i];} - public void Itms_add(Wdata_prop_itm_core itm) {list.Add(itm);} ListAdp list = ListAdp_.new_(); - public void Itms_make() { - itms = (Wdata_prop_itm_core[])list.XtoAryAndClear(Wdata_prop_itm_core.class); - list = null; - } +package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*; +import org.junit.*; +public class Pft_func_time_int_tst { + @Before public void init() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private Xop_fxt fxt = new Xop_fxt(); + @Test public void Time_before_date__dmy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|01:02 3.4.2005}}" , "2005-04-03 01:02");} // PAGE:sk.w:Dr._House; DATE:2014-09-23 + @Test public void Time_before_date__mdy() {fxt.Test_parse_tmpl_str("{{#time:Y-m-d H:i|01:02 3.14.2005}}" , "Invalid month: 14");} // mdy is invalid; DATE:2014-09-23 } diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_eval_seg.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_eval_seg.java new file mode 100644 index 000000000..3ea8a37bd --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_eval_seg.java @@ -0,0 +1,209 @@ +/* +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 . +*/ +package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*; +class Pxd_eval_year { + public static void Eval_at_pos_0(Pxd_parser tctx, Pxd_itm_int cur) { + Pxd_itm[] data_ary = tctx.Data_ary(); + if (tctx.Data_ary_len() < 2) return; + Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); + if (itm_1 != null) { + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_1)) return; + } + if (tctx.Data_ary_len() < 3) return; + Pxd_itm_int itm_2 = Pxd_itm_int_.CastOrNull(data_ary[2]); + if (itm_2 != null) { + if (!Pxd_eval_seg.Eval_as_d(tctx, itm_2)) return; + } + if (tctx.Data_ary_len() == 4) { // handle strange constructions like 2014-03-24-25; + Pxd_itm_int itm_3 = Pxd_itm_int_.CastOrNull(data_ary[3]); + if (itm_3 != null) { // treat 4th number as hour adjustment; EX: 2014-03-24-72 -> 2014-03-26; DATE:2014-03-24 + int itm_3_val = itm_3.Val(); + if (itm_3_val > 99) itm_3_val = 0; // only adjust if number is between 0 and 99; + Pxd_itm_int_.Convert_to_rel(tctx, itm_3, Pxd_parser_.Unit_name_hour, DateAdp_.SegIdx_hour, itm_3_val); + } + } + } + public static void Eval_at_pos_2(Pxd_parser tctx, Pxd_itm_int cur) { + Pxd_itm[] data_ary = tctx.Data_ary(); + Pxd_itm_int itm_0 = Pxd_itm_int_.CastOrNull(data_ary[0]); + Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); + if (itm_0 == null || itm_1 == null) return; // 0 or 1 is not an int; + if (itm_1.Val() > 13) { + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_d(tctx, itm_1)) return; + } + else { + if (!Pxd_eval_seg.Eval_as_d(tctx, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_1)) return; + } + } + public static void Eval_at_pos_n(Pxd_parser tctx, Pxd_itm_int cur) { // where n > 2; EX: 1:23 4.5.2010; PAGE:sk.w:Dr._House; DATE:2014-09-23 + Pxd_itm[] data_ary = tctx.Data_ary(); int data_ary_len = data_ary.length; int data_idx = cur.Data_idx(); + Pxd_itm_int lhs_1 = Pxd_itm_int_.Get_int_bwd(data_ary, data_ary_len, data_idx - 1); + if (lhs_1 != null) { // lhs_1 is int; EX:05-2014 + Pxd_itm_int lhs_0 = Pxd_itm_int_.Get_int_bwd(data_ary, data_ary_len, data_idx - 2); + if (lhs_0 != null) { // lhs_0 is int; EX:01-05-2014 + if (!Pxd_eval_seg.Eval_as_d(tctx, lhs_0)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, lhs_1)) return; + if (!Pxd_eval_seg.Eval_as_y(tctx, cur )) return; + } + } + } + public static final int Month_max = 12; +} +class Pxd_eval_seg { + public static boolean Eval_as_y(Pxd_parser tctx, Pxd_itm_int itm) { + int val = itm.Val(); + switch (itm.Digits()) { + case 1: + case 2: + itm.Val_(val + (val > 69 ? 1900 : 2000)); // assume that 70 refers to 1970 and 69 refers to 2069 + tctx.Seg_idxs_(itm, DateAdp_.SegIdx_year); + return true; + case 3: // NOTE: 3 digit numbers are valid years; MW relies on PHP time parse which always zero-pad numbers; PAGE:en.w:Battle of the Catalaunian Plains; {{#time:Y|June 20, 451}} + case 4: + tctx.Seg_idxs_(itm, DateAdp_.SegIdx_year); + return true; + } + tctx.Err_set(Pft_func_time_log.Invalid_year, Bry_fmtr_arg_.int_(val)); + return false; + } + public static boolean Eval_as_m(Pxd_parser tctx, Pxd_itm_int itm) { + int val = itm.Val(); + switch (itm.Digits()) { + case 1: + case 2: + if (val > 0 && val < 13) { + tctx.Seg_idxs_(itm, DateAdp_.SegIdx_month); + return true; + } + else if (val == 0) {// 0 day means subtract 1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 + Pxd_itm_int_.Convert_to_rel(tctx, itm, Pxd_parser_.Unit_name_month, DateAdp_.SegIdx_month, -1); + return true; + } + break; + } + tctx.Err_set(Pft_func_time_log.Invalid_month, Bry_fmtr_arg_.int_(val)); + return false; + } + public static boolean Eval_as_d(Pxd_parser tctx, Pxd_itm_int itm) { + int val = itm.Val(); + switch (itm.Digits()) { + case 1: + case 2: + if (val > 0 && val < 32) { + tctx.Seg_idxs_(itm, DateAdp_.SegIdx_day); + return true; + } + else if (val == 0) { // 0 day means subtract 1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 + Pxd_itm_int_.Convert_to_rel(tctx, itm, Pxd_parser_.Unit_name_day, DateAdp_.SegIdx_day, -1); + return true; + } + break; + } + tctx.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(val)); + return false; + } + public static boolean Eval_as_h(Pxd_parser tctx, Pxd_itm_int itm) { + int val = itm.Val(); + switch (itm.Digits()) { + case 1: + case 2: + if (val > -1 && val < 25) { + tctx.Seg_idxs_(itm, DateAdp_.SegIdx_hour, val); + return true; + } + break; + } + tctx.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.int_(val)); + return false; + } + public static boolean Eval_as_n(Pxd_parser tctx, Pxd_itm_int itm) { + int val = itm.Val(); + switch (itm.Digits()) { + case 1: + case 2: + if (val > -1 && val < 60) { + tctx.Seg_idxs_(itm, DateAdp_.SegIdx_minute, val); + return true; + } + break; + } + tctx.Err_set(Pft_func_time_log.Invalid_minute, Bry_fmtr_arg_.int_(val)); + return false; + } + public static boolean Eval_as_s(Pxd_parser tctx, Pxd_itm_int itm) { + int val = itm.Val(); + switch (itm.Digits()) { + case 1: + case 2: + if (val > -1 && val < 60) { + tctx.Seg_idxs_(itm, DateAdp_.SegIdx_second); + return true; + } + break; + } + tctx.Err_set(Pft_func_time_log.Invalid_second, Bry_fmtr_arg_.int_(val)); + return false; + } + public static boolean Eval_as_tz_h(Pxd_parser tctx, Pxd_itm_int itm, boolean negative) { + if (negative) itm.Val_(itm.Val() * -1); + int val = itm.Val(); + switch (itm.Digits()) { + case 1: + case 2: + if (val > -12 && val < 12) { + itm.Val_is_adj_(Bool_.Y); + itm.Seg_idx_(DateAdp_.SegIdx_hour); + return true; + } + break; + } + tctx.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.int_(val)); + return false; + } + public static boolean Eval_as_tz_m(Pxd_parser tctx, Pxd_itm_int itm, boolean negative) { + int val = itm.Val(); + if (negative) val *= -1; + switch (itm.Digits()) { + case 1: + case 2: + if (val > -60 && val < 60) { + itm.Val_is_adj_(Bool_.Y); + itm.Seg_idx_(DateAdp_.SegIdx_minute); + return true; + } + break; + } + tctx.Err_set(Pft_func_time_log.Invalid_minute, Bry_fmtr_arg_.int_(val)); + return false; + } + public static byte Eval_as_tz_sym(Pxd_parser tctx, Pxd_itm[] tkns, Pxd_itm_int hour_itm) { + Pxd_itm sym = Pxd_itm_.Find_bwd__non_ws(tkns, hour_itm.Ary_idx()); + switch (sym.Tkn_tid()) { + case Pxd_itm_.Tid_sym: + Pxd_itm_sym sym_itm = (Pxd_itm_sym)sym; + if (sym_itm.Sym_byte() == Byte_ascii.Plus) + return Bool_.Y_byte; + break; + case Pxd_itm_.Tid_dash: return Bool_.N_byte; + } + tctx.Err_set(Pft_func_time_log.Invalid_timezone, Bry_fmtr_arg_.bry_("null")); + return Bool_.__byte; + } +} \ No newline at end of file diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_.java index 094e81541..590aec035 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_.java @@ -63,6 +63,7 @@ class Pxd_itm_ { } return null; } + public static boolean Eval_needed(Pxd_itm itm) {return itm.Seg_idx() == -1;} } abstract class Pxd_itm_base implements Pxd_itm { public abstract byte Tkn_tid(); diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_int.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_int.java index 231680197..2d0435600 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_int.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_int.java @@ -57,211 +57,177 @@ class Pxd_itm_int extends Pxd_itm_base implements Pxd_itm_int_interface { } else bldr.Seg_set(seg_idx, val); - } - private static final int Month_max = 12; - @Override public void Eval(Pxd_parser state) { + } + @Override public void Eval(Pxd_parser tctx) { int data_idx = this.Data_idx(); if (this.Seg_idx() != Pxd_itm_base.Seg_idx_null) return; // has seg_idx; already eval'd by something else switch (digits) { case 5: // 5 digits switch (data_idx) { - case 0: Eval_year_at_pos_0(state); break; // year at pos 0; EX: 01234-02-03 - case 1: state.Err_set(Pft_func_time_log.Invalid_date); return; // year at pos 1; invalid; EX: 01-01234-02 - case 2: state.Err_set(Pft_func_time_log.Invalid_date); break; // year at pos 2; invalid; EX: 01-02-01234 + case 0: Pxd_eval_year.Eval_at_pos_0(tctx, this); break; // year at pos 0; EX: 01234-02-03 + case 1: tctx.Err_set(Pft_func_time_log.Invalid_date); return; // year at pos 1; invalid; EX: 01-01234-02 + case 2: tctx.Err_set(Pft_func_time_log.Invalid_date); break; // year at pos 2; invalid; EX: 01-02-01234 } val = 2000 + (val % 10); // NOTE: emulate PHP's incorrect behavior with 5 digit years; EX:ca.w:Nicolau_de_Mira; DATE:2014-04-18 - state.Seg_idxs_(this, DateAdp_.SegIdx_year); + tctx.Seg_idxs_(this, DateAdp_.SegIdx_year); break; case 4: // 4 digits; assume year switch (data_idx) { - case 0: Eval_year_at_pos_0(state); break; // year at pos 0; EX: 2001-02-03 - case 1: state.Err_set(Pft_func_time_log.Invalid_year_mid); return; // year at pos 1; invalid; EX: 02-2003-03 - case 2: Eval_year_at_pos_2(state); break; // year at pos 2; EX: 02-03-2001 + case 0: Pxd_eval_year.Eval_at_pos_0(tctx, this); break; // year at pos 0; EX: 2001-02-03 + case 1: tctx.Err_set(Pft_func_time_log.Invalid_year_mid); return;// year at pos 1; invalid; EX: 02-2003-03 + case 2: Pxd_eval_year.Eval_at_pos_2(tctx, this); break; // year at pos 2; EX: 02-03-2001 + default: Pxd_eval_year.Eval_at_pos_n(tctx, this); break; // year at pos n; EX: 04:05 02-03-2001 } - state.Seg_idxs_(this, DateAdp_.SegIdx_year); + tctx.Seg_idxs_(this, DateAdp_.SegIdx_year); break; default: - Pxd_itm[] data_ary = state.Data_ary(); + Pxd_itm[] data_ary = tctx.Data_ary(); int data_ary_len = data_ary.length; Pxd_itm_int cur_itm = Pxd_itm_int_.CastOrNull(data_ary[data_idx]); Pxd_itm lhs_itm = data_idx == 0 ? null : data_ary[data_idx - 1]; Pxd_itm rhs_itm = data_idx == data_ary_len - 1 ? null : data_ary[data_idx + 1]; if ( lhs_itm != null && lhs_itm.Seg_idx() == DateAdp_.SegIdx_month // itm on left is month && rhs_itm != null && rhs_itm.Seg_idx() == DateAdp_.SegIdx_year // itm on right is year - && state.Seg_idxs()[DateAdp_.SegIdx_day] == -1 // day not yet set; needed for {{#time:Y|July 28 - August 1, 1975}} + && tctx.Seg_idxs()[DateAdp_.SegIdx_day] == -1 // day not yet set; needed for {{#time:Y|July 28 - August 1, 1975}} ) - if (Pxd_itm_int_.Day_err(state, cur_itm)) return; // cur int should be day; EX:January 1, 2010; PAGE:en.w:Wikipedia:WikiProject_Maine/members; DATE:2014-06-25 - if (val > Month_max) { // value is not a month; assume day; DATE:2013-03-15 + if (!Pxd_eval_seg.Eval_as_d(tctx, cur_itm)) return; // cur int should be day; EX:January 1, 2010; PAGE:en.w:Wikipedia:WikiProject_Maine/members; DATE:2014-06-25 + if (val > Month_max) { // value is not a month; assume day; DATE:2013-03-15 switch (data_idx) { case 0: // > 12 in slot 0 - if (Match_sym(state, true, Pxd_itm_.Tid_dot)) // next sym is dot; assume m.d.y; EX: 22.5.70 - Eval_day_at_pos_0(state); + if (Match_sym(tctx, Bool_.Y, Pxd_itm_.Tid_dot)) // next sym is dot; assume m.d.y; EX: 22.5.70 + Eval_day_at_pos_0(tctx); else // next sym is not dot; assume y-m-d; EX: 70-5-22 - Eval_month_at_pos_0(state); + Eval_month_at_pos_0(tctx); break; - case 1: Eval_month_at_pos_1(state); break; // > 12 in slot 1; assume m.d; EX: 5.22 + case 1: Eval_month_at_pos_1(tctx); break; // > 12 in slot 1; assume m.d; EX: 5.22 case 2: // > 12 in slot 2 - if (Match_sym(state, false, Pxd_itm_.Tid_dot)) // prv sym is dot; assume d.m.y; EX: 22.5.70 - Eval_dmy_at_y(state); + if (Match_sym(tctx, Bool_.N, Pxd_itm_.Tid_dot)) // prv sym is dot; assume d.m.y; EX: 22.5.70 + Eval_dmy_at_y(tctx); else // prv sym is not dot; assume m-d-y; EX: 22.5.70 - Eval_month_at_pos_2(state); + Eval_month_at_pos_2(tctx); break; case 4: - Eval_unknown_at_pos_4(state); + Eval_unknown_at_pos_4(tctx); break; } } else { // value is either day or month; switch (data_idx) { - case 0: Eval_unknown_at_pos_0(state); break; - case 3: Eval_unknown_at_pos_3(state); break; - case 4: Eval_unknown_at_pos_4(state); break; + case 0: Eval_unknown_at_pos_0(tctx); break; + case 3: Eval_unknown_at_pos_3(tctx); break; + case 4: Eval_unknown_at_pos_4(tctx); break; } } break; } } - private void Eval_unknown_at_pos_3(Pxd_parser state) { // int at pos 4 - if ( state.Seg_idxs_chk(DateAdp_.SegIdx_year, DateAdp_.SegIdx_month, DateAdp_.SegIdx_day) // check that ymd is set - && Match_sym(state, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-" - Pxd_itm_int_.Hour_err(state, this); // mark as hour; handles strange fmts like November 2, 1991-06; DATE:2013-06-19 + public static final int Month_max = 12; + private void Eval_unknown_at_pos_3(Pxd_parser tctx) { // int at pos 4 + if ( tctx.Seg_idxs_chk(DateAdp_.SegIdx_year, DateAdp_.SegIdx_month, DateAdp_.SegIdx_day) // check that ymd is set + && Match_sym(tctx, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-" + Pxd_eval_seg.Eval_as_h(tctx, this); // mark as hour; handles strange fmts like November 2, 1991-06; DATE:2013-06-19 } - private void Eval_unknown_at_pos_4(Pxd_parser state) { - if ( state.Seg_idxs_chk(DateAdp_.SegIdx_year + private void Eval_unknown_at_pos_4(Pxd_parser tctx) { + if ( tctx.Seg_idxs_chk(DateAdp_.SegIdx_year , DateAdp_.SegIdx_month, DateAdp_.SegIdx_day, DateAdp_.SegIdx_hour) // check that ymdh is set - && Match_sym(state, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-" - state.Seg_idxs_(this, Pxd_itm_base.Seg_idx_skip); // mark as ignore; handles strange fmts like November 2, 1991-06-19; DATE:2013-06-19 + && Match_sym(tctx, false, Pxd_itm_.Tid_dash)) // check that preceding symbol is "-" + tctx.Seg_idxs_(this, Pxd_itm_base.Seg_idx_skip); // mark as ignore; handles strange fmts like November 2, 1991-06-19; DATE:2013-06-19 } - boolean Match_sym(Pxd_parser state, boolean fwd, int sym_tid) { + boolean Match_sym(Pxd_parser tctx, boolean fwd, int sym_tid) { int sym_idx = this.Ary_idx() + (fwd ? 1 : -1); - Pxd_itm[] sym_tkns = state.Tkns(); + Pxd_itm[] sym_tkns = tctx.Tkns(); if (sym_idx < 0 || sym_idx > sym_tkns.length) return false; // NOTE: was Data_ary_len; DATE:2013-06-19 return sym_tkns[sym_idx].Tkn_tid() == sym_tid; } - private void Eval_month_at_pos_0(Pxd_parser state) { - Pxd_itm[] data_ary = state.Data_ary(); - if (state.Data_ary_len() < 2) return; + private void Eval_month_at_pos_0(Pxd_parser tctx) { + Pxd_itm[] data_ary = tctx.Data_ary(); + if (tctx.Data_ary_len() < 2) return; Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); if (itm_1 != null) { - if (Pxd_itm_int_.Month_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_1)) return; } - if (state.Data_ary_len() > 2) { + if (tctx.Data_ary_len() > 2) { Pxd_itm_int itm_2 = Pxd_itm_int_.CastOrNull(data_ary[2]); if (itm_2 != null) { - if (Pxd_itm_int_.Day_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_d(tctx, itm_2)) return; } } - Pxd_itm_int_.Year_err(state, this); + Pxd_eval_seg.Eval_as_y(tctx, this); } - private void Eval_day_at_pos_0(Pxd_parser state) { // eval 1 as month; 2 as year, 0 as day - Pxd_itm[] data_ary = state.Data_ary(); - if (state.Data_ary_len() < 2) return; + private void Eval_day_at_pos_0(Pxd_parser tctx) { // eval 1 as month; 2 as year, 0 as day + Pxd_itm[] data_ary = tctx.Data_ary(); + if (tctx.Data_ary_len() < 2) return; Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); if (itm_1 != null) { - if (Pxd_itm_int_.Month_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_1)) return; } - if (state.Data_ary_len() > 2) { + if (tctx.Data_ary_len() > 2) { Pxd_itm_int itm_2 = Pxd_itm_int_.CastOrNull(data_ary[2]); if (itm_2 != null) { - if (Pxd_itm_int_.Year_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_y(tctx, itm_2)) return; } } - Pxd_itm_int_.Day_err(state, this); + Pxd_eval_seg.Eval_as_d(tctx, this); } - private void Eval_dmy_at_y(Pxd_parser state) { // dmy format; cur is y (slot 2) - Pxd_itm[] data_ary = state.Data_ary(); - if (state.Data_ary_len() < 3) return; // since proc starts at y, assume at least d-m-y (not m-y) + private void Eval_dmy_at_y(Pxd_parser tctx) { // dmy format; cur is y (slot 2) + Pxd_itm[] data_ary = tctx.Data_ary(); + if (tctx.Data_ary_len() < 3) return; // since proc starts at y, assume at least d-m-y (not m-y) Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); if (itm_1 != null) { - if (Pxd_itm_int_.Month_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_1)) return; } Pxd_itm_int itm_0 = Pxd_itm_int_.CastOrNull(data_ary[0]); if (itm_0 != null) { - if (Pxd_itm_int_.Year_err(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_y(tctx, itm_0)) return; } - Pxd_itm_int_.Year_err(state, this); + Pxd_eval_seg.Eval_as_y(tctx, this); } - private void Eval_month_at_pos_1(Pxd_parser state) { - Pxd_itm[] data_ary = state.Data_ary(); + private void Eval_month_at_pos_1(Pxd_parser tctx) { + Pxd_itm[] data_ary = tctx.Data_ary(); Pxd_itm_int itm_0 = Pxd_itm_int_.CastOrNull(data_ary[0]); if (itm_0 != null) { - if (Pxd_itm_int_.Month_err(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_0)) return; } - if (state.Data_ary_len() > 2) { + if (tctx.Data_ary_len() > 2) { Pxd_itm_int itm_2 = Pxd_itm_int_.CastOrNull(data_ary[2]); if (itm_2 != null) { - if (Pxd_itm_int_.Year_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_y(tctx, itm_2)) return; } } - Pxd_itm_int_.Day_err(state, this); + Pxd_eval_seg.Eval_as_d(tctx, this); } - private void Eval_month_at_pos_2(Pxd_parser state) { - Pxd_itm[] data_ary = state.Data_ary(); + private void Eval_month_at_pos_2(Pxd_parser tctx) { + Pxd_itm[] data_ary = tctx.Data_ary(); Pxd_itm_int itm_0 = Pxd_itm_int_.CastOrNull(data_ary[0]); if (itm_0 != null) { - if (Pxd_itm_int_.Month_err(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_0)) return; } Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); if (itm_1 != null) { - if (Pxd_itm_int_.Day_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_d(tctx, itm_1)) return; } - Pxd_itm_int_.Year_err(state, this); + Pxd_eval_seg.Eval_as_y(tctx, this); } - private void Eval_unknown_at_pos_0(Pxd_parser state) { // NOTE: assumes dmy format - Pxd_itm[] data_ary = state.Data_ary(); - if (state.Data_ary_len() < 2) {state.Err_set(Pft_func_time_log.Invalid_year, Bry_fmtr_arg_.int_(val)); return;} + private void Eval_unknown_at_pos_0(Pxd_parser tctx) { // NOTE: assumes dmy format + Pxd_itm[] data_ary = tctx.Data_ary(); + if (tctx.Data_ary_len() < 2) {tctx.Err_set(Pft_func_time_log.Invalid_year, Bry_fmtr_arg_.int_(val)); return;} Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); if (itm_1 != null) { // if 1st itm to right is number, parse it as month - if (Pxd_itm_int_.Month_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_m(tctx, itm_1)) return; } - if (state.Data_ary_len() > 2) { + if (tctx.Data_ary_len() > 2) { Pxd_itm_int itm_2 = Pxd_itm_int_.CastOrNull(data_ary[2]); if (itm_2 != null) { // if 2nd itm to right is number, assume it as year - if (Pxd_itm_int_.Year_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_y(tctx, itm_2)) return; } } - Pxd_itm_int_.Day_err(state, this); // parse current as day (dmy format) - } - private void Eval_year_at_pos_0(Pxd_parser state) { - Pxd_itm[] data_ary = state.Data_ary(); - if (state.Data_ary_len() < 2) return; - Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); - if (itm_1 != null) { - if (Pxd_itm_int_.Month_err(state, itm_1)) return; - } - if (state.Data_ary_len() < 3) return; - Pxd_itm_int itm_2 = Pxd_itm_int_.CastOrNull(data_ary[2]); - if (itm_2 != null) { - if (Pxd_itm_int_.Day_err(state, itm_2)) return; - } - if (state.Data_ary_len() == 4) { // handle strange constructions like 2014-03-24-25; - Pxd_itm_int itm_3 = Pxd_itm_int_.CastOrNull(data_ary[3]); - if (itm_3 != null) { // treat 4th number as hour adjustment; EX: 2014-03-24-72 -> 2014-03-26; DATE:2014-03-24 - int itm_3_val = itm_3.Val(); - if (itm_3_val > 99) itm_3_val = 0; // only adjust if number is between 0 and 99; - Pxd_itm_int_.Convert_to_rel(state, itm_3, Pxd_parser_.Unit_name_hour, DateAdp_.SegIdx_hour, itm_3_val); - } - } - } - private void Eval_year_at_pos_2(Pxd_parser state) { - Pxd_itm[] data_ary = state.Data_ary(); - Pxd_itm_int itm_0 = Pxd_itm_int_.CastOrNull(data_ary[0]); - Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); - if (itm_0 == null || itm_1 == null) {return;} // trie: fail - if (itm_1.Val() > 13) { - if (Pxd_itm_int_.Month_err(state, itm_0)) return; - if (Pxd_itm_int_.Day_err(state, itm_1)) return; - } - else { - if (Pxd_itm_int_.Day_err(state, itm_0)) return; - if (Pxd_itm_int_.Month_err(state, itm_1)) return; - } + Pxd_eval_seg.Eval_as_d(tctx, this); // parse current as day (dmy format) } } class Pxd_itm_int_ { - public static void Convert_to_rel(Pxd_parser state, Pxd_itm_int itm, byte[] unit_name, int seg_idx, int rel_val) { + public static void Convert_to_rel(Pxd_parser tctx, Pxd_itm_int itm, byte[] unit_name, int seg_idx, int rel_val) { int tkn_idx = itm.Ary_idx(); - state.Tkns()[tkn_idx] = new Pxd_itm_unit(tkn_idx, unit_name, seg_idx, rel_val); + tctx.Tkns()[tkn_idx] = new Pxd_itm_unit(tkn_idx, unit_name, seg_idx, rel_val); } public static Pxd_itm_int CastOrNull(Pxd_itm itm) {return itm.Tkn_tid() == Pxd_itm_.Tid_int ? (Pxd_itm_int)itm : null; } public static Pxd_itm_int GetNearest(Pxd_itm[] tkns, int tkn_idx, boolean fwd) { @@ -279,7 +245,7 @@ class Pxd_itm_int_ { } return null; } - public static int Read_nearest_as_int_and_skip(Pxd_parser state, Pxd_itm[] tkns, int bgn, boolean fwd, int or) { + public static int Read_nearest_as_int_and_skip(Pxd_parser tctx, Pxd_itm[] tkns, int bgn, boolean fwd, int or) { int adj = 1, end = tkns.length; if (!fwd) { adj = -1; @@ -300,10 +266,10 @@ class Pxd_itm_int_ { if (itm_int_seg_idx == -1) { // not evaluated int factor = 1; if (dash_itm != null) { - state.Seg_idxs_((Pxd_itm_base)dash_itm, Pxd_itm_base.Seg_idx_skip, -1); + tctx.Seg_idxs_((Pxd_itm_base)dash_itm, Pxd_itm_base.Seg_idx_skip, -1); factor = -1; } - state.Seg_idxs_((Pxd_itm_base)itm, Pxd_itm_base.Seg_idx_skip, -1); + tctx.Seg_idxs_((Pxd_itm_base)itm, Pxd_itm_base.Seg_idx_skip, -1); return itm_int.Xto_int_or(or) * factor; } break; @@ -311,143 +277,23 @@ class Pxd_itm_int_ { } return or; } - public static boolean Year_err(Pxd_parser state, Pxd_itm_int itm) { - int val = itm.Val(); - switch (itm.Digits()) { - case 1: - case 2: - itm.Val_(val + (val > 69 ? 1900 : 2000)); // ASSUME that 70 refers to 1970 and 69 refers to 2069 - state.Seg_idxs_(itm, DateAdp_.SegIdx_year); - return false; - case 3: // NOTE: 3 digit numbers are valid years; MW relies on PHP time parse which always zero-pad numbers; PAGE:en.w:Battle of the Catalaunian Plains; {{#time:Y|June 20, 451}} - case 4: - state.Seg_idxs_(itm, DateAdp_.SegIdx_year); - return false; + public static Pxd_itm_int Get_int_bwd(Pxd_itm[] data_ary, int data_ary_len, int idx) { + if (idx > -1) { // make sure idx is > 0 + Pxd_itm rv = data_ary[idx]; // assume caller not passing in anything > ary.len + if ( rv.Tkn_tid() == Pxd_itm_.Tid_int // rv is int + && Pxd_itm_.Eval_needed(rv) // rv needs evaluation + ) + return (Pxd_itm_int)rv; // return it } - state.Err_set(Pft_func_time_log.Invalid_year, Bry_fmtr_arg_.int_(val)); - return true; + return null; } - public static boolean Month_err(Pxd_parser state, Pxd_itm_int itm) { - int val = itm.Val(); - switch (itm.Digits()) { - case 1: - case 2: - if (val > 0 && val < 13) { - state.Seg_idxs_(itm, DateAdp_.SegIdx_month); - return false; - } - else if (val == 0) {// 0 day means subtract 1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 - Pxd_itm_int_.Convert_to_rel(state, itm, Pxd_parser_.Unit_name_month, DateAdp_.SegIdx_month, -1); - return false; - } - break; + public static Pxd_itm Get_int_fwd(Pxd_itm[] data_ary, int data_ary_len, int idx) { + if (idx < data_ary_len) { + Pxd_itm rv = data_ary[idx]; + if ( rv.Tkn_tid() == Pxd_itm_.Tid_int + && rv.Seg_idx() == -1) + return rv; } - state.Err_set(Pft_func_time_log.Invalid_month, Bry_fmtr_arg_.int_(val)); - return true; + return null; } - public static boolean Day_err(Pxd_parser state, Pxd_itm_int itm) { - int val = itm.Val(); - switch (itm.Digits()) { - case 1: - case 2: - if (val > 0 && val < 32) { - state.Seg_idxs_(itm, DateAdp_.SegIdx_day); - return false; - } - else if (val == 0) { // 0 day means subtract 1; EX:w:Mariyinsky_Palace; DATE:2014-03-25 - Pxd_itm_int_.Convert_to_rel(state, itm, Pxd_parser_.Unit_name_day, DateAdp_.SegIdx_day, -1); - return false; - } - break; - } - state.Err_set(Pft_func_time_log.Invalid_day, Bry_fmtr_arg_.int_(val)); - return true; - } - public static boolean Hour_err(Pxd_parser state, Pxd_itm_int itm) { - int val = itm.Val(); - switch (itm.Digits()) { - case 1: - case 2: - if (val > -1 && val < 25) { - state.Seg_idxs_(itm, DateAdp_.SegIdx_hour, val); - return false; - } - break; - } - state.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.int_(val)); - return true; - } - public static boolean Min_err(Pxd_parser state, Pxd_itm_int itm) { - int val = itm.Val(); - switch (itm.Digits()) { - case 1: - case 2: - if (val > -1 && val < 60) { - state.Seg_idxs_(itm, DateAdp_.SegIdx_minute, val); - return false; - } - break; - } - state.Err_set(Pft_func_time_log.Invalid_minute, Bry_fmtr_arg_.int_(val)); - return true; - } - public static boolean Sec_err(Pxd_parser state, Pxd_itm_int itm) { - int val = itm.Val(); - switch (itm.Digits()) { - case 1: - case 2: - if (val > -1 && val < 60) { - state.Seg_idxs_(itm, DateAdp_.SegIdx_second); - return false; - } - break; - } - state.Err_set(Pft_func_time_log.Invalid_second, Bry_fmtr_arg_.int_(val)); - return true; - } - public static byte Tz_sym_err(Pxd_parser state, Pxd_itm[] tkns, Pxd_itm_int hour_itm) { - Pxd_itm sym = Pxd_itm_.Find_bwd__non_ws(tkns, hour_itm.Ary_idx()); - switch (sym.Tkn_tid()) { - case Pxd_itm_.Tid_sym: - Pxd_itm_sym sym_itm = (Pxd_itm_sym)sym; - if (sym_itm.Sym_byte() == Byte_ascii.Plus) - return Bool_.Y_byte; - break; - case Pxd_itm_.Tid_dash: return Bool_.N_byte; - } - state.Err_set(Pft_func_time_log.Invalid_timezone, Bry_fmtr_arg_.bry_("null")); - return Bool_.__byte; - } - public static boolean Tz_hour_err(Pxd_parser state, Pxd_itm_int itm, boolean negative) { - if (negative) itm.Val_(itm.Val() * -1); - int val = itm.Val(); - switch (itm.Digits()) { - case 1: - case 2: - if (val > -12 && val < 12) { - itm.Val_is_adj_(Bool_.Y); - itm.Seg_idx_(DateAdp_.SegIdx_hour); - return false; - } - break; - } - state.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.int_(val)); - return true; - } - public static boolean Tz_min_err(Pxd_parser state, Pxd_itm_int itm, boolean negative) { - int val = itm.Val(); - if (negative) val *= -1; - switch (itm.Digits()) { - case 1: - case 2: - if (val > -60 && val < 60) { - itm.Val_is_adj_(Bool_.Y); - itm.Seg_idx_(DateAdp_.SegIdx_minute); - return false; - } - break; - } - state.Err_set(Pft_func_time_log.Invalid_minute, Bry_fmtr_arg_.int_(val)); - return true; - } -} \ No newline at end of file +} diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_misc.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_misc.java index 217d4fd35..2545d066b 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_misc.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_misc.java @@ -27,25 +27,25 @@ class Pxd_itm_colon extends Pxd_itm_base { case 1: // hh:mm itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), Bool_.N); if (itm_int == null) {state.Err_set(Pft_func_time_log.Invalid_hour, Bry_fmtr_arg_.bry_("null")); return;} - if (Pxd_itm_int_.Hour_err(state, itm_int)) return; + if (!Pxd_eval_seg.Eval_as_h(state, itm_int)) return; itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), true); - if (Pxd_itm_int_.Min_err(state, itm_int)) return; + if (!Pxd_eval_seg.Eval_as_n(state, itm_int)) return; break; case 2: // :ss itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), true); - if (Pxd_itm_int_.Sec_err(state, itm_int)) return; + if (!Pxd_eval_seg.Eval_as_s(state, itm_int)) return; break; case 3: // +hh:mm; DATE:2014-08-26 itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), Bool_.N); if (itm_int == null) {state.Err_set(Pft_func_time_log.Invalid_timezone, Bry_fmtr_arg_.bry_("null")); return;} - byte tz_positive_val = Pxd_itm_int_.Tz_sym_err(state, tkns, itm_int); + byte tz_positive_val = Pxd_eval_seg.Eval_as_tz_sym(state, tkns, itm_int); if (tz_positive_val == Bool_.__byte) return; boolean tz_negative = tz_positive_val == Bool_.N_byte; - if (Pxd_itm_int_.Tz_hour_err(state, itm_int, tz_negative)) return; + if (!Pxd_eval_seg.Eval_as_tz_h(state, itm_int, tz_negative)) return; itm_int = Pxd_itm_int_.GetNearest(tkns, this.Ary_idx(), Bool_.Y); if (itm_int == null) {state.Err_set(Pft_func_time_log.Invalid_timezone, Bry_fmtr_arg_.bry_("null")); return;} if (tz_negative) itm_int.Val_(itm_int.Val() * -1); - if (Pxd_itm_int_.Tz_min_err(state, itm_int, tz_negative)) return; + if (!Pxd_eval_seg.Eval_as_tz_m(state, itm_int, tz_negative)) return; break; } } diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_month_name.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_month_name.java index 095b5c97e..013181ac2 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_month_name.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_itm_month_name.java @@ -54,8 +54,8 @@ class Pxd_itm_month_name extends Pxd_itm_base implements Pxd_itm_prototype { Pxd_itm_int itm_1 = Pxd_itm_int_.CastOrNull(data_ary[1]); if (itm_1 == null) {return;} // trie: fail switch (itm_1.Digits()) { - case 4: Pxd_itm_int_.Year_err(state, itm_1); break; - default: Pxd_itm_int_.Day_err(state, itm_1); break; + case 4: Pxd_eval_seg.Eval_as_y(state, itm_1); break; + default: Pxd_eval_seg.Eval_as_d(state, itm_1); break; } break; } @@ -65,10 +65,10 @@ class Pxd_itm_month_name extends Pxd_itm_base implements Pxd_itm_prototype { Pxd_itm_int itm_2 = Pxd_itm_int_.CastOrNull(data_ary[2]); if (itm_1 == null || itm_2 == null) {return;} // trie: fail if (itm_1.Digits() == 4) { // ASSUME: year since there are 4 digits; EX: May 2012 - if (!Pxd_itm_int_.Year_err(state, itm_1)) return; // no error; return; otherwise continue below; + if (Pxd_eval_seg.Eval_as_y(state, itm_1)) return; // no error; return; otherwise continue below; } - if (Pxd_itm_int_.Day_err(state, itm_1)) return; - if (Pxd_itm_int_.Year_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_d(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_y(state, itm_2)) return; break; } } @@ -81,8 +81,8 @@ class Pxd_itm_month_name extends Pxd_itm_base implements Pxd_itm_prototype { Pxd_itm_int itm_0 = Pxd_itm_int_.CastOrNull(data_ary[0]); if (itm_0 == null) {return;} // trie: fail switch (itm_0.Digits()) { - case 4: Pxd_itm_int_.Year_err(state, itm_0); break; - default: Pxd_itm_int_.Day_err(state, itm_0); break; + case 4: Pxd_eval_seg.Eval_as_y(state, itm_0); break; + default: Pxd_eval_seg.Eval_as_d(state, itm_0); break; } break; } @@ -93,17 +93,17 @@ class Pxd_itm_month_name extends Pxd_itm_base implements Pxd_itm_prototype { if (itm_0 == null || itm_2 == null) {return;} // trie: fail switch (itm_0.Digits()) { case 4: - if (Pxd_itm_int_.Year_err(state, itm_0)) return; - if (Pxd_itm_int_.Day_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_y(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_d(state, itm_2)) return; break; default: if (itm_2.Digits() == 4) { - if (Pxd_itm_int_.Day_err(state, itm_0)) return; - if (Pxd_itm_int_.Year_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_d(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_y(state, itm_2)) return; } else { // 2 digits on either side of month; assume dd mm yy; EX: 03 Feb 01 -> 2001-02-03 - if (Pxd_itm_int_.Day_err(state, itm_0)) return; - if (Pxd_itm_int_.Year_err(state, itm_2)) return; + if (!Pxd_eval_seg.Eval_as_d(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_y(state, itm_2)) return; } break; } @@ -121,17 +121,17 @@ class Pxd_itm_month_name extends Pxd_itm_base implements Pxd_itm_prototype { if (itm_0 == null || itm_1 == null) {return;} // trie: fail switch (itm_0.Digits()) { case 4: - if (Pxd_itm_int_.Year_err(state, itm_0)) return; - if (Pxd_itm_int_.Day_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_y(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_d(state, itm_1)) return; break; default: if (itm_1.Digits() == 4) { - if (Pxd_itm_int_.Day_err(state, itm_0)) return; - if (Pxd_itm_int_.Year_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_d(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_y(state, itm_1)) return; } else { // 2 digits on either side of month; assume dd mm yy; EX: 03 Feb 01 -> 2001-02-03 - if (Pxd_itm_int_.Day_err(state, itm_0)) return; - if (Pxd_itm_int_.Year_err(state, itm_1)) return; + if (!Pxd_eval_seg.Eval_as_d(state, itm_0)) return; + if (!Pxd_eval_seg.Eval_as_y(state, itm_1)) return; } break; } diff --git a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_parser.java b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_parser.java index 5d636bbcd..c8b64ba83 100644 --- a/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_parser.java +++ b/400_xowa/src/gplx/xowa/xtns/pfuncs/times/Pxd_parser.java @@ -40,11 +40,11 @@ class Pxd_parser { public void Err_set(Gfo_msg_itm itm, Bry_fmtr_arg... args) { if (itm == null) return; Bry_fmtr fmtr = itm.Fmtr(); - fmtr.Bld_bfr(errorBfr, args); - } private Bry_bfr errorBfr = Bry_bfr.new_(32); - public DateAdp Parse(byte[] src, Bry_bfr errorBfr) { + fmtr.Bld_bfr(error_bfr, args); + } private Bry_bfr error_bfr = Bry_bfr.new_(32); + public DateAdp Parse(byte[] src, Bry_bfr error_bfr) { Tokenize(src); // NOTE: should check if Tokenize failed, but want to be liberal as date parser is not fully implemented; this will always default to 1st day of year; DATE:2014-03-27 - return Evaluate(src, errorBfr); + return Evaluate(src, error_bfr); } private boolean Tokenize(byte[] src) { this.src = src; src_len = src.length; @@ -52,7 +52,7 @@ class Pxd_parser { tkn_type = Pxd_itm_.Tid_null; tkn_bgn_pos = -1; cur_pos = 0; Colon_count = 0; - errorBfr.Clear(); + error_bfr.Clear(); for (int i = 0; i < DateAdp_.SegIdx__max; i++) seg_idxs[i] = Pxd_itm_base.Seg_idx_null; while (cur_pos < src_len) { @@ -134,8 +134,8 @@ class Pxd_parser { MakeDataAry(); for (int i = 0; i < tkns_len; i++) { eval_ary[i].Eval(this); - if (errorBfr.Len() != 0) { - error.Add_bfr_and_clear(errorBfr); + if (error_bfr.Len() != 0) { + error.Add_bfr_and_clear(error_bfr); return DateAdp_.MinValue; } } diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java index 186312b42..3f6a0b353 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/Scrib_core.java @@ -161,7 +161,7 @@ public class Scrib_core { 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_utf8_(fnc_name)); KeyVal[] func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeModule"), func_args); // call init_chunk to get proc dynamically; DATE:2014-07-12 - if (func_rslt == null || func_rslt.length == 0) throw Err_.new_("lua.error:function did not return a value; fnc_name=~{0}", String_.new_utf8_(fnc_name)); + if (func_rslt == null || func_rslt.length < 2) throw Err_.new_("lua.error:function did not return a value; fnc_name=~{0}", String_.new_utf8_(fnc_name)); // must return at least 2 items for func_rslt[1] below; DATE:2014-09-22 Scrib_lua_proc proc = (Scrib_lua_proc)func_rslt[1].Val(); // note that init_chunk should have: [0]:true/false result; [1]:proc func_args = Scrib_kv_utl_.base1_many_(proc); func_rslt = engine.CallFunction(lib_mw.Mod().Fncs_get_id("executeFunction"), func_args); // call function now diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity_tst.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity_tst.java index 97d21d73f..e7e5fb0c8 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_entity_tst.java @@ -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_pages_add(wdata_fxt.page_bldr_("Q2").Props_add(wdata_fxt.prop_str_(3, "P3_val")).Xto_page_doc()); + wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_str(3, "P3_val")).Xto_wdoc()); wdata_fxt.Init_pids_add("en", "P3", 3); fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3"), "P3_val"); } diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java index 749181e18..9959a4cf7 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl.java @@ -27,8 +27,8 @@ class Scrib_lib_wikibase_srl { 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())); - Srl_root(rv, Wdata_doc_parser_v2.Str_descriptions , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Description_list())); - Srl_root(rv, Wdata_doc_parser_v2.Str_sitelinks , Srl_sitelinks (Wdata_dict_sitelink.Str_site , Wdata_dict_sitelink.Str_title, wdoc.Sitelink_list())); + Srl_root(rv, Wdata_doc_parser_v2.Str_descriptions , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Descr_list())); + Srl_root(rv, Wdata_doc_parser_v2.Str_sitelinks , Srl_sitelinks (Wdata_dict_sitelink.Str_site , Wdata_dict_sitelink.Str_title, wdoc.Slink_list())); Srl_root(rv, Wdata_doc_parser_v2.Str_aliases , Srl_aliases (base_adj, wdoc.Alias_list())); Srl_root(rv, Wdata_doc_parser_v2.Str_claims , Srl_claims (base_adj, legacy_style, wdoc.Claim_list())); return (KeyVal[])rv.XtoAry(KeyVal.class); @@ -93,10 +93,10 @@ class Scrib_lib_wikibase_srl { return rv; } private static KeyVal[] Srl_claims_prop_grp(String pid, Wdata_claim_grp grp, int base_adj) { - int len = grp.Itms_len(); + int len = grp.Len(); KeyVal[] rv = new KeyVal[len]; for (int i = 0; i < len; i++) { - Wdata_claim_itm_core itm = grp.Itms_get_at(i); + Wdata_claim_itm_core itm = grp.Get_at(i); rv[i] = KeyVal_.int_(i + base_adj, Srl_claims_prop_itm(pid, itm)); // NOTE: must be super 0 or super 1; DATE:2014-05-09 } return rv; @@ -107,8 +107,27 @@ class Scrib_lib_wikibase_srl { list.Add(KeyVal_.new_("mainsnak", Srl_claims_prop_itm_core(pid, itm))); list.Add(KeyVal_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid()))); list.Add(KeyVal_.new_("type", itm.Prop_type())); + Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(itm.Qualifiers())); return (KeyVal[])list.XtoAryAndClear(KeyVal.class); } + private static KeyVal[] Srl_qualifiers(Wdata_claim_grp_list list) { + if (list == null) return null; + int list_len = list.Len(); if (list_len == 0) return KeyVal_.Ary_empty; + ListAdp rv = ListAdp_.new_(); + ListAdp pid_list = ListAdp_.new_(); + for (int i = 0; i < list_len; ++i) { + Wdata_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); + pid_list.Add(KeyVal_.int_(j + ListAdp_.Base1, Srl_claims_prop_itm_core(itm_pid, itm))); + } + rv.Add(KeyVal_.new_(itm_pid, (KeyVal[])pid_list.XtoAryAndClear(KeyVal.class))); + } + return (KeyVal[])rv.XtoAryAndClear(KeyVal.class); + } private static KeyVal[] Srl_claims_prop_itm_core(String pid, Wdata_claim_itm_core itm) { KeyVal[] rv = new KeyVal[3]; rv[0] = KeyVal_.new_("datavalue", Srl_claims_prop_itm_core_val(itm)); diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java index 689c28ae9..fbd01f9a1 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_srl_tst.java @@ -118,9 +118,9 @@ public class Scrib_lib_wikibase_srl_tst { , " value:'de_1'" , "" ); - } + } @Test public void Claims_str() { - fxt.Init_prop(fxt.Wdata_fxt().prop_str_(2, "Moon")); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_str(2, "Moon")); fxt.Test ( "claims:" , " P2:" @@ -138,7 +138,7 @@ public class Scrib_lib_wikibase_srl_tst { ); } @Test public void Claims_somevalue() { // PURPOSE: somevalue should always return value node; EX:w:Joseph-François_Malgaigne; DATE:2014-04-07 - fxt.Init_prop(fxt.Wdata_fxt().prop_somevalue_(2)); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_somevalue(2)); fxt.Test ( "claims:" , " P2:" @@ -156,7 +156,7 @@ public class Scrib_lib_wikibase_srl_tst { ); } @Test public void Claims_entity() { - fxt.Init_prop(fxt.Wdata_fxt().prop_entity_(2, 3)); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_entity(2, 3)); fxt.Test ( "claims:" , " P2:" @@ -176,7 +176,7 @@ public class Scrib_lib_wikibase_srl_tst { ); } @Test public void Claims_base_0() { // PURPOSE: test for legacyStyle (aka base_0); used by pl.w:Module:Wikidane; DATE:2014-05-09 - fxt.Init_prop(fxt.Wdata_fxt().prop_entity_(2, 3)); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_entity(2, 3)); fxt.Test(true , "claims:" , " P2:" @@ -209,7 +209,7 @@ public class Scrib_lib_wikibase_srl_tst { ); } @Test public void Claims_time() { - fxt.Init_prop(fxt.Wdata_fxt().prop_time_(2, "2001-02-03 04:05:06")); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_time(2, "2001-02-03 04:05:06")); fxt.Test ( "claims:" , " P2:" @@ -233,7 +233,7 @@ public class Scrib_lib_wikibase_srl_tst { ); } @Test public void Claims_globecoordinate() { - fxt.Init_prop(fxt.Wdata_fxt().prop_geodata_(2, "1.2345", "6.789")); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_geo(2, "1.2345", "6.789")); fxt.Test ( "claims:" , " P2:" @@ -256,7 +256,7 @@ public class Scrib_lib_wikibase_srl_tst { ); } @Test public void Claims_quantity() { - fxt.Init_prop(fxt.Wdata_fxt().prop_quantity_(2, "+1,234", "2", "+1,236", "+1232")); + fxt.Init_prop(fxt.Wdata_fxt().Make_claim_quantity(2, "+1,234", "2", "+1,236", "+1232")); fxt.Test ( "claims:" , " P2:" @@ -277,38 +277,71 @@ 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.Test + ( "claims:" + , " P2:" + , " 1:" + , " id:null" + , " mainsnak:" + , " datavalue:" + , " type:'string'" + , " value:'Earth'" + , " property:'P2'" + , " snaktype:'value'" + , " rank:'normal'" + , " type:'statement'" + , " qualifiers:" + , " P3:" + , " 1:" + , " datavalue:" + , " type:'time'" + , " value:" + , " time:'+00000002001-02-03T04:05:06Z'" + , " precision:'11'" + , " before:'0'" + , " after:'0'" + , " timezone:'0'" + , " calendarmodel:'http://www.wikidata.org/entity/Q1985727'" + , " property:'P3'" + , " snaktype:'value'" + , "" + ); + } } class Scrib_lib_wikibase_srl_fxt { + private Wdata_doc_bldr wdoc_bldr; public void Clear() { wdata_fxt = new Wdata_wiki_mgr_fxt(); wdata_fxt.Init(); - doc_bldr = wdata_fxt.page_bldr_("q2"); + wdoc_bldr = wdata_fxt.Wdoc_bldr("q2"); header_enabled = false; } public Wdata_wiki_mgr_fxt Wdata_fxt() {return wdata_fxt;} private Wdata_wiki_mgr_fxt wdata_fxt; - private Wdata_doc_bldr doc_bldr; private boolean header_enabled; public Scrib_lib_wikibase_srl_fxt Init_header_enabled_y_() {header_enabled = true; return this;} public Scrib_lib_wikibase_srl_fxt Init_label(String lang, String label) { - doc_bldr.Label_add(lang, label); + wdoc_bldr.Add_label(lang, label); return this; } public Scrib_lib_wikibase_srl_fxt Init_description(String lang, String description) { - doc_bldr.Description_add(lang, description); + wdoc_bldr.Add_description(lang, description); return this; } public Scrib_lib_wikibase_srl_fxt Init_link(String xwiki, String val) { - doc_bldr.Link_add(xwiki, val); + wdoc_bldr.Add_sitelink(xwiki, val); return this; } public Scrib_lib_wikibase_srl_fxt Init_alias(String lang, String... ary) { - doc_bldr.Alias_add(lang, ary); + wdoc_bldr.Add_alias(lang, ary); return this; } - public Scrib_lib_wikibase_srl_fxt Init_prop(Wdata_claim_itm_core prop) {doc_bldr.Props_add(prop); 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 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(doc_bldr.Xto_page_doc(), header_enabled, base0); + KeyVal[] actl = Scrib_lib_wikibase_srl.Srl(wdoc_bldr.Xto_wdoc(), header_enabled, base0); Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl))); return this; } diff --git a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_tst.java b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_tst.java index eef3898b5..744f4fd12 100644 --- a/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/scribunto/lib/Scrib_lib_wikibase_tst.java @@ -34,7 +34,7 @@ public class Scrib_lib_wikibase_tst { } @Test public void GetEntity() { Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false); - wdata_fxt.Init_pages_add(wdata_fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc()); + wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc()); fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl_skip_last ( "1=" , " id=q2" @@ -48,7 +48,7 @@ public class Scrib_lib_wikibase_tst { } @Test public void GetEntity_property() { // PURPOSE: getEntity should be able to convert "p2" to "Property:P2"; EX:es.w:Arnold_Gesell; DATE:2014-02-18 Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false); - wdata_fxt.Init_pages_add(wdata_fxt.page_bldr_("Property:p2").Label_add("en", "b").Xto_page_doc()); + wdata_fxt.Init_pages_add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("en", "b").Xto_wdoc()); fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("p2", false), String_.Concat_lines_nl_skip_last ( "1=" , " id=Property:p2" // only difference from above diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java index 4f5410001..de21ab0e1 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc.java @@ -18,15 +18,24 @@ along with this program. If not, see . package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; public class Wdata_doc { - public Wdata_doc(byte[] qid, Wdata_wiki_mgr mgr, Json_doc jdoc) {this.qid = qid; this.mgr = mgr; this.jdoc = jdoc;} private Wdata_wiki_mgr mgr; + 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, OrderedHash slink_list, OrderedHash label_list, OrderedHash descr_list, OrderedHash alias_list, OrderedHash 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 OrderedHash Sitelink_list() {if (sitelink_list == null) sitelink_list = mgr.Wdoc_parser(jdoc).Parse_sitelinks(qid, jdoc); return sitelink_list;} private OrderedHash sitelink_list; - public OrderedHash Label_list() {if (label_list == null) label_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.Y); return label_list;} private OrderedHash label_list; - public OrderedHash Description_list() {if (description_list == null) description_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return description_list;} private OrderedHash description_list; - public OrderedHash Alias_list() {if (alias_list == null) alias_list = mgr.Wdoc_parser(jdoc).Parse_aliases(qid, jdoc); return alias_list;} private OrderedHash alias_list; - public OrderedHash Claim_list() {if (claim_list == null) claim_list = mgr.Wdoc_parser(jdoc).Parse_claims(jdoc); return claim_list;} private OrderedHash claim_list; - public Wdata_claim_grp Claim_list_get(int pid) {return (Wdata_claim_grp)this.Claim_list().Fetch(mgr.Tmp_prop_ref().Val_(pid));} + public OrderedHash Slink_list() {if (slink_list == null) slink_list = mgr.Wdoc_parser(jdoc).Parse_sitelinks(qid, jdoc); return slink_list;} private OrderedHash slink_list; + public OrderedHash Label_list() {if (label_list == null) label_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.Y); return label_list;} private OrderedHash label_list; + public OrderedHash Descr_list() {if (descr_list == null) descr_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return descr_list;} private OrderedHash descr_list; + public OrderedHash Alias_list() {if (alias_list == null) alias_list = mgr.Wdoc_parser(jdoc).Parse_aliases(qid, jdoc); return alias_list;} private OrderedHash alias_list; + public OrderedHash Claim_list() {if (claim_list == null) claim_list = mgr.Wdoc_parser(jdoc).Parse_claims(qid, jdoc); return claim_list;} private OrderedHash claim_list; + public Wdata_claim_grp Claim_list_get(int pid) { + if (tmp_key == null) tmp_key = Int_obj_ref.neg1_(); + Object o = this.Claim_list().Fetch(tmp_key.Val_(pid)); + return (Wdata_claim_grp)o; + } public byte[] Label_list_get(byte[] lang_key) { Object rv_obj = this.Label_list().Fetch(lang_key); if (rv_obj == null) return null; Wdata_langtext_itm rv = (Wdata_langtext_itm)rv_obj; diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_.java deleted file mode 100644 index 7e037a9dc..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_.java +++ /dev/null @@ -1,48 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; -public class Wdata_doc_ { - public static byte[] Link_extract(Json_itm_kv kv) { - Json_itm kv_val = kv.Val(); - switch (kv_val.Tid()) { - case Json_itm_.Tid_string: // "enwiki":"Earth" - return kv_val.Data_bry(); - case Json_itm_.Tid_nde: // "enwiki":{name:"Earth", badges:[]} - Json_itm_nde kv_val_as_nde = (Json_itm_nde)kv_val; - Json_itm_kv name_itm = (Json_itm_kv)kv_val_as_nde.Subs_get_by_key(Key_name); - return name_itm.Val().Data_bry(); - default: - throw Err_.unhandled(kv_val.Tid()); - } - } - public static byte[] Entity_extract(Json_doc doc) { - Json_itm kv_val = doc.Find_nde(Wdata_doc_consts.Key_atr_entity_bry); - switch (kv_val.Tid()) { - case Json_itm_.Tid_string: // "entity":"q1" - return kv_val.Data_bry(); - case Json_itm_.Tid_array: // "entity":["item",1] - Json_itm_ary kv_val_as_ary = (Json_itm_ary)kv_val; - Json_itm entity_id = kv_val_as_ary.Subs_get_at(1); - return Bry_.Add(Byte_ascii.Ltr_q, entity_id.Data_bry()); - default: - throw Err_.unhandled(kv_val.Tid()); - } - } - public static final byte[] Key_name = Bry_.new_ascii_("name"); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java index 3a5c1d454..78a02994c 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_bldr.java @@ -18,194 +18,26 @@ along with this program. If not, see . package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; public class Wdata_doc_bldr { - public Wdata_doc_bldr(Wdata_wiki_mgr mgr) {this.mgr = mgr;} Wdata_wiki_mgr mgr; - public Wdata_doc_bldr Qid_(String v) {this.qid = Bry_.new_ascii_(v); return this;} private byte[] qid; ListAdp props = ListAdp_.new_(); - public Wdata_doc_bldr Props_add(Wdata_claim_itm_core... ary) { - int len = ary.length; - for (int i = 0; i < len; i++) - props.Add(ary[i]); + private OrderedHash 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_ascii_(v); return this;} private byte[] qid; + public Wdata_doc_bldr Add_claims(Wdata_claim_itm_core... ary) { + if (ary.length == 0) throw Err_.new_("claims must be greater than 0"); + Wdata_claim_itm_core itm = ary[0]; + Wdata_claim_grp grp = new Wdata_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_utf8_(lang); descr_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_utf8_(text))); return this;} + public Wdata_doc_bldr Add_label(String lang, String text) {byte[] key = Bry_.new_utf8_(lang); label_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_utf8_(text))); return this;} + public Wdata_doc_bldr Add_sitelink(String site, String ttl) {byte[] key = Bry_.new_utf8_(site); slink_list.Add(key, new Wdata_sitelink_itm(key, Bry_.new_utf8_(ttl), Bry_.Ary_empty)); return this;} + public Wdata_doc_bldr Add_alias(String lang, String... ary){byte[] key = Bry_.new_utf8_(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; } - public static byte[] Xto_time(String date) {return Xto_time(DateAdp_.parse_fmt(date, "yyyy-MM-dd HH:mm:ss"));} - public static byte[] Xto_time(DateAdp date) { - // +0000000yyyy-MM-ddTHH:mm:ssZ - tmp_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 tmp_bfr.XtoAryAndClear(); - } private static Bry_bfr tmp_bfr = Bry_bfr.new_(); private static byte[] Bry_year_prefix = Bry_.new_ascii_("+0000000"); - public Wdata_doc_bldr Description_add(String lang, String val) {descriptions.Add(KeyVal_.new_(lang, val)); return this;} ListAdp descriptions = ListAdp_.new_(); - public Wdata_doc_bldr Label_add(String lang, String val) {labels.Add(KeyVal_.new_(lang, val)); return this;} ListAdp labels = ListAdp_.new_(); - public Wdata_doc_bldr Link_add(String xwiki, String ttl) {links.Add(KeyVal_.new_(xwiki, ttl)); return this;} ListAdp links = ListAdp_.new_(); - public Wdata_doc_bldr Alias_add(String lang, String[] ary) { - aliases.AddReplace(lang, new Wdata_doc_alias(lang, ary)); - return this; - } OrderedHash aliases = OrderedHash_.new_(); - public byte[] Xto_bry() { - wtr.Nde_bgn(); - wtr.Kv(Bool_.N, Wdata_doc_parser_v1.Bry_entity, qid); - Xto_bry__list(Wdata_doc_parser_v1.Bry_label, labels); - Xto_bry__list(Wdata_doc_parser_v1.Bry_description, descriptions); - Xto_bry__sitelinks(Wdata_doc_parser_v1.Bry_links, links); - Xto_bry__aliases(); - Xto_bry__claims(); - wtr.Nde_end(); - return wtr.Bld(); - } Json_doc_wtr wtr = new Json_doc_wtr(); - private void Xto_bry__list(byte[] key, ListAdp 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.FetchAt(i); - wtr.Kv(i != 0, Bry_.new_utf8_(kv.Key()), Bry_.new_utf8_(kv.Val_to_str_or_empty())); - } - wtr.Nde_end(); - list.Clear(); + private void Init() { + descr_list = OrderedHash_.new_bry_(); label_list = OrderedHash_.new_bry_(); slink_list = OrderedHash_.new_bry_(); alias_list = OrderedHash_.new_bry_(); claim_list = OrderedHash_.new_(); } - private void Xto_bry__sitelinks(byte[] key, ListAdp 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.FetchAt(i); - wtr.Key(false, Bry_.new_utf8_(kv.Key())); // write key; EX: enwiki: - wtr.Nde_bgn(); // bgn nde; EX: { - wtr.Kv(false, Wdata_doc_parser_v1.Bry_name, Bry_.new_utf8_(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() { - 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_doc_alias alias = (Wdata_doc_alias)aliases.FetchAt(i); - wtr.Key(i != 0, Bry_.new_utf8_(alias.Lang())); - wtr.Ary_bgn(); - String[] aliases_ary = alias.Aliases(); - int aliases_len = aliases_ary.length; - for (int j = 0; j < aliases_len; j++) { - String aliases_str = aliases_ary[j]; - wtr.Val(j != 0, Bry_.new_utf8_(aliases_str)); - } - wtr.Ary_end(); - } - wtr.Nde_end(); - aliases.Clear(); - } - private void Xto_bry__claims() { - 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(); - Wdata_claim_itm_core prop = (Wdata_claim_itm_core)props.FetchAt(i); - wtr.Nde_bgn(); - wtr.Key(false, Wdata_dict_claim_v1.Bry_m); - wtr.Ary_bgn(); - wtr.Val(Bool_.N, Wdata_dict_snak_tid.Xto_bry(prop.Snak_tid())); - wtr.Val(Bool_.Y, prop.Pid()); - if (prop.Snak_tid() == Wdata_dict_snak_tid.Tid_value) { - switch (prop.Val_tid()) { - case Wdata_dict_val_tid.Tid_string: - Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)prop; - wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_string); - wtr.Val(Bool_.Y, claim_str.Val_str()); - break; - case Wdata_dict_val_tid.Tid_entity: - Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)prop; - wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_entity); - wtr.Comma(); - wtr.Nde_bgn(); - wtr.Kv(Bool_.N, Wdata_dict_value_entity.Bry_entity_type , Wdata_dict_value_entity.Val_entity_type_item_bry); - wtr.Kv(Bool_.Y, Wdata_dict_value_entity.Bry_numeric_id , claim_entity.Entity_id()); - wtr.Nde_end(); - break; - case Wdata_dict_val_tid.Tid_time: - Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)prop; - wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_time); - wtr.Comma(); - wtr.Nde_bgn(); - wtr.Kv(Bool_.N, Wdata_dict_value_time.Bry_time , claim_time.Time()); - wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_precision , Wdata_dict_value_time.Val_timezone_bry); - wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_before , Wdata_dict_value_time.Val_before_bry); - wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_after , Wdata_dict_value_time.Val_after_bry); - wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_timezone , Wdata_dict_value_time.Val_timezone_bry); - wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_bry); - wtr.Nde_end(); - break; - case Wdata_dict_val_tid.Tid_globecoordinate: { - Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)prop; - wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_globecoordinate); - wtr.Comma(); - wtr.Nde_bgn(); - wtr.Kv_double (Bool_.N, Wdata_dict_value_globecoordinate.Bry_latitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lat()))); - wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_longitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lng()))); - wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_altitude , null); - wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_bry); - wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_precision , .00001d); - wtr.Nde_end(); - break; - } - case Wdata_dict_val_tid.Tid_quantity: { - Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)prop; - wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_quantity); - wtr.Comma(); - wtr.Nde_bgn(); - wtr.Kv (Bool_.N, Wdata_dict_value_quantity.Bry_amount , claim_quantity.Amount()); // +1,234 - wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_unit , claim_quantity.Unit()); // 1 - wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_upperbound , claim_quantity.Ubound()); // +1,235 - wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_lowerbound , claim_quantity.Lbound()); // +1,233 - wtr.Nde_end(); - break; - } - case Wdata_dict_val_tid.Tid_monolingualtext: { - Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)prop; - wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_monolingualtext); - wtr.Comma(); - wtr.Nde_bgn(); - wtr.Kv (Bool_.N, Wdata_dict_value_monolingualtext.Bry_text , claim_monolingualtext.Text()); // text - wtr.Kv (Bool_.Y, Wdata_dict_value_monolingualtext.Bry_language , claim_monolingualtext.Lang()); // en - wtr.Nde_end(); - break; - } - default: throw Err_.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, Wdata_dict_rank.Tid_normal); - wtr.Kv_ary_empty(Bool_.Y, Wdata_dict_claim_v1.Bry_refs); - wtr.Nde_end(); - } - wtr.Ary_end(); - props.Clear(); - } - public Wdata_doc Xto_page_doc() {return new Wdata_doc(qid, mgr, mgr.Jdoc_parser().Parse(Xto_bry()));} -} -class Wdata_doc_alias { - public Wdata_doc_alias(String lang, String[] aliases) {this.lang = lang; this.aliases = aliases;} - public String Lang() {return lang;} private String lang; - public String[] Aliases() {return aliases;} private String[] aliases; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_consts.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_consts.java deleted file mode 100644 index 9ed1aa78e..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_consts.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -public class Wdata_doc_consts { - public static final String - Key_atr_entity_str = "entity", Key_atr_label_str = "label", Key_atr_description_str = "description", Key_atr_aliases_str = "aliases" - , Key_atr_links_str = "links", Key_atr_claims_str = "claims" - , Key_claims_m_str = "m", Key_claims_q_str = "q", Key_claims_g_str = "g", Key_claims_rank_str = "rank", Key_claims_refs_str = "refs" - , Key_ent_entity_type_str = "entity-type", Key_ent_numeric_id_str = "numeric-id" - , Val_ent_entity_type_item_str = "item" - , Val_prop_value_str = "value", Val_prop_novalue_str = "novalue", Val_prop_somevalue_str = "somevalue" - , Key_time_time_str = "time", Key_time_precision_str = "precision", Key_time_before_str = "before", Key_time_after_str = "after", Key_time_timezone_str = "timezone", Key_time_calendarmodel_str = "calendarmodel" - , Val_time_precision_str = "11", Val_time_before_str = "0", Val_time_after_str = "0", Val_time_timezone_str = "0" - , Val_time_globe_str = "http:\\/\\/www.wikidata.org\\/entity\\/Q2", Val_time_calendarmodel_str = "http://www.wikidata.org/entity/Q1985727" - , Key_geo_type_str = "globecoordinate", Key_geo_latitude_str = "latitude", Key_geo_longitude_str = "longitude", Key_geo_altitude_str = "altitude" - , Key_geo_globe_str = "globe", Key_geo_precision_str = "precision" - , Key_quantity_type_str = "quantity", Key_quantity_amount_str = "amount", Key_quantity_unit_str = "unit" - , Key_quantity_ubound_str = "upperBound", Key_quantity_lbound_str = "lowerBound" - , Key_monolingualtext_language_str = "language", Key_monolingualtext_text_str = "text" - ; - public static final int - Val_time_precision_int = 11, Val_time_before_int = 0, Val_time_after_int = 0, Val_time_timezone_int = 0; - public static final byte[] - Key_atr_entity_bry = bry_(Key_atr_entity_str), Key_atr_label_bry = bry_(Key_atr_label_str), Key_atr_description_bry = bry_(Key_atr_description_str), Key_atr_aliases_bry = bry_(Key_atr_aliases_str) - , Key_atr_links_bry = bry_(Key_atr_links_str), Key_atr_claims_bry = bry_(Key_atr_claims_str) - , Key_claims_g_bry = bry_(Key_claims_g_str), Key_claims_m_bry = bry_(Key_claims_m_str), Key_claims_q_bry = bry_(Key_claims_q_str), Key_claims_rank_bry = bry_(Key_claims_rank_str), Key_claims_refs_bry = bry_(Key_claims_refs_str) - - , Key_ent_entity_type_bry = bry_(Key_ent_entity_type_str), Key_ent_numeric_id_bry = bry_(Key_ent_numeric_id_str) - , Val_ent_entity_type_item_bry = bry_(Val_ent_entity_type_item_str) - , Val_prop_value_bry = bry_(Val_prop_value_str), Val_prop_novalue_bry = bry_(Val_prop_novalue_str), Val_prop_somevalue_bry = bry_(Val_prop_somevalue_str) - , Key_time_time_bry = bry_(Key_time_time_str), Key_time_timezone_bry = bry_(Key_time_timezone_str), Key_time_before_bry = bry_(Key_time_before_str), Key_time_after_bry = bry_(Key_time_after_str) - , Key_time_precision_bry = bry_(Key_time_precision_str), Key_time_calendarmodel_bry = bry_(Key_time_calendarmodel_str) - , Val_time_precision_bry = bry_(Val_time_precision_str), Val_time_before_bry = bry_(Val_time_before_str), Val_time_after_bry = bry_(Val_time_after_str), Val_time_timezone_bry = bry_(Val_time_timezone_str) - , Val_time_calendarmodel_bry = bry_(Val_time_timezone_str), Val_time_globe_bry = bry_(Val_time_globe_str) - , Key_geo_latitude_bry = bry_(Key_geo_latitude_str), Key_geo_longitude_bry = bry_(Key_geo_longitude_str), Key_geo_altitude_bry = bry_(Key_geo_altitude_str) - , Key_geo_globe_bry = bry_(Key_geo_globe_str), Key_geo_precision_bry = bry_(Key_geo_precision_str) - , Key_quantity_amount_bry = bry_(Key_quantity_amount_str), Key_quantity_unit_bry = bry_(Key_quantity_unit_str) - , Key_quantity_ubound_bry = bry_(Key_quantity_ubound_str), Key_quantity_lbound_bry = bry_(Key_quantity_lbound_str) - , Key_monolingualtext_language_bry = bry_(Key_monolingualtext_language_str), Key_monolingualtext_text_bry = bry_(Key_monolingualtext_text_str) - ; - private static byte[] bry_(String s) {return Bry_.new_ascii_(s);} -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_parser.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_parser.java deleted file mode 100644 index 040feba8a..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_parser.java +++ /dev/null @@ -1,147 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; -public class Wdata_doc_parser { - public Wdata_doc_parser(Gfo_usr_dlg usr_dlg) {this.usr_dlg = usr_dlg;} private Gfo_usr_dlg usr_dlg; - public OrderedHash Bld_hash(Json_doc doc, byte[] key) { - Json_itm_nde nde = Json_itm_nde.cast_(doc.Get_grp(key)); if (nde == null) return Empty_ordered_hash_bry; - OrderedHash rv = OrderedHash_.new_bry_(); - int len = nde.Subs_len(); - for (int i = 0; i < len; i++) { - Json_itm_kv kv = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte[] kv_key = kv.Key().Data_bry(); - rv.Add(kv_key, kv); - } - return rv; - } - public OrderedHash Bld_props(Json_doc doc) { - Json_itm_ary claims_nde = Json_itm_ary.cast_(doc.Get_grp(Wdata_doc_consts.Key_atr_claims_bry)); if (claims_nde == null) return Empty_ordered_hash_generic; - return Bld_props(doc.Src(), claims_nde); - } - public OrderedHash Bld_props(byte[] src, Json_itm_ary claims_nde) { - OrderedHash hash = OrderedHash_.new_(); - int len = claims_nde.Subs_len(); - for (int i = 0; i < len; i++) { - Json_itm_nde prop_nde = Json_itm_nde.cast_(claims_nde.Subs_get_at(i)); - Wdata_prop_itm_core prop_itm = New_prop(src, prop_nde); - Int_obj_ref prop_itm_id = Int_obj_ref.new_(prop_itm.Pid()); - Wdata_prop_grp prop_grp = (Wdata_prop_grp)hash.Fetch(prop_itm_id); - if (prop_grp == null) { - prop_grp = new Wdata_prop_grp(prop_itm_id); - hash.Add(prop_itm_id, prop_grp); - } - prop_grp.Itms_add(prop_itm); - } - len = hash.Count(); - OrderedHash rv = OrderedHash_.new_(); - for (int i = 0; i < len; i++) { - Wdata_prop_grp grp = (Wdata_prop_grp)hash.FetchAt(i); - grp.Itms_make(); - rv.Add(grp.Id_ref(), grp); - } - return rv; - } - private Wdata_prop_itm_core New_prop(byte[] src, Json_itm_nde prop_nde) { - int len = prop_nde.Subs_len(); // should have 5 (m, q, g, rank, refs), but don't enforce (can rely on keys) - Wdata_prop_itm_core rv = null; - for (int i = 0; i < len; i++) { - Json_itm_kv kv = Json_itm_kv.cast_(prop_nde.Subs_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_utf8_mid_safe_(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_itm_ary.cast_(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_.unhandled(bv.Val()); - } - } - return rv; - } - private Wdata_prop_itm_core New_prop_by_m(byte[] src, Json_itm_ary ary) { - byte snak_tid = Wdata_prop_itm_base_.Snak_tid_parse(ary.Subs_get_at(0).Data_bry()); - int pid = Json_itm_int.cast_(ary.Subs_get_at(1)).Data_as_int(); - switch (snak_tid) { - case Wdata_prop_itm_base_.Snak_tid_novalue : return Wdata_prop_itm_core.new_novalue_(pid); - case Wdata_prop_itm_base_.Snak_tid_somevalue : return Wdata_prop_itm_core.new_somevalue_(pid); - } - Json_itm val_tid_itm = ary.Subs_get_at(2); - byte val_tid = Wdata_prop_itm_base_.Val_tid_parse(src, val_tid_itm.Src_bgn(), val_tid_itm.Src_end()); - byte[] val_bry = Parse_val(ary, val_tid); - return new Wdata_prop_itm_core(snak_tid, pid, val_tid, val_bry); - } - private byte[] Parse_val(Json_itm_ary ary, byte val_tid) { - switch (val_tid) { - case Wdata_prop_itm_base_.Val_tid_string: - return ary.Subs_get_at(3).Data_bry(); - case Wdata_prop_itm_base_.Val_tid_entity: { - Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); - Json_itm_kv entity_kv = Json_itm_kv.cast_(sub_nde.Subs_get_at(1)); - return entity_kv.Val().Data_bry(); - } - case Wdata_prop_itm_base_.Val_tid_time: { - Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); - Json_itm_kv entity_kv = Json_itm_kv.cast_(sub_nde.Subs_get_at(0)); - return entity_kv.Val().Data_bry(); - } - case Wdata_prop_itm_base_.Val_tid_globecoordinate: case Wdata_prop_itm_base_.Val_tid_bad: { - Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); - return Add_kvs(tmp_parse_bfr, sub_nde, 0, 2); - } - case Wdata_prop_itm_base_.Val_tid_quantity: { - Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); - return Add_kvs(tmp_parse_bfr, sub_nde, 0, 4); - } - case Wdata_prop_itm_base_.Val_tid_monolingualtext: { - Json_itm_nde sub_nde = Json_itm_nde.cast_(ary.Subs_get_at(3)); - return Add_kvs(tmp_parse_bfr, sub_nde, 0, 2); - } - default: {throw Err_.unhandled(val_tid);} - } - } - private Bry_bfr tmp_parse_bfr = Bry_bfr.reset_(32); - private static byte[] Add_kvs(Bry_bfr bfr, Json_itm_nde sub_nde, int bgn, int end) { - for (int i = bgn; i < end; i++) { - Json_itm_kv kv = Json_itm_kv.cast_(sub_nde.Subs_get_at(i)); - if (i != 0) bfr.Add_byte(Wdata_prop_itm_core.Prop_dlm); - bfr.Add(kv.Val().Data_bry()); - } - return bfr.XtoAryAndClear(); - } - private void Warn(String fmt, Object... args) {usr_dlg.Warn_many("", "", fmt, args);} - public static final OrderedHash Empty_ordered_hash_bry = OrderedHash_.new_bry_(), Empty_ordered_hash_generic = OrderedHash_.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_ascii_() - .Add_bry_byte(Wdata_doc_consts.Key_claims_m_bry , Prop_tid_m) - .Add_bry_byte(Wdata_doc_consts.Key_claims_q_bry , Prop_tid_q) - .Add_bry_byte(Wdata_doc_consts.Key_claims_g_bry , Prop_tid_g) - .Add_bry_byte(Wdata_doc_consts.Key_claims_rank_bry , Prop_tid_rank) - .Add_bry_byte(Wdata_doc_consts.Key_claims_refs_bry , Prop_tid_refs); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_parser_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_parser_tst.java deleted file mode 100644 index 451c0dcc4..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_parser_tst.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import org.junit.*; -import gplx.json.*; -public class Wdata_doc_parser_tst { - @Test public void Invalid_type__bad() { // wikidata flags several entries as "bad"; https://www.wikidata.org/wiki/Wikidata:Project_chat/Archive/2013/10 - Json_doc jdoc = Json_doc.new_apos_concat_nl - ( "{ 'entity':['item',2]" - , ", 'claims':" - , " [" - , " { 'm':" - , " [ 'value'" - , " , 373" - , " , 'bad'" - , " ," - , " { 'latitude':1" - , " , 'longitude':2" - , " , 'altitude':null" - , " , 'globe':null" - , " , 'precision':1" - , " }" - , " ]" - , " }" - , " ]" - , "}" - ); - Wdata_doc_parser parser = new Wdata_doc_parser(Gfo_usr_dlg_.Null); - parser.Bld_props(jdoc); // make sure it doesn't fail - } -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_wtr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_wtr.java new file mode 100644 index 000000000..74469b259 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_wtr.java @@ -0,0 +1,171 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.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, OrderedHash 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.FetchAt(i); + wtr.Kv(i != 0, Bry_.new_utf8_(kv.Key()), Bry_.new_utf8_(kv.Val_to_str_or_empty())); + } + wtr.Nde_end(); + list.Clear(); + } + private void Xto_bry__sitelinks(byte[] key, OrderedHash 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.FetchAt(i); + wtr.Key(false, Bry_.new_utf8_(kv.Key())); // write key; EX: enwiki: + wtr.Nde_bgn(); // bgn nde; EX: { + wtr.Kv(false, Wdata_doc_parser_v1.Bry_name, Bry_.new_utf8_(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(OrderedHash 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.FetchAt(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, OrderedHash 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(); + Wdata_claim_itm_core prop = (Wdata_claim_itm_core)props.FetchAt(i); + wtr.Nde_bgn(); + wtr.Key(false, Wdata_dict_claim_v1.Bry_m); + wtr.Ary_bgn(); + wtr.Val(Bool_.N, Wdata_dict_snak_tid.Xto_bry(prop.Snak_tid())); + wtr.Val(Bool_.Y, prop.Pid()); + if (prop.Snak_tid() == Wdata_dict_snak_tid.Tid_value) { + switch (prop.Val_tid()) { + case Wdata_dict_val_tid.Tid_string: + Wdata_claim_itm_str claim_str = (Wdata_claim_itm_str)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_string); + wtr.Val(Bool_.Y, claim_str.Val_str()); + break; + case Wdata_dict_val_tid.Tid_entity: + Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_entity); + wtr.Comma(); + wtr.Nde_bgn(); + wtr.Kv(Bool_.N, Wdata_dict_value_entity.Bry_entity_type , Wdata_dict_value_entity.Val_entity_type_item_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_entity.Bry_numeric_id , claim_entity.Entity_id()); + wtr.Nde_end(); + break; + case Wdata_dict_val_tid.Tid_time: + Wdata_claim_itm_time claim_time = (Wdata_claim_itm_time)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_time); + wtr.Comma(); + wtr.Nde_bgn(); + wtr.Kv(Bool_.N, Wdata_dict_value_time.Bry_time , claim_time.Time()); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_precision , Wdata_dict_value_time.Val_timezone_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_before , Wdata_dict_value_time.Val_before_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_after , Wdata_dict_value_time.Val_after_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_timezone , Wdata_dict_value_time.Val_timezone_bry); + wtr.Kv(Bool_.Y, Wdata_dict_value_time.Bry_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_bry); + wtr.Nde_end(); + break; + case Wdata_dict_val_tid.Tid_globecoordinate: { + Wdata_claim_itm_globecoordinate claim_globecoordinate = (Wdata_claim_itm_globecoordinate)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_globecoordinate); + wtr.Comma(); + wtr.Nde_bgn(); + wtr.Kv_double (Bool_.N, Wdata_dict_value_globecoordinate.Bry_latitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lat()))); + wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_longitude , Double_.parse_(String_.new_ascii_(claim_globecoordinate.Lng()))); + wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_altitude , null); + wtr.Kv (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_globe , Wdata_dict_value_globecoordinate.Val_globe_dflt_bry); + wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_precision , .00001d); + wtr.Nde_end(); + break; + } + case Wdata_dict_val_tid.Tid_quantity: { + Wdata_claim_itm_quantity claim_quantity = (Wdata_claim_itm_quantity)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_quantity); + wtr.Comma(); + wtr.Nde_bgn(); + wtr.Kv (Bool_.N, Wdata_dict_value_quantity.Bry_amount , claim_quantity.Amount()); // +1,234 + wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_unit , claim_quantity.Unit()); // 1 + wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_upperbound , claim_quantity.Ubound()); // +1,235 + wtr.Kv (Bool_.Y, Wdata_dict_value_quantity.Bry_lowerbound , claim_quantity.Lbound()); // +1,233 + wtr.Nde_end(); + break; + } + case Wdata_dict_val_tid.Tid_monolingualtext: { + Wdata_claim_itm_monolingualtext claim_monolingualtext = (Wdata_claim_itm_monolingualtext)prop; + wtr.Val(Bool_.Y, Wdata_dict_val_tid.Bry_monolingualtext); + wtr.Comma(); + wtr.Nde_bgn(); + wtr.Kv (Bool_.N, Wdata_dict_value_monolingualtext.Bry_text , claim_monolingualtext.Text()); // text + wtr.Kv (Bool_.Y, Wdata_dict_value_monolingualtext.Bry_language , claim_monolingualtext.Lang()); // en + wtr.Nde_end(); + break; + } + default: throw Err_.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, Wdata_dict_rank.Tid_normal); + wtr.Kv_ary_empty(Bool_.Y, Wdata_dict_claim_v1.Bry_refs); + wtr.Nde_end(); + } + wtr.Ary_end(); + props.Clear(); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_external_lang_links_data.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_external_lang_links_data.java deleted file mode 100644 index 05aae015f..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_external_lang_links_data.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.xowa.xtns.pfuncs.*; -public class Wdata_external_lang_links_data { - private ListAdp langs_list = ListAdp_.new_(); private Hash_adp_bry langs_hash = Hash_adp_bry.ci_ascii_(); // 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;} private boolean sort; public Wdata_external_lang_links_data Sort_(boolean v) {sort = v; return this;} - 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.FetchAt(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.App().Utl_bry_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, self, tmp_bfr); - byte[] lang = tmp_bfr.XtoAryAndClear(); - Langs_add(lang); - } - tmp_bfr.Mkr_rls(); - } - public static final byte[] Key_sort = new byte[] {Byte_ascii.Asterisk}; -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_cfg.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_cfg.java deleted file mode 100644 index c4087bf63..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_cfg.java +++ /dev/null @@ -1,28 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -public class Wdata_itemByTitle_cfg implements GfoInvkAble { - public byte[] Site_default() {return site_default;} private byte[] site_default = Bry_.new_ascii_("enwiki"); - public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) { - if (ctx.Match(k, Invk_site_default)) return site_default; - else if (ctx.Match(k, Invk_site_default_)) site_default = m.ReadBry("v"); - else return GfoInvkAble_.Rv_unhandled; - return this; - } private static final String Invk_site_default = "site_default", Invk_site_default_ = "site_default_"; - public static final String Key = "itemByTitle"; -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_page.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_page.java deleted file mode 100644 index 57c97290d..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_page.java +++ /dev/null @@ -1,83 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.xowa.specials.*; -public class Wdata_itemByTitle_page implements Xows_page { - private Xoa_url_arg_hash arg_hash = new Xoa_url_arg_hash(); - private static final byte[] Arg_site = Bry_.new_ascii_("site"), Arg_page = Bry_.new_ascii_("page"); - public Bry_fmtr Html_fmtr() {return html_fmtr;} - private Wdata_itemByTitle_cfg cfg; - public void Special_gen(Xoa_url calling_url, Xoa_page page, Xow_wiki wiki, Xoa_ttl ttl) { - if (cfg == null) cfg = (Wdata_itemByTitle_cfg)wiki.App().Special_mgr().Get_or_null(Wdata_itemByTitle_cfg.Key); - // Special:ItemByTitle/enwiki/Earth -> www.wikidata.org/wiki/Q2 - Gfo_usr_dlg usr_dlg = wiki.App().Usr_dlg(); - byte[] site_bry = cfg.Site_default(); - byte[] page_bry = Bry_.Empty; - byte[] raw_bry = ttl.Full_txt_wo_qarg(); // EX: enwiki/Earth - int args_len = calling_url.Args().length; - if (args_len > 0) { - arg_hash.Load(calling_url); - site_bry = arg_hash.Get_val_bry_or(Arg_site, Bry_.Empty); - page_bry = arg_hash.Get_val_bry_or(Arg_page, Bry_.Empty); - } - int site_bgn = Bry_finder.Find_fwd(raw_bry, Xoa_ttl.Subpage_spr); - if (site_bgn != Bry_.NotFound) { // leaf arg is available - int page_bgn = Bry_finder.Find_fwd(raw_bry, Xoa_ttl.Subpage_spr, site_bgn + 1); - int raw_bry_len = raw_bry.length; - if (page_bgn != Bry_.NotFound && page_bgn < raw_bry_len) { // pipe is found and not last char (EX: "enwiki/" is invalid - site_bry = Bry_.Mid(raw_bry, site_bgn + 1, page_bgn); - page_bry = Bry_.Mid(raw_bry, page_bgn + 1, raw_bry_len); - } - } - Xoa_app app = wiki.App(); - if (Bry_.Len_gt_0(site_bry) && Bry_.Len_gt_0(page_bry)) - if (Navigate(usr_dlg, app, app.Wiki_mgr().Wdata_mgr(), page, site_bry, page_bry)) return; - Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004(); - html_fmtr.Bld_bfr_many(tmp_bfr, "Search for items by site and title", "Site", site_bry, "Page", page_bry, "Search"); - page.Data_raw_(tmp_bfr.Mkr_rls().XtoAryAndClear()); - page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML - } - private static boolean Navigate(Gfo_usr_dlg usr_dlg, Xoa_app app, Wdata_wiki_mgr wdata_mgr, Xoa_page page, byte[] site_bry, byte[] page_bry) { - page_bry = app.Encoder_mgr().Url().Decode(page_bry); // NOTE: space is converted to + on postback to url; decode - byte[] wiki_domain = Xob_bz2_file.Parse_wmf_key(site_bry); if (wiki_domain == null) {usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_utf8_(site_bry)); return false;} - Xow_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_domain); if (wiki == null) {usr_dlg.Warn_many("", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_utf8_(wiki_domain)); return false;} - Xoa_ttl wdata_ttl = Xoa_ttl.parse_(wiki, page_bry); if (wdata_ttl == null) {usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_utf8_(page_bry)); return false;} - Wdata_doc doc = wdata_mgr.Pages_get(wiki, wdata_ttl); if (doc == null) {usr_dlg.Warn_many("", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_utf8_(wdata_ttl.Raw())); return false;} - byte[] qid_bry = doc.Qid(); - Xoa_page qid_page = wdata_mgr.Wdata_wiki().Data_mgr().Redirect(page, qid_bry); if (qid_page.Missing()) {usr_dlg.Warn_many("", "", "qid cannot be found in wikidata; qid:~{0}", String_.new_utf8_(qid_bry)); return false;} - return true; - } - private static Bry_fmtr html_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl - ( "
" - , "
" - , "
" - , "~{legend}" - , "" - , "" - , "" - , "" - , "" - , "" - , "" - , "
" - , "
" - , "
" - , "
To change the default site, see Help:Options/Wikibase" - ) - , "legend", "site_lbl", "site_val", "page_lbl", "page_val", "search_lbl"); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_page_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_page_tst.java deleted file mode 100644 index 934074889..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_itemByTitle_page_tst.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import org.junit.*; import gplx.xowa.wikis.*; -public class Wdata_itemByTitle_page_tst { - @Before public void init() {fxt.Clear();} private Wdata_itemByTitle_page_fxt fxt = new Wdata_itemByTitle_page_fxt(); - @Test public void Url() { - fxt.Init_wdata_page("Q2", "q2_earth"); - fxt.Init_wdata_label("enwiki", "Earth", "Q2"); - fxt.Test_open("Special:ItemByTitle/enwiki/Earth", "q2_earth"); - } - @Test public void Missing() { - fxt.Test_open("Special:ItemByTitle/enwiki/unknown_page", fxt.Expd_html("enwiki", "unknown page")); - } - @Test public void Html() { - fxt.Test_open("Special:ItemByTitle", fxt.Expd_html("enwiki", "")); - } - @Test public void Args() { - fxt.Init_wdata_page("Q2", "q2_earth"); - fxt.Init_wdata_label("enwiki", "Earth", "Q2"); - fxt.Test_open("Special:ItemByTitle?site=enwiki&page=Earth", "q2_earth"); - } - @Test public void Url_decode() { // PURPOSE: spaces not handled; EX: Albert Einstein -> Albert+Einstein; DATE:2013-07-24 - fxt.Init_wdata_page("Q2", "q2_page"); - fxt.Init_wdata_label("enwiki", "A_B", "Q2"); - fxt.Test_open("Special:ItemByTitle?site=enwiki&page=A+B", "q2_page"); - } -} -class Wdata_itemByTitle_page_fxt { - public void Clear() { - parser_fxt = new Xop_fxt(); - parser_fxt.Reset(); - app = parser_fxt.App(); - wiki = parser_fxt.Wiki(); - special_page = wiki.Special_mgr().Page_itemByTitle(); - wdata_fxt = new Wdata_wiki_mgr_fxt().Init(parser_fxt, true); - } private Xop_fxt parser_fxt; private Xoa_app app; private Wdata_itemByTitle_page special_page; private Xow_wiki wiki; - Wdata_wiki_mgr_fxt wdata_fxt; - public void Init_wdata_page(String qid_ttl, String text) { - Wdata_doc doc = wdata_fxt.doc_(qid_ttl); - app.Wiki_mgr().Wdata_mgr().Pages_add(Bry_.new_ascii_(qid_ttl), doc); - parser_fxt.Init_page_create(app.Wiki_mgr().Wdata_mgr().Wdata_wiki(), qid_ttl, text); - } - public void Init_wdata_label(String wmf_key_str, String wdata_label, String qid) { - wdata_fxt.Init_qids_add("en", Xow_wiki_domain_.Tid_wikipedia, wdata_label, qid); - } - public void Test_open(String link, String expd) { - Xoa_page page = wiki.Ctx().Cur_page(); - Xoa_url url = Xoa_url_parser.Parse_url(app, wiki, link); - page.Url_(url); - Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Bry_.new_ascii_(link)); - page.Ttl_(ttl); - special_page.Special_gen(url, page, wiki, ttl); - Tfds.Eq_str_lines(expd, String_.new_ascii_(page.Data_raw())); - } - public String Expd_html(String wmf_key, String ttl_str) { - Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_k004(); - special_page.Html_fmtr().Bld_bfr_many(tmp_bfr, "Search for items by site and title", "Site", wmf_key, "Page", ttl_str, "Search"); - return tmp_bfr.Mkr_rls().XtoStrAndClear(); - } -} - diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_noExternalLangLinks.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_noExternalLangLinks.java deleted file mode 100644 index 019244d6b..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_noExternalLangLinks.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; -import gplx.xowa.xtns.pfuncs.*; -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(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) { - ctx.Cur_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"; -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_noExternalLangLinks_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_noExternalLangLinks_tst.java deleted file mode 100644 index 2fd489996..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_noExternalLangLinks_tst.java +++ /dev/null @@ -1,64 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -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.Ctx().Cur_page().Wdata_external_lang_links(); - } - expd_sort = expd_enabled = Bool_.__byte; - expd_langs = null; - data.Reset(); - return this; - } private Xop_fxt parser_fxt; Xoa_app app; Xow_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_utf8_((byte[])data.Langs_get_at(i)); - } - return rv; - } -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property.java deleted file mode 100644 index b1a4b49e1..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property.java +++ /dev/null @@ -1,106 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.xtns.pfuncs.*; -public class Wdata_pf_property extends Pf_func_base { - @Override public int Id() {return Xol_kwd_grp_.Id_property;} - @Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_property().Name_(name);} - @Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) {// {{#property:pNumber|}} - byte[] id = Eval_argx(ctx, src, caller, self); - Xop_log_property_wkr property_wkr = ctx.Xtn__wikidata__property_wkr(); - long log_time_bgn = 0; - if (property_wkr != null) { - log_time_bgn = Env_.TickCount(); - if (!property_wkr.Eval_bgn(ctx.Cur_page(), id)) return; - } - - Xoa_app app = ctx.App(); - Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr(); - if (!wdata_mgr.Enabled()) return; - Xow_wiki wiki = ctx.Wiki(); - Xoa_ttl ttl = ctx.Cur_page().Ttl(); - - Wdata_pf_property_data data = new Wdata_pf_property_data(); - data.Init_by_parse(ctx, src, caller, self, this, id); - Wdata_doc prop_doc = wdata_mgr.Pages_get(wiki, ttl, data); if (prop_doc == null) return; // NOTE: some pages will not exist in qid; EX: {{#property:P345}} for "Unknown_page" will not even had a qid; if no qid, then no pid - int pid = data.Id_int(); - if (pid == Wdata_wiki_mgr.Pid_null) - pid = wdata_mgr.Pids_get(wiki.Wdata_wiki_lang(), data.Id()); - if (pid == Wdata_wiki_mgr.Pid_null) {Print_self(app.Usr_dlg(), bfr, src, self, "prop_not_found", "prop id not found: ~{0} ~{1} ~{2}", wiki.Domain_str(), ttl.Page_db_as_str(), data.Id()); return;} - Wdata_prop_grp prop_grp = prop_doc.Claim_list_get(pid); if (prop_grp == null) return;// NOTE: some props may not exist; EX: {{#property:P345}} for "Unknown_movie" may have a qid, but doesn't have a defined pid - wdata_mgr.Resolve_to_bfr(bfr, prop_grp, wiki.Wdata_wiki_lang()); // NOTE: was ctx.Cur_page().Lang().Key_bry(), but fails in simplewiki; DATE:2013-12-02 - if (property_wkr != null) - property_wkr.Eval_end(ctx.Cur_page(), id, log_time_bgn); - } - public static int Parse_pid(NumberParser num_parser, byte[] bry) { - int bry_len = bry.length; - if (bry_len < 2) return Wdata_wiki_mgr.Pid_null; // must have at least 2 chars; p# - byte b_0 = bry[0]; - if (b_0 != Byte_ascii.Ltr_p && b_0 != Byte_ascii.Ltr_P) return Wdata_wiki_mgr.Pid_null; - num_parser.Parse(bry, 1, bry_len); - return num_parser.HasErr() ? Wdata_wiki_mgr.Pid_null : num_parser.AsInt(); - } - 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); - } - public static void Print_empty(Gfo_usr_dlg usr_dlg, String warn_cls, String warn_fmt, Object... args) { - usr_dlg.Warn_many(GRP_KEY, warn_cls, warn_fmt, args); - } - private static final String GRP_KEY = "xowa.xtns.wdata.property"; -} -class Wdata_pf_property_data { - public byte[] Of() {return of;} private byte[] of; - public byte[] Q() {return q;} private byte[] q; - public byte[] Id() {return id;} private byte[] id; - public int Id_int() {return id_int;} private int id_int; - public void Init_by_parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Wdata_pf_property pfunc) { - byte[] id = pfunc.Eval_argx(ctx, src, caller, self); - Init_by_parse(ctx, src, caller, self, pfunc, id); - } - public void Init_by_parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Wdata_pf_property pfunc, byte[] id) { - this.id = id; - id_int = Wdata_pf_property.Parse_pid(ctx.App().Utl_num_parser(), id); - if (id_int == Wdata_wiki_mgr.Pid_null) {} // named; TODO: get pid from pid_regy - int args_len = self.Args_len(); - Bry_bfr tmp_bfr = ctx.Wiki().Utl_bry_bfr_mkr().Get_b512(); - for (int i = 0; i < args_len; i++) { - Arg_nde_tkn nde = self.Args_get_by_idx(i); - Arg_itm_tkn nde_key = nde.Key_tkn(); - int nde_key_bgn = nde_key.Src_bgn(), nde_key_end = nde_key.Src_end(); - if (nde_key_bgn == nde_key_end && nde_key_bgn == -1) continue; // null arg; ignore, else will throw warning below; EX: {{#property:p1|}}; DATE:2013-11-15 - Object o = Atr_keys.Get_by_mid(src, nde_key_bgn, nde_key_end); - if (o == null) { - ctx.App().Usr_dlg().Warn_many("", "", "unknown key for property: ~{0} ~{1}", String_.new_utf8_(ctx.Cur_page().Ttl().Full_txt()), String_.new_utf8_(src, self.Src_bgn(), self.Src_end())); - continue; - } - nde.Val_tkn().Tmpl_evaluate(ctx, src, self, tmp_bfr); - byte[] val = tmp_bfr.XtoAryAndClear(); - byte key_tid = ((Byte_obj_val)o).Val(); - switch (key_tid) { - case Atr_of_id: of = val; break; - case Atr_q_id: q = val; break; - default: throw Err_.unhandled(key_tid); - } - } - tmp_bfr.Mkr_rls(); - } - static final byte Atr_of_id = 1, Atr_q_id = 2; - private static final byte[] Atr_of_bry = Bry_.new_ascii_("of"), Atr_q_bry = Bry_.new_ascii_("q"); - private static final Hash_adp_bry Atr_keys = Hash_adp_bry.ci_ascii_().Add_bry_byte(Atr_of_bry, Atr_of_id).Add_bry_byte(Atr_q_bry, Atr_q_id); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property_fmt.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property_fmt.java deleted file mode 100644 index 6f4fdf44e..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property_fmt.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -public class Wdata_pf_property_fmt { - public byte[] Separator() {return separator;} private byte[] separator; - public byte[] Value_template() {return value_template;} private byte[] value_template; - public byte[] Qualifier_template() {return qualifier_template;} private byte[] qualifier_template; - public byte[] Qualifier_separator() {return qualifier_separator;} private byte[] qualifier_separator; - public byte[] Qualifiers_wrapper() {return qualifiers_wrapper;} private byte[] qualifiers_wrapper; - public byte[] Qualifiers_template() {return qualifiers_template;} private byte[] qualifiers_template; - public byte[] Qualifiers_value_separator() {return qualifiers_value_separator;} private byte[] qualifiers_value_separator; - public byte[] Reference_keyvalue_template() {return reference_keyvalue_template;} private byte[] reference_keyvalue_template; - public byte[] Reference_wrapper() {return reference_wrapper;} private byte[] reference_wrapper; - public byte[] References_wrapper() {return references_wrapper;} private byte[] references_wrapper; - public byte[] Reference_keyvalue_separator() {return reference_keyvalue_separator;} private byte[] reference_keyvalue_separator; - public byte[] Reference_template() {return reference_template;} private byte[] reference_template; - public byte[] Reference_value_separator() {return reference_value_separator;} private byte[] reference_value_separator; - public byte[] Reference_separator() {return reference_separator;} private byte[] reference_separator; - public void Init() { - byte[] comma = new byte[] {Byte_ascii.Comma}; - separator = comma; - value_template = Bry_.new_ascii_("{{{value}}} {{{qualifiers}}}{{{references}}}"); - qualifier_template = Bry_.new_ascii_("{{{1}}} {{{2}}}"); - qualifier_separator = comma; - qualifiers_wrapper = Bry_.new_ascii_("{{{1}}}"); - qualifiers_template = Bry_.Empty; - qualifiers_value_separator = comma; - reference_keyvalue_template = Bry_.new_ascii_("{{{1}}} {{{2}}}"); - reference_wrapper = Bry_.new_ascii_("{{{1}}}"); - references_wrapper = Bry_.new_ascii_("{{{1}}}"); - reference_keyvalue_separator = comma; - reference_template = Bry_.Empty; - reference_value_separator = comma; - reference_separator = Bry_.Empty; // "a separator to use between each reference" - } -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property_tst.java deleted file mode 100644 index 99926d85f..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_property_tst.java +++ /dev/null @@ -1,150 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import org.junit.*; -public class Wdata_pf_property_tst { - @Before public void init() {fxt.Init();} Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt(); - @Test public void String() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_str_(1, "a"))); - fxt.Test_parse("{{#property:p1}}", "a"); - fxt.Test_parse("{{#property:p2}}", ""); - } - @Test public void Entity() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc()); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); - fxt.Test_parse("{{#property:p1}}", "b"); - } - @Test public void Entity_fr() { // PURPOSE: non-English wiki should default to English label if non-English label not available; DATE:2013-12-19 - fxt.Wiki().Wdata_wiki_lang_(Bry_.new_ascii_("fr")); // set wiki to French - fxt.Init_links_add("frwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); // create wdata page Q1 with prop entity reference to Q2 - fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc()); // create wdata page Q2 with label in en (not fr) - fxt.Test_parse("{{#property:p1}}", "b"); // parse; should get en label - } - @Test public void Entity_missing() { // PURPOSE: 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 - fxt.Init_links_add("enwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); // create wdata page Q1 with prop entity reference to Q2; note that Q2 is not created - fxt.Test_parse("{{#property:p1}}", ""); // parse; get "" - } - @Test public void Time() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_time_(1, "2012-01-02 03:04:05"))); - fxt.Test_parse("{{#property:p1}}", "+00000002012-01-02T03:04:05Z"); - } - @Test public void Geodata() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_geodata_(1, "1.2345", "6.789"))); - fxt.Test_parse("{{#property:p1}}", "1.2345, 6.789"); - } - @Test public void Quantity() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_quantity_(1, "+1,234", "2", "+1,236", "+1232"))); - fxt.Test_parse("{{#property:p1}}", "1,234±2"); - } - @Test public void Monolingualtext() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_monolingualtext_(1, "Lorem ipsum dolor sit amet", "la"))); - fxt.Test_parse("{{#property:p1}}", "Lorem ipsum dolor sit amet"); - } - @Test public void Novalue() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_novalue_(1))); - fxt.Test_parse("{{#property:p1}}", "novalue"); - } - @Test public void Somevalue() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_somevalue_(1))); - fxt.Test_parse("{{#property:p1}}", "somevalue"); - } - @Test public void Multiple() { - fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_str_(1, "a"), fxt.prop_str_(1, "b"))); - fxt.Test_parse("{{#property:p1}}", "a, b"); - } - @Test public void Q() { - fxt.Init_links_add("enwiki", "Test_page", "q2"); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); - fxt.Test_parse("{{#property:p1|q=q2}}", "a"); - } - @Test public void Of() { - fxt.Init_links_add("enwiki", "Of_page", "q2"); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); - fxt.Test_parse("{{#property:p1|of=Of_page}}", "a"); - } - @Test public void Pid_as_name() { - fxt.Init_links_add("enwiki", "Test_page", "q2"); - fxt.Init_pids_add("en", "astronomic symbol", 1); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); - fxt.Test_parse("{{#property:astronomic symbol}}", "a"); - } - @Test public void Empty_arg() { // PURPOSE: {{#property:p1|}} should not fail / warn; DATE:2013-11-15 - fxt.Init_links_add("enwiki", "Test_page", "q2"); - fxt.Init_pids_add("en", "astronomic symbol", 1); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); - fxt.Test_parse("{{#property:p1|}}", "a"); - } - @Test public void Data() { - Wdata_pf_property_data_fxt fxt = new Wdata_pf_property_data_fxt(); - fxt.Init().Expd_id_int_(1).Test_parse("{{#property:p1}}"); - fxt.Init().Expd_id_int_(1).Expd_q_("q2").Test_parse("{{#property:p1|q=q2}}"); - fxt.Init().Expd_id_int_(1).Expd_of_("Earth").Test_parse("{{#property:p1|of=Earth}}"); - } - @Test public void Parse_pid() { - fxt.Test_parse_pid ("p123" , 123); // basic - fxt.Test_parse_pid ("P123" , 123); // uppercase - fxt.Test_parse_pid_null ("population"); // name test - fxt.Test_parse_pid_null ("123"); // missing p - fxt.Test_parse_pid_null (""); // empty String test - } -} -class Wdata_pf_property_data_fxt { - public Wdata_pf_property_data_fxt Init() { - if (app == null) { - parser_fxt = new Xop_fxt(); - app = parser_fxt.App(); - page_bldr = new Wdata_doc_bldr(app.Wiki_mgr().Wdata_mgr()); - wdata_mgr = app.Wiki_mgr().Wdata_mgr(); - } - Io_mgr._.InitEngine_mem(); - wdata_mgr.Clear(); - parser_fxt.Reset(); - expd_id_int = -1; - expd_q = expd_of = null; - return this; - } private Xoa_app app; Wdata_wiki_mgr wdata_mgr; Wdata_doc_bldr page_bldr; Xop_fxt parser_fxt; - public Wdata_pf_property_data_fxt Expd_id_int_(int v) {expd_id_int = v; return this;} private int expd_id_int; - public Wdata_pf_property_data_fxt Expd_q_(String v) {expd_q = Bry_.new_ascii_(v); return this;} private byte[] expd_q; - public Wdata_pf_property_data_fxt Expd_of_(String v) {expd_of = Bry_.new_ascii_(v); return this;} private byte[] expd_of; - public void Test_parse(String raw) { - Wdata_pf_property_data actl = new Wdata_pf_property_data(); - byte[] raw_bry = Bry_.new_utf8_(raw); - Xow_wiki wiki = parser_fxt.Wiki(); Xop_ctx ctx = wiki.Ctx(); - Xop_tkn_mkr tkn_mkr = app.Tkn_mkr(); - Wdata_pf_property pfunc = new Wdata_pf_property(); - Xop_root_tkn root = tkn_mkr.Root(raw_bry); - wiki.Parser().Parse_text_to_wtxt(root, ctx, tkn_mkr, raw_bry); - Xot_invk tkn = (Xot_invk)root.Subs_get(0); - actl.Init_by_parse(ctx, raw_bry, Xot_invk_mock.Null, tkn, pfunc); - - if (expd_id_int != -1) Tfds.Eq(expd_id_int, actl.Id_int()); - if (expd_q != null) Tfds.Eq_bry(expd_q, actl.Q()); - if (expd_of != null) Tfds.Eq_bry(expd_of, actl.Of()); - } -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_wbreponame.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_wbreponame.java deleted file mode 100644 index e8acb5807..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_wbreponame.java +++ /dev/null @@ -1,27 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import gplx.json.*; -import gplx.xowa.xtns.pfuncs.*; -public class Wdata_pf_wbreponame extends Pf_func_base { - @Override public int Id() {return Xol_kwd_grp_.Id_wbreponame;} - @Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_wbreponame().Name_(name);} - @Override public void Func_evaluate(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Bry_bfr bfr) { - bfr.Add(Reponame); // NOTE: MW has logic to look for message named "wbreponame", and returning it if it exists; only applies to non-WMF Wikidatas; DATE:2014-09-07 - } private static final byte[] Reponame = Bry_.new_ascii_("Wikidata"); -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_base.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_base.java deleted file mode 100644 index d499118d7..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_base.java +++ /dev/null @@ -1,34 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -public class Wdata_prop_itm_base { - public Wdata_prop_itm_base Ctor(byte snak_tid, int pid, byte val_tid, byte[] val) { - this.snak_tid = snak_tid; - this.pid = pid; - this.val_tid_byte = val_tid; - this.val = val; - return this; - } - public int Pid() {return pid;} private int pid; - public byte Val_tid_byte() {return val_tid_byte;} private byte val_tid_byte; - public String Val_tid_str() {return Wdata_prop_itm_base_.Val_tid_to_string(val_tid_byte);} - public byte[] Val() {return val;} private byte[] val; - public byte[] Snak_bry() {return Wdata_prop_itm_base_.Snak_tid_bry(snak_tid);} - public byte Snak_tid() {return snak_tid;} private byte snak_tid = Wdata_prop_itm_base_.Snak_tid_value; - public String Snak_str() {return Wdata_prop_itm_base_.Snak_tid_string(snak_tid);} -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_base_.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_base_.java deleted file mode 100644 index 221478902..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_base_.java +++ /dev/null @@ -1,99 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -public class Wdata_prop_itm_base_ { - public static final Wdata_prop_itm_base[] Ary_empty = new Wdata_prop_itm_base[0]; - public static final byte - Val_tid_unknown = 0, Val_tid_bad = 1 - , Val_tid_string = 2, Val_tid_entity = 3 - , Val_tid_time = 4, Val_tid_globecoordinate = 5, Val_tid_quantity = 6, Val_tid_monolingualtext = 7; - public static final String - Val_str_bad = "bad" - , Val_str_string = "string", Val_str_entity = "wikibase-entityid" - , Val_str_time = "time", Val_str_globecoordinate = "globecoordinate", Val_str_quantity = "quantity", Val_str_monolingualtext = "monolingualtext" - ; - public static final byte[] - Val_bry_bad = bry_(Val_str_bad) - , Val_bry_string = bry_(Val_str_string), Val_bry_entity = bry_(Val_str_entity) - , Val_bry_time = bry_(Val_str_time), Val_bry_globecoordinate = bry_(Val_str_globecoordinate), Val_bry_quantity = bry_(Val_str_quantity), Val_bry_monolingualtext = bry_(Val_str_monolingualtext) - ; - public static byte Val_tid_parse(byte[] src, int bgn, int end) { - Object bval_obj = Val_tid_regy.Get_by_mid(src, bgn, end); - if (bval_obj == null) return Val_tid_unknown; - return ((Byte_obj_val)bval_obj).Val(); - } - private static final Hash_adp_bry Val_tid_regy = Hash_adp_bry.ci_ascii_() - .Add_bry_byte(Val_bry_string, Wdata_prop_itm_base_.Val_tid_string) - .Add_bry_byte(Val_bry_entity, Wdata_prop_itm_base_.Val_tid_entity) - .Add_bry_byte(Val_bry_time, Wdata_prop_itm_base_.Val_tid_time) - .Add_bry_byte(Val_bry_globecoordinate, Wdata_prop_itm_base_.Val_tid_globecoordinate) - .Add_bry_byte(Val_bry_quantity, Wdata_prop_itm_base_.Val_tid_quantity) - .Add_bry_byte(Val_bry_monolingualtext, Wdata_prop_itm_base_.Val_tid_monolingualtext) - .Add_bry_byte(Val_bry_bad, Wdata_prop_itm_base_.Val_tid_bad) - ; - public static String Val_tid_to_string(byte tid) { - switch (tid) { - case Val_tid_string : return Val_str_string; - case Val_tid_entity : return Val_str_entity; - case Val_tid_time : return Val_str_time; - case Val_tid_globecoordinate : return Val_str_globecoordinate; - case Val_tid_quantity : return Val_str_quantity; - case Val_tid_monolingualtext : return Val_str_monolingualtext; - case Val_tid_bad : return Val_str_bad; // NOTE: wikidata identifies several entries as "bad"; Q1615351|'s-Graveland, Q107538|Baco; DATE:2013-10-20 - default : return "unknown"; - } - } - public static final byte Snak_tid_novalue = 0, Snak_tid_value = 1, Snak_tid_somevalue = 2; - public static byte Snak_tid_parse(byte[] v) { - Object bval_obj = Snak_tid_regy.Get_by_bry(v); - if (bval_obj == null) throw Err_.new_fmt_("unknown snak type_id: ~{0}", String_.new_utf8_(v)); - return ((Byte_obj_val)bval_obj).Val(); - } - private static Hash_adp_bry Snak_tid_regy = Hash_adp_bry.ci_ascii_() - .Add_bry_byte(Wdata_doc_consts.Val_prop_novalue_bry, Snak_tid_novalue) - .Add_str_byte(Wdata_doc_consts.Val_prop_value_str, Snak_tid_value) - .Add_str_byte(Wdata_doc_consts.Val_prop_somevalue_str, Snak_tid_somevalue) - ; - public static String Snak_tid_string(byte v) { - switch (v) { - case Snak_tid_value: return Wdata_doc_consts.Val_prop_value_str; - case Snak_tid_novalue: return Wdata_doc_consts.Val_prop_novalue_str; - case Snak_tid_somevalue:return Wdata_doc_consts.Val_prop_somevalue_str; - default: return "unknown"; - } - } - public static byte[] Snak_tid_bry(byte v) { - switch (v) { - case Snak_tid_value: return Wdata_doc_consts.Val_prop_value_bry; - case Snak_tid_novalue: return Wdata_doc_consts.Val_prop_novalue_bry; - case Snak_tid_somevalue:return Wdata_doc_consts.Val_prop_somevalue_bry; - default: return null; - } - } - public static final byte Rank_preferred = 2, Rank_normal = 1, Rank_deprecated = 0; - public static String Rank_string(byte v) { - switch (v) { - case Rank_preferred: return "preferred"; - case Rank_normal: return "normal"; - case Rank_deprecated: return "deprecated"; - default: throw Err_.unhandled(v); - } - } - public static final String Prop_type_statement = "statement"; - private static byte[] bry_(String s) {return Bry_.new_ascii_(s);} -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_core.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_core.java deleted file mode 100644 index d90aa0983..000000000 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_prop_itm_core.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012 gnosygnu@gmail.com - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -*/ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -public class Wdata_prop_itm_core extends Wdata_prop_itm_base { - public Wdata_prop_itm_core(byte snak_tid, int pid, byte val_tid_byte, byte[] val) {this.Ctor(snak_tid, pid, val_tid_byte, val);} - public byte[] Wguid() {return wguid;} public void Wguid_(byte[] v) {this.wguid = v;} private byte[] wguid; - public String Prop_type() {return Wdata_prop_itm_base_.Prop_type_statement;} - public byte Rank_tid() {return rank_tid;} - public void Rank_tid_(byte v) {this.rank_tid = v;} private byte rank_tid; - public String Rank_str() {return Wdata_prop_itm_base_.Rank_string(rank_tid);} - public Wdata_prop_itm_base[] Qual_ary() {return qual_ary;} public void Qual_ary_(Wdata_prop_itm_base[] v) {this.qual_ary = v;} Wdata_prop_itm_base[] qual_ary; - public Wdata_prop_itm_base[] Ref_ary() {return ref_ary;} public void Ref_ary_(Wdata_prop_itm_base[] v) {this.ref_ary = v;} Wdata_prop_itm_base[] ref_ary; - - public static final byte Prop_dlm = Byte_ascii.Pipe; - public static Wdata_prop_itm_core new_novalue_(int pid) {return new Wdata_prop_itm_core(Wdata_prop_itm_base_.Snak_tid_novalue , pid, Wdata_prop_itm_base_.Val_tid_unknown, Bry_.Empty);} - public static Wdata_prop_itm_core new_somevalue_(int pid) {return new Wdata_prop_itm_core(Wdata_prop_itm_base_.Snak_tid_somevalue, pid, Wdata_prop_itm_base_.Val_tid_unknown, Bry_.Empty);} - public static Wdata_prop_itm_core new_str_(int pid, String val) {return new_(Wdata_prop_itm_base_.Val_tid_string, pid, Bry_.new_utf8_(val));} - public static Wdata_prop_itm_core new_str_(int pid, byte[] val) {return new_(Wdata_prop_itm_base_.Val_tid_string, pid, val);} - public static Wdata_prop_itm_core new_time_(int pid, String val) {return new_(Wdata_prop_itm_base_.Val_tid_time, pid, Wdata_doc_bldr.Xto_time(DateAdp_.parse_fmt(val, "yyyy-MM-dd HH:mm:ss")));} - public static Wdata_prop_itm_core new_geodata_(int pid, String lat, String lon) {return new_(Wdata_prop_itm_base_.Val_tid_globecoordinate, pid, Bry_.Add_w_dlm(Prop_dlm, Bry_.new_ascii_(lat), Bry_.new_ascii_(lon)));} - public static Wdata_prop_itm_core new_quantity_(int pid, String amount, String unit, String ubound, String lbound) - {return new_(Wdata_prop_itm_base_.Val_tid_quantity, pid, Bry_.Add_w_dlm(Prop_dlm, Bry_.new_ascii_(amount), Bry_.new_ascii_(unit), Bry_.new_ascii_(ubound), Bry_.new_ascii_(lbound)));} - public static Wdata_prop_itm_core new_monolingualtext_(int pid, String text, String lang) - {return new_(Wdata_prop_itm_base_.Val_tid_monolingualtext, pid, Bry_.Add_w_dlm(Prop_dlm, Bry_.new_ascii_(text), Bry_.new_utf8_(lang)));} - public static Wdata_prop_itm_core new_entity_(int pid, int v) {return new_(Wdata_prop_itm_base_.Val_tid_entity, pid, Bry_.XtoStrBytesByInt(v, 0));} - private static Wdata_prop_itm_core new_(byte tid, int pid, byte[] val) {return new Wdata_prop_itm_core(Wdata_prop_itm_base_.Snak_tid_value, pid, tid, val);} -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java index 64e8954e6..3bf074831 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr.java @@ -121,10 +121,10 @@ public class Wdata_wiki_mgr implements GfoInvkAble { return qids[qid_idx]; } public void Resolve_to_bfr(Bry_bfr bfr, Wdata_claim_grp prop_grp, byte[] lang_key) { - int len = prop_grp.Itms_len(); + int len = prop_grp.Len(); for (int i = 0; i < len; i++) { // NOTE: multiple props possible; EX: roles = scientist,painter if (i != 0) bfr.Add(Prop_tmpl_val_dlm); - Wdata_claim_itm_core prop = prop_grp.Itms_get_at(i); + Wdata_claim_itm_core prop = prop_grp.Get_at(i); switch (prop.Snak_tid()) { case Wdata_dict_snak_tid.Tid_novalue : bfr.Add(Wdata_dict_snak_tid.Bry_novalue); break; case Wdata_dict_snak_tid.Tid_somevalue : bfr.Add(Wdata_dict_snak_tid.Bry_somevalue); break; @@ -180,7 +180,8 @@ public class Wdata_wiki_mgr implements GfoInvkAble { private static final byte[] Ignore_comma = new byte[]{Byte_ascii.Comma}; private static final byte[] Bry_quantity_margin_of_error = Bry_.new_utf8_("±"); public static final byte[] Bry_q = Bry_.new_ascii_("q"), Prop_tmpl_val_dlm = Bry_.new_ascii_(", "); - public void Write_json_as_html(Bry_bfr bfr, byte[] data_raw) { + public void Write_json_as_html(Bry_bfr bfr, byte[] data_raw) {Write_json_as_html(jdoc_parser, bfr, data_raw);} + 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); // Json_doc json = jdoc_parser.Parse(data_raw); json.Root().Print_as_json(bfr, 0); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java index ee356defb..b1b7e0022 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_wiki_mgr_fxt.java @@ -25,7 +25,7 @@ public class Wdata_wiki_mgr_fxt { this.parser_fxt = parser_fxt; this.wiki = parser_fxt.Wiki(); app = wiki.App(); - page_bldr = new Wdata_doc_bldr(app.Wiki_mgr().Wdata_mgr()); + wdoc_bldr = new Wdata_doc_bldr(); wdata_mgr = app.Wiki_mgr().Wdata_mgr(); wdata_mgr.Clear(); if (reset) { @@ -33,19 +33,28 @@ public class Wdata_wiki_mgr_fxt { parser_fxt.Reset(); } return this; - } private Xoa_app app; Xow_wiki wiki; Wdata_wiki_mgr wdata_mgr; Wdata_doc_bldr page_bldr; Xop_fxt parser_fxt; + } private Xoa_app app; private Xow_wiki wiki; private Wdata_wiki_mgr wdata_mgr; private Wdata_doc_bldr wdoc_bldr; private Xop_fxt parser_fxt; public Xoa_app App() {return app;} - public Wdata_doc_bldr page_bldr_(String qid) {return page_bldr.Qid_(qid);} - public Wdata_claim_itm_core prop_novalue_(int pid) {return Wdata_claim_itm_system.new_novalue(pid);} - public Wdata_claim_itm_core prop_somevalue_(int pid) {return Wdata_claim_itm_system.new_somevalue(pid);} - public Wdata_claim_itm_core prop_str_(int pid, String val) {return prop_str_(pid, Bry_.new_utf8_(val));} - public Wdata_claim_itm_core prop_str_(int pid, byte[] val) {return new Wdata_claim_itm_str(pid, Wdata_dict_snak_tid.Tid_value, val);} - public Wdata_claim_itm_core prop_time_(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_doc_bldr.Xto_time(val), Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty);} - public Wdata_claim_itm_core prop_monolingualtext_(int pid, String text, String lang) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} - public Wdata_claim_itm_core prop_geodata_(int pid, String lat, String lon) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(lat), Bry_.new_ascii_(lon), Bry_.Empty, Bry_.Empty, Bry_.Empty);} - public Wdata_claim_itm_core prop_quantity_(int pid, String amount, String unit, String ubound, String lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(amount), Bry_.new_ascii_(unit), Bry_.new_ascii_(ubound), Bry_.new_ascii_(lbound));} - public Wdata_claim_itm_core prop_entity_(int pid, int val) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Int_.Xto_bry(val));} - public Wdata_doc doc_(String qid, Wdata_claim_itm_core... props) {return page_bldr.Qid_(qid).Props_add(props).Xto_page_doc();} + public Wdata_doc_bldr Wdoc_bldr(String qid) {return wdoc_bldr.Qid_(qid);} + public Wdata_claim_itm_core Make_claim_novalue(int pid) {return Wdata_claim_itm_system.new_novalue(pid);} + public Wdata_claim_itm_core Make_claim_somevalue(int pid) {return Wdata_claim_itm_system.new_somevalue(pid);} + public Wdata_claim_itm_core Make_claim_str(int pid, String val) {return Make_claim_str(pid, Bry_.new_utf8_(val));} + public Wdata_claim_itm_core Make_claim_str(int pid, byte[] val) {return new Wdata_claim_itm_str(pid, Wdata_dict_snak_tid.Tid_value, val);} + public Wdata_claim_itm_core Make_claim_time(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_time.Xto_time(val), Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty, Bry_.Empty);} + public Wdata_claim_itm_core Make_claim_monolingual(int pid, String lang, String text) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} + public Wdata_claim_itm_core Make_claim_geo(int pid, String lat, String lon) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(lat), Bry_.new_ascii_(lon), Bry_.Empty, Bry_.Empty, Bry_.Empty);} + public Wdata_claim_itm_core Make_claim_quantity(int pid, String amount, String unit, String ubound, String lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_ascii_(amount), Bry_.new_ascii_(unit), Bry_.new_ascii_(ubound), Bry_.new_ascii_(lbound));} + public Wdata_claim_itm_core Make_claim_entity(int pid, int val) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Int_.Xto_bry(val));} + public Wdata_claim_grp Make_qualifiers_grp(int pid, Wdata_claim_itm_core... ary) {return new Wdata_claim_grp(Int_obj_ref.new_(pid), ary);} + public Wdata_claim_grp_list Make_qualifiers(Wdata_claim_grp... ary) { + Wdata_claim_grp_list rv = new Wdata_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, Wdata_claim_itm_core... 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++) { diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java index 86e7863a6..a8ebbb401 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr.java @@ -36,7 +36,7 @@ public class Wdata_xwiki_link_wtr implements Bry_fmtr_arg { Wdata_wiki_mgr wdata_mgr = wiki.App().Wiki_mgr().Wdata_mgr(); Wdata_doc doc = wdata_mgr.Pages_get(wiki, ttl); if (doc == null) return Qid_null; // no links boolean external_links_mgr_enabled = external_links_mgr.Enabled(); - OrderedHash links = doc.Sitelink_list(); + OrderedHash links = doc.Slink_list(); Bry_bfr tmp_bfr = wiki.App().Utl_bry_bfr_mkr().Get_k004(); Xow_wiki_abrv wiki_abrv = new Xow_wiki_abrv(); int len = links.Count(); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr_tst.java index 35c37dc79..485b1570d 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_xwiki_link_wtr_tst.java @@ -22,13 +22,13 @@ public class Wdata_xwiki_link_wtr_tst { @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_wiki_domain_.Tid_wikipedia, "Q1_en", "Q1"); - fxt.Init_pages_add(fxt.page_bldr_("Q1").Link_add("enwiki", "Q1_en").Link_add("frwiki", "Q1_fr").Link_add("dewiki", "Q1_de").Xto_page_doc()); + fxt.Init_pages_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_wiki_domain_.Tid_wikipedia, "Q1_en", "Q1"); - fxt.Init_pages_add(fxt.page_bldr_("Q1").Link_add("enwiki", "Q1_en").Link_add("frwiki", "Q1_fr").Link_add("dewiki", "Q1_de").Xto_page_doc()); + fxt.Init_pages_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(); @@ -94,7 +94,7 @@ public class Wdata_xwiki_link_wtr_tst { // @Test public void No_external_lang_links__sort() { // fxt.Init_xwikis_add("de", "fr"); // fxt.Init_qids_add("en", Xow_wiki_domain_.Tid_wikipedia, "Q1_en", "Q1"); -// fxt.Init_pages_add("Q1", fxt.page_bldr_("Q1").Link_add("enwiki", "Q1_en").Link_add("frwiki", "Q1_fr").Link_add("dewiki", "Q1_de").Xto_page_doc()); +// fxt.Init_pages_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(); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp.java index 80a4c98f0..53d9e5fa6 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp.java @@ -20,16 +20,17 @@ public class Wdata_claim_grp { public Wdata_claim_grp(Int_obj_ref id_ref, Wdata_claim_itm_core[] 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 int Itms_len() {return itms.length;} private Wdata_claim_itm_core[] itms; - public Wdata_claim_itm_core Itms_get_at(int i) {return itms[i];} + public String Id_str() {if (id_str == null) id_str = "P" + Int_.Xto_str(id_ref.Val()); return id_str;} private String id_str; + public int Len() {return itms.length;} private Wdata_claim_itm_core[] itms; + public Wdata_claim_itm_core Get_at(int i) {return itms[i];} public static ListAdp Xto_list(OrderedHash hash) { int len = hash.Count(); ListAdp rv = ListAdp_.new_(); for (int i = 0; i < len; ++i) { Wdata_claim_grp grp = (Wdata_claim_grp)hash.FetchAt(i); - int grp_len = grp.Itms_len(); + int grp_len = grp.Len(); for (int j = 0; j < grp_len; ++j) - rv.Add(grp.Itms_get_at(j)); + rv.Add(grp.Get_at(j)); } return rv; } diff --git a/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp_list.java similarity index 61% rename from 400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_mgr.java rename to 400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp_list.java index ecaaa4ef1..2c11c77f2 100644 --- a/400_xowa/src/gplx/xowa/hdumps/htmls/Hdump_html_mgr.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_grp_list.java @@ -15,13 +15,10 @@ 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 . */ -package gplx.xowa.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.hdumps.*; -import gplx.xowa.hdumps.core.*; -public class Hdump_html_mgr { - private Hdump_html_body body_fmtr = new Hdump_html_body(); - public Hdump_html_mgr Init_by_app(Xoa_app app) {body_fmtr.Init_by_app(app); return this;} - public void Write(Bry_bfr bfr, Xow_wiki wiki, Hdump_page page) { - body_fmtr.Init_by_page(wiki, page); - body_fmtr.XferAry(bfr, 0); - } +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_claim_grp_list { + private OrderedHash hash = OrderedHash_.new_(); + public void Add(Wdata_claim_grp itm) {hash.Add(itm.Id_ref(), itm);} + public int Len() {return hash.Count();} + public Wdata_claim_grp Get_at(int i) {return (Wdata_claim_grp)hash.FetchAt(i);} } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java index b8b836a7a..cf3da9f18 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_base.java @@ -25,7 +25,7 @@ public abstract class Wdata_claim_itm_base implements CompareAble { public int Pid() {return pid;} private int pid; public abstract byte Val_tid(); public byte Snak_tid() {return snak_tid;} private byte snak_tid = Wdata_dict_snak_tid.Tid_value; - public byte Rank_tid() {return rank_tid;} public void Rank_tid_(byte v) {this.rank_tid = v;} private byte rank_tid; + public byte Rank_tid() {return rank_tid;} public void Rank_tid_(byte v) {this.rank_tid = v;} private byte rank_tid = Wdata_dict_rank.Tid_normal; // TEST: default to normal for tests public int compareTo(Object obj) { Wdata_claim_itm_base comp = (Wdata_claim_itm_base)obj; return Int_.Compare(pid, comp.pid); diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java index 7ddbb087b..e5c12ae9d 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_core.java @@ -19,6 +19,7 @@ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gp public abstract class Wdata_claim_itm_core extends Wdata_claim_itm_base { public byte[] Wguid() {return wguid;} public void Wguid_(byte[] v) {this.wguid = v;} private byte[] wguid; public String Prop_type() {return Prop_type_statement;} private static final String Prop_type_statement = "statement"; - public Wdata_claim_itm_base[] Qual_ary() {return qual_ary;} public void Qual_ary_(Wdata_claim_itm_base[] v) {this.qual_ary = v;} private Wdata_claim_itm_base[] qual_ary; - public Wdata_claim_itm_base[] Ref_ary() {return ref_ary;} public void Ref_ary_(Wdata_claim_itm_base[] v) {this.ref_ary = v;} private Wdata_claim_itm_base[] ref_ary; + public Wdata_claim_grp_list Qualifiers() {return qualifiers;} public Wdata_claim_itm_core Qualifiers_(Wdata_claim_grp_list v) {qualifiers = v; return this;} private Wdata_claim_grp_list qualifiers; + public int[] Qualifiers_order() {return qualifiers_order;} public void Qualifiers_order_(int[] v) {qualifiers_order = v;} private int[] qualifiers_order; + public Wdata_references_grp[] References() {return references;} public void References_(Wdata_references_grp[] v) {references = v;} private Wdata_references_grp[] references; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java index eddafaf18..aa8c8ab52 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_quantity.java @@ -22,10 +22,23 @@ public class Wdata_claim_itm_quantity extends Wdata_claim_itm_core { public Wda } @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_quantity;} public byte[] Amount() {return amount;} private final byte[] amount; - public byte[] Unit() {return unit;} private final byte[] unit; + public long Amount_as_long() { + if (amount_as_long == Long_.MinValue) amount_as_long = Long_.parse_(String_.new_ascii_(amount)); + return amount_as_long; + } private long amount_as_long = Long_.MinValue; public byte[] Ubound() {return ubound;} private final byte[] ubound; + public long Ubound_as_long() { + if (ubound_as_long == Long_.MinValue) ubound_as_long = Long_.parse_(String_.new_ascii_(ubound)); + return ubound_as_long; + } private long ubound_as_long = Long_.MinValue; public byte[] Lbound() {return lbound;} private final byte[] lbound; + public long Lbound_as_long() { + if (lbound_as_long == Long_.MinValue) lbound_as_long = Long_.parse_(String_.new_ascii_(lbound)); + return lbound_as_long; + } private long lbound_as_long = Long_.MinValue; + public byte[] Unit() {return unit;} private final byte[] unit; @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(amount), String_.new_utf8_(unit), String_.new_utf8_(ubound), String_.new_utf8_(lbound)); } + public static final byte[] Unit_1 = Bry_.new_ascii_("1"); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java index 4e1829ea4..e8f90c718 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_str.java @@ -21,7 +21,7 @@ public class Wdata_claim_itm_str extends Wdata_claim_itm_core { public Wdata_cl this.val = val; } @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_string;} - public byte[] Val_str() {return val;} private final byte[] val; + public byte[] Val_str() {return val;} private final byte[] val; @Override public String toString() {// TEST: return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_utf8_(val)); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java index 525b1bf7f..330667730 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_claim_itm_time.java @@ -22,6 +22,10 @@ public class Wdata_claim_itm_time extends Wdata_claim_itm_core { public Wdata_c } @Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_time;} public byte[] Time() {return time;} private final byte[] time; + public Wdata_date Time_as_date() { + if (time_as_date == null) time_as_date = Wdata_date.parse(time); + return time_as_date; + } private Wdata_date time_as_date; 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; diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date.java new file mode 100644 index 000000000..4364da1e5 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_date { + public Wdata_date(long year, int month, int day, int hour, int minute, int second) {this.year = year; this.month = month; this.day = day; this.hour = hour; this.minute = minute; this.second = second;} + 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 static Wdata_date parse(byte[] bry) {// EX:+00000002001-02-03T04:05:06Z + int year_sign = 1; + switch (bry[0]) { + case Byte_ascii.Plus: break; + case Byte_ascii.Dash: year_sign = -1; break; + default: throw Err_.unhandled(bry[0]); + } + int year_end = Bry_finder.Find_fwd(bry, Byte_ascii.Dash, 1); + long year = Long_.parse_or_(String_.new_ascii_(bry, 1, year_end), -1); if (year == -1) throw Err_.new_("parse failed; raw={0}", String_.new_ascii_(bry)); + int month = Bry_.Xto_int_or(bry, year_end + 1, year_end + 3, -1); + int day = Bry_.Xto_int_or(bry, year_end + 4, year_end + 6, -1); + int hour = Bry_.Xto_int_or(bry, year_end + 7, year_end + 9, -1); + int minute = Bry_.Xto_int_or(bry, year_end + 10, year_end + 12, -1); + int second = Bry_.Xto_int_or(bry, year_end + 13, year_end + 15, -1); + return new Wdata_date(year * year_sign, month, day, hour, minute, second); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date_tst.java new file mode 100644 index 000000000..b2c1eb99f --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_date_tst.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; +public class Wdata_date_tst { + @Before public void init() {} private Wdata_date_fxt fxt = new Wdata_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); + } +} +class Wdata_date_fxt { + public void Test_parse(String raw, long expd_y, int expd_m, int expd_d, int expd_h, int expd_n, int expd_s) { + Wdata_date actl_date = Wdata_date.parse(Bry_.new_ascii_(raw)); + 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()); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim.java index f4f3fbdde..23f7d30f7 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_claim.java @@ -26,14 +26,23 @@ public class Wdata_dict_claim { , 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_ascii_("mainsnak") - , Bry_type = Bry_.new_ascii_("type") - , Bry_id = Bry_.new_ascii_("id") - , Bry_rank = Bry_.new_ascii_("rank") - , Bry_references = Bry_.new_ascii_("references") - , Bry_qualifiers = Bry_.new_ascii_("qualifiers") - , Bry_qualifiers_order = Bry_.new_ascii_("qualifiers-order") + Bry_mainsnak = Bry_.new_ascii_(Str_mainsnak) + , Bry_type = Bry_.new_ascii_(Str_type) + , Bry_id = Bry_.new_ascii_(Str_id) + , Bry_rank = Bry_.new_ascii_(Str_rank) + , Bry_references = Bry_.new_ascii_(Str_references) + , Bry_qualifiers = Bry_.new_ascii_(Str_qualifiers) + , Bry_qualifiers_order = Bry_.new_ascii_(Str_qualifiers_order) ; public static final Hash_adp_bry Dict = Hash_adp_bry.cs_() .Add_bry_byte(Bry_mainsnak , Tid_mainsnak) diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_datavalue.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_datavalue.java index f3e1ea258..3077de92c 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_datavalue.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_datavalue.java @@ -20,13 +20,21 @@ 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_ascii_("value") - , Bry_type = Bry_.new_ascii_("type") + Bry_value = Bry_.new_ascii_(Str_value) + , Bry_type = Bry_.new_ascii_(Str_type) + , Bry_error = Bry_.new_ascii_(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) ; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_reference.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_reference.java new file mode 100644 index 000000000..8b937beee --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_reference.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +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_ascii_(Str_hash) + , Bry_snaks = Bry_.new_ascii_(Str_snaks) + , Bry_snaks_order = Bry_.new_ascii_(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_.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_.unhandled(v); + } + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_utl.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_utl.java index e481e4270..49cac30b8 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_utl.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_utl.java @@ -17,9 +17,13 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; public class Wdata_dict_utl { - public static byte Get_tid_or_fail(Hash_adp_bry dict, byte[] key) { + 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) throw Err_.new_("unknown key; key={0}", String_.new_ascii_(key)); + if (rv_obj == null) { + Gfo_usr_dlg_._.Warn_many("", "", "unknown wikidata key; qid=~{0} key=~{1}", String_.new_utf8_(qid), String_.new_utf8_(key)); + return Tid_invalid; + } return ((Byte_obj_val)rv_obj).Val(); } + public static final byte Tid_invalid = Byte_.MaxValue_127; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_val_tid.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_val_tid.java index 4e767c3c0..70050727b 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_val_tid.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_val_tid.java @@ -46,6 +46,7 @@ public class Wdata_dict_val_tid { , Bry_globecoordinate = Bry_.new_ascii_(Str_globecoordinate) , Bry_quantity = Bry_.new_ascii_(Str_quantity) , Bry_monolingualtext = Bry_.new_ascii_(Str_monolingualtext) + , Bry_unknown = Bry_.new_ascii_(Str_unknown) ; private static final Hash_adp_bry Dict = Hash_adp_bry.cs_() .Add_bry_byte(Bry_string , Tid_string) diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_time.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_time.java index 9da1368b7..1bb648354 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_time.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_dict_value_time.java @@ -69,4 +69,25 @@ public class Wdata_dict_value_time { , Val_timezone_bry = Bry_.new_ascii_(Val_timezone_str) , Val_calendarmodel_bry = Bry_.new_ascii_(Val_calendarmodel_str) ; + public static byte[] Xto_time(String date) {return Xto_time(DateAdp_.parse_fmt(date, "yyyy-MM-dd HH:mm:ss"));} + public static byte[] Xto_time(DateAdp date) { + // +0000000yyyy-MM-ddTHH:mm:ssZ + tmp_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 tmp_bfr.XtoAryAndClear(); + } + private static Bry_bfr tmp_bfr = Bry_bfr.new_(); private static byte[] Bry_year_prefix = Bry_.new_ascii_("+0000000"); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java index f9c030e01..f96e7cea8 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_langtext_itm.java @@ -17,10 +17,11 @@ along with this program. If not, see . */ package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import gplx.json.*; -public class Wdata_langtext_itm { - public Wdata_langtext_itm(byte[] lang, byte[] text) {this.lang = lang; this.text = text;} - public byte[] Lang() {return lang;} private byte[] lang; - public byte[] Text() {return text;} private byte[] text; +public class Wdata_langtext_itm implements Wdata_sortable { + public Wdata_langtext_itm(byte[] lang, byte[] text) {this.lang = lang; this.text = text; this.sort = -1;} + public byte[] Lang() {return lang;} private final byte[] lang; + public byte[] Text() {return text;} private final byte[] text; + public int Sort() {return sort;} public void Sort_(int v) {sort = v;} private int sort; @Override public String toString() {// TEST: return String_.Concat_with_str("|", String_.new_utf8_(lang), String_.new_utf8_(text)); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_references_grp.java similarity index 56% rename from 400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_tst.java rename to 400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_references_grp.java index d6f7f932d..85adbfd8e 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_doc_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_references_grp.java @@ -15,16 +15,9 @@ 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 . */ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import org.junit.*; import gplx.json.*; -public class Wdata_doc_tst { - @Test public void Link_extract() { - Tst_link_extract("{\"enwiki\":\"A\"}", "A"); - Tst_link_extract("{\"enwiki\":{\"name\":\"A\",\"badges\":[]}}", "A"); - } - private void Tst_link_extract(String src, String expd) { - Json_doc doc = Json_doc.new_(src); - Json_itm_kv root = (Json_itm_kv)doc.Root().Subs_get_at(0); - Tfds.Eq(expd, String_.new_ascii_(Wdata_doc_.Link_extract(root))); - } +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public class Wdata_references_grp { + public Wdata_references_grp(Wdata_claim_grp_list references, int[] references_order) {this.references = references; this.references_order = references_order;} + public Wdata_claim_grp_list References() {return references;} private Wdata_claim_grp_list references; + public int[] References_order() {return references_order;} private int[] references_order; } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_wbreponame_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sortable.java similarity index 52% rename from 400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_wbreponame_tst.java rename to 400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sortable.java index d46d121a4..629e6b7b2 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/Wdata_pf_wbreponame_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/core/Wdata_sortable.java @@ -15,22 +15,8 @@ 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 . */ -package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; -import org.junit.*; -public class Wdata_pf_wbreponame_tst { - @Before public void init() {fxt.Clear();} private Wdata_pf_wbreponame_fxt fxt = new Wdata_pf_wbreponame_fxt(); - @Test public void Basic() { - fxt.Test_parse("{{wbreponame}}", "Wikidata"); - } -} -class Wdata_pf_wbreponame_fxt { - public Wdata_pf_wbreponame_fxt Clear() { - if (parser_fxt == null) { - parser_fxt = new Xop_fxt(); - } - return this; - } private Xop_fxt parser_fxt; - public void Test_parse(String raw, String expd) { - parser_fxt.Test_html_full_str(raw, expd); - } +package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +public interface Wdata_sortable { + byte[] Lang(); + int Sort(); void Sort_(int v); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__json.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__json.java new file mode 100644 index 000000000..111b875d3 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__json.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; +class Wdata_fmtr__json implements Bry_fmtr_arg { + private byte[] tbl_hdr; private Json_doc jdoc; private Json_parser jdoc_parser; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + public void Init_by_ctor(Json_parser jdoc_parser) {this.jdoc_parser = jdoc_parser;} + public void Init_by_lang(byte[] tbl_hdr) {this.tbl_hdr = tbl_hdr;} + public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, Json_doc jdoc) { + fmtr_toc.Add(tbl_hdr); + this.jdoc = jdoc; + } + public void XferAry(Bry_bfr bfr, int idx) { + if (jdoc == null) return; + Wdata_wiki_mgr.Write_json_as_html(jdoc_parser, tmp_bfr, jdoc.Src()); + fmtr.Bld_bfr_many(bfr, tbl_hdr, tmp_bfr.XtoAryAndClear()); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "

~{hdr}

" + , "" + , "~{json}" + ), "hdr", "json"); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__sitelink_tbl.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__sitelink_tbl.java new file mode 100644 index 000000000..676fc9e84 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__sitelink_tbl.java @@ -0,0 +1,104 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.html.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.wikis.*; +class Wdata_fmtr__sitelink_tbl implements Bry_fmtr_arg { + private Wdata_fmtr__sitelink_row fmtr_row = new Wdata_fmtr__sitelink_row(); + private Wdata_hwtr_msgs msgs; private byte[] col_hdr_lang, col_hdr_text, col_hdr_bdgs; private int list_len; + public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {fmtr_row.Init_by_ctor(lbl_regy);} + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + this.col_hdr_lang = msgs.Slink_col_hdr_site(); this.col_hdr_text = msgs.Slink_col_hdr_text(); this.col_hdr_bdgs = msgs.Slink_col_hdr_bdgs(); + this.msgs = msgs; + } + public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, OrderedHash list) { + this.list_len = list.Count(); if (list_len == 0) return; + fmtr_toc.Add(msgs.Slink_tbl_hdr()); + fmtr_row.Init_by_page(list); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (list_len == 0) return; + fmtr.Bld_bfr_many(bfr, msgs.Slink_tbl_hdr(), col_hdr_lang, col_hdr_text, col_hdr_bdgs, fmtr_row); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "

~{hdr}

" + , "" + , "" + , " " + , " " + , " " + , " " + , " ~{rows}" + , "
~{site_lbl}~{link_lbl}~{bdgs_lbl}
" + ), "hdr", "site_lbl", "link_lbl", "bdgs_lbl", "rows" + ); +} +class Wdata_fmtr__sitelink_row implements Wdata_fmtr__row { + private Wdata_lbl_mgr lbl_regy; private OrderedHash list; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {this.lbl_regy = lbl_regy;} + public void Init_by_page(OrderedHash list) {this.list = list;} + public void XferAry(Bry_bfr bfr, int idx) { + lbl_regy.getClass(); + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i); + byte[] site = itm.Site(); + byte[] domain_bry = Xob_bz2_file.Parse__domain_name(site, 0, site.length); + byte[][] badges_ary = itm.Badges(); + int badges_len = badges_ary.length; + for (int j = 0; j < badges_len; ++j) { + byte[] val = badges_ary[j]; + if (j != 0) tmp_bfr.Add(Html_tag_.Br_inl); + tmp_bfr.Add(Html_utl.Escape_html_as_bry(val)); + } + row_fmtr.Bld_bfr_many(bfr, site, domain_bry, itm.Name()); + } + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " ~{site}" + , "
~{page}" + , " " + ), "site", "domain", "page" + ); +} +// class Wdata_slink_grp { +// public Wdata_slink_grp(int tid, byte[] tbl_hdr) {this.tid = tid; this.tbl_hdr = tbl_hdr;} +// public int Tid() {return tid;} private final int tid; +// public byte[] Tbl_hdr() {return tbl_hdr;} private final byte[] tbl_hdr; +// public OrderedHash Rows() {return rows;} private final OrderedHash rows = OrderedHash_.new_(); +// public static Wdata_slink_grp[] new_(OrderedHash list) { +// ListAdp rv = ListAdp_.new_(); +// int list_len = list.Count(); +// for (int i = 0; i < list_len; ++i) { +// Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.FetchAt(i); +// byte[] site = itm.Site(); +// byte[] domain = Xob_bz2_file.Parse__domain_name(site, 0, site.length); +// Xow_wiki_domain domain_tid = Xow_wiki_domain_.parse_by_domain(domain); +// domain_tid.Tid +// } +//// ListAdp list +//// int grps_len = 0; +//// OrderedHash[] grps = new OrderedHash[grps_len]; +// // sort by tid +// // iterate and add to list +// return (Wdata_slink_grp[])rv.XtoAryAndClear(typeof(ListAdp)); +// } +// // , Tid_wikipedia = 2, Tid_wiktionary = 3, Tid_wikisource = 4, Tid_wikibooks = 5, Tid_wikiversity = 6, Tid_wikiquote = 7, Tid_wikinews = 8, Tid_wikivoyage = 9, Tid_commons = 10 +// } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc_div.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc_div.java new file mode 100644 index 000000000..9cc019d9d --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtr__toc_div.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +class Wdata_fmtr__toc_div implements Bry_fmtr_arg { + private Wdata_fmtr__toc_itm fmtr_itm = new Wdata_fmtr__toc_itm(); + private byte[] tbl_hdr; private ListAdp itms = ListAdp_.new_(); + public void Init_by_ctor(Url_encoder href_encoder) {fmtr_itm.Init_by_ctor(href_encoder);} + 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(byte[] hdr) {itms.Add(hdr);} + public void XferAry(Bry_bfr bfr, int idx) { + int itms_len = itms.Count(); + if (itms_len < 3) return; + fmtr_itm.Init_by_page((byte[][])itms.XtoAryAndClear(byte[].class)); + fmtr.Bld_bfr_many(bfr, tbl_hdr, fmtr_itm); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "

" + , "

" + , "

~{hdr}

" + , "
    ~{itms}" + , "
" + , " " + ), "hdr", "itms"); +} +class Wdata_fmtr__toc_itm implements Bry_fmtr_arg { + private byte[][] hdrs; private Url_encoder href_encoder; + public void Init_by_ctor(Url_encoder href_encoder) {this.href_encoder = href_encoder;} + public void Init_by_page(byte[][] hdrs) {this.hdrs = hdrs;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = hdrs.length; + for (int i = 0; i < len; ++i) { + byte[] hdr = hdrs[i]; + fmtr.Bld_bfr_many(bfr, i + ListAdp_.Base1, href_encoder.Encode(hdr), hdr); + } + } + private Bry_fmtr fmtr = Bry_fmtr.new_ + ( "
  • ~{idx} ~{hdr}
  • " + , "idx", "href", "text"); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtrs.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtrs.java new file mode 100644 index 000000000..62d0825a1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_fmtrs.java @@ -0,0 +1,216 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.html.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; +import gplx.xowa.wikis.*; +interface Wdata_fmtr__row extends Bry_fmtr_arg { + void Init_by_page(OrderedHash list); +} +class Wdata_fmtr__langtext_tbl implements Bry_fmtr_arg { + private Wdata_fmtr__row fmtr_row; + private byte[] tbl_hdr, col_hdr_lang, col_hdr_text; private int list_len; + public void Init_by_ctor(Wdata_fmtr__row fmtr_row) {this.fmtr_row = fmtr_row;} + public void Init_by_lang(byte[] tbl_hdr, byte[] col_hdr_lang, byte[] col_hdr_text) { + this.tbl_hdr = tbl_hdr; this.col_hdr_lang = col_hdr_lang; this.col_hdr_text = col_hdr_text; + } + public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, OrderedHash list) { + this.list_len = list.Count(); if (list_len == 0) return; + fmtr_toc.Add(tbl_hdr); + fmtr_row.Init_by_page(list); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (list_len == 0) return; + fmtr.Bld_bfr_many(bfr, tbl_hdr, col_hdr_lang, col_hdr_text, fmtr_row); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "

    ~{hdr}

    " + , "" + , "" + , " " + , " " + , " " + , " ~{rows}" + , "
    ~{lang_lbl}~{text_lbl}
    " + ), "hdr", "lang_lbl", "text_lbl", "rows"); +} +class Wdata_fmtr__langtext_row implements Wdata_fmtr__row { + private OrderedHash list; + public void Init_by_page(OrderedHash list) {this.list = list;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_langtext_itm itm = (Wdata_langtext_itm)list.FetchAt(i); + row_fmtr.Bld_bfr_many(bfr, itm.Lang(), Html_utl.Escape_html_as_bry(itm.Text())); + } + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " ~{lang}" + , " ~{text}" + , " " + ), "lang", "text"); +} +class Wdata_fmtr__alias_row implements Wdata_fmtr__row { + private OrderedHash list; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + public void Init_by_page(OrderedHash list) {this.list = list;} + public void XferAry(Bry_bfr bfr, int idx) { + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_alias_itm itm = (Wdata_alias_itm)list.FetchAt(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]; + if (j != 0) tmp_bfr.Add(Html_tag_.Br_inl); + tmp_bfr.Add(Html_utl.Escape_html_as_bry(val)); + } + row_fmtr.Bld_bfr_many(bfr, itm.Lang(), tmp_bfr.XtoAryAndClear()); + } + } + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " ~{lang}" + , " ~{text}" + , " " + ), "lang", "text"); +} +class Wdata_fmtr__claim_tbl implements Bry_fmtr_arg { + public Wdata_fmtr__claim_row Fmtr_row() {return fmtr_row;} private Wdata_fmtr__claim_row fmtr_row = new Wdata_fmtr__claim_row(); private int list_len; + private byte[] tbl_hdr, col_hdr_prop_id, col_hdr_prop_name, col_hdr_val, col_hdr_ref, col_hdr_qual, col_hdr_rank; + public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {fmtr_row.Init_by_ctor(lbl_regy);} + public void Init_by_lang(Wdata_hwtr_msgs msgs, byte[] tbl_hdr, byte[] col_hdr_prop_id, byte[] col_hdr_prop_name, byte[] col_hdr_val, byte[] col_hdr_ref, byte[] col_hdr_qual, byte[] col_hdr_rank) { + fmtr_row.Init_by_lang(msgs); + this.tbl_hdr = tbl_hdr; this.col_hdr_prop_id = col_hdr_prop_id; this.col_hdr_prop_name = col_hdr_prop_name; + this.col_hdr_val = col_hdr_val; this.col_hdr_ref = col_hdr_ref; this.col_hdr_qual = col_hdr_qual; this.col_hdr_rank = col_hdr_rank; + } + public void Init_by_wdoc(Wdata_fmtr__toc_div fmtr_toc, OrderedHash list) { + this.list_len = list.Count(); if (list_len == 0) return; + fmtr_toc.Add(tbl_hdr); + fmtr_row.Init_by_page(list); + } + public void XferAry(Bry_bfr bfr, int idx) { + if (list_len == 0) return; + fmtr.Bld_bfr_many(bfr, tbl_hdr, col_hdr_prop_id, col_hdr_prop_name, col_hdr_val, col_hdr_ref, col_hdr_qual, col_hdr_rank, fmtr_row); + } + private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , "

    ~{hdr}

    " + , "" + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " ~{rows}" + , "
    ~{prop_id}~{prop_name}~{val}~{ref}~{qual}~{rank}
    " + ), "hdr", "prop_id", "prop_name", "val", "ref", "qual", "rank", "rows"); +} +class Wdata_fmtr__claim_row implements Wdata_fmtr__row { + private Wdata_lbl_mgr lbl_regy; private Wdata_hwtr_msgs msgs; + private OrderedHash list; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255); + public void Init_by_ctor(Wdata_lbl_mgr lbl_regy) {this.lbl_regy = lbl_regy;} + public void Init_by_lang(Wdata_hwtr_msgs msgs) {this.msgs = msgs;} + public void Init_by_page(OrderedHash list) {this.list = list;} + public void XferAry(Bry_bfr bfr, int idx) { + lbl_regy.getClass(); + int len = list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_claim_grp grp = (Wdata_claim_grp)list.FetchAt(i); + int grp_len = grp.Len(); + for (int j = 0; j < grp_len; ++j) { + Wdata_claim_itm_core itm = grp.Get_at(j); + byte[] val = Calc_val(itm); + byte[] pid_name = lbl_regy.Pid_regy().Get_text_or_empty(itm.Pid()); + row_fmtr.Bld_bfr_many(bfr, itm.Pid(), pid_name, val, "", "", Wdata_dict_rank.Xto_str(itm.Rank_tid())); + } + } + } + public byte[] Calc_val(Wdata_claim_itm_core itm) { + switch (itm.Val_tid()) { + case Wdata_dict_val_tid.Tid_string: + return ((Wdata_claim_itm_str)itm).Val_str(); + case Wdata_dict_val_tid.Tid_monolingualtext: + Wdata_claim_itm_monolingualtext monolingual = (Wdata_claim_itm_monolingualtext)itm; + tmp_bfr.Add_byte(Byte_ascii.Brack_bgn).Add(monolingual.Lang()).Add_byte(Byte_ascii.Brack_end).Add_byte(Byte_ascii.Space); + tmp_bfr.Add(monolingual.Text()); + return tmp_bfr.XtoAryAndClear(); + case Wdata_dict_val_tid.Tid_time: + Wdata_claim_itm_time time = (Wdata_claim_itm_time)itm; + Wdata_date date = time.Time_as_date(); + tmp_bfr.Add_long_variable(date.Year()); + tmp_bfr.Add_byte(Byte_ascii.Dash) .Add_int_fixed(date.Month() , 2); + tmp_bfr.Add_byte(Byte_ascii.Dash) .Add_int_fixed(date.Day() , 2); + tmp_bfr.Add_byte(Byte_ascii.Space) .Add_int_fixed(date.Hour() , 2); + tmp_bfr.Add_byte(Byte_ascii.Colon) .Add_int_fixed(date.Minute(), 2); + tmp_bfr.Add_byte(Byte_ascii.Colon) .Add_int_fixed(date.Second(), 2); + return tmp_bfr.XtoAryAndClear(); + case Wdata_dict_val_tid.Tid_quantity: + Wdata_claim_itm_quantity quantity = (Wdata_claim_itm_quantity)itm; + long amount = quantity.Amount_as_long(); + long ubound = quantity.Ubound_as_long(); + long lbound = quantity.Lbound_as_long(); + long udiff = ubound - amount; + long ldiff = amount - lbound; + tmp_bfr.Add(quantity.Amount()).Add_byte_space(); + if (udiff == ldiff) { // delta is same in both directions; EX: amount=50 ubound=60 lbound=40 -> udiff == ldiff == 10 + if (udiff != 0) // skip if 0 + tmp_bfr.Add(msgs.Sym_plusminus()).Add_long_variable(udiff); + } + else { // delta is diff in both directions; EX: amount=50 ubound=60 lbound=30 -> udiff == 10, ldiff == 20 + if (udiff != 0) // skip if 0 + tmp_bfr.Add(msgs.Sym_plus()).Add_long_variable(udiff); + if (ldiff != 0) { // skip if 0 + if (udiff != 0) tmp_bfr.Add(Time_plus_minus_spr); + tmp_bfr.Add(msgs.Sym_minus()).Add_long_variable(ldiff); + } + } + byte[] unit = quantity.Unit(); + if (!Bry_.Eq(unit, Wdata_claim_itm_quantity.Unit_1)) + tmp_bfr.Add_byte_space().Add(unit); + return tmp_bfr.XtoAryAndClear(); + case Wdata_dict_val_tid.Tid_globecoordinate: + case Wdata_dict_val_tid.Tid_bad: + // Wdata_claim_itm_globecoordinate globecoordinate = (Wdata_claim_itm_globecoordinate)itm; + break; + case Wdata_dict_val_tid.Tid_entity: + Wdata_claim_itm_entity entity = (Wdata_claim_itm_entity)itm; + return lbl_regy.Qid_regy().Get_text_or_empty(entity.Entity_id()); + case Wdata_dict_val_tid.Tid_unknown: + return Wdata_dict_val_tid.Bry_unknown; + } + return null; + } private static final byte[] Time_plus_minus_spr = Bry_.new_ascii_(" / "); + private Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last + ( "" + , " " + , " ~{prop_id}" + , " ~{prop_name}" + , " ~{val}" + , " ~{ref}" + , " ~{qual}" + , " ~{rank}" + , " " + ), "prop_id", "prop_name", "val", "ref", "qual", "rank" + ); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr.java new file mode 100644 index 000000000..2f586c417 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr.java @@ -0,0 +1,65 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; +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_tbl Fmtr_claim() {return fmtr_claim;} private final Wdata_fmtr__claim_tbl fmtr_claim = new Wdata_fmtr__claim_tbl(); + 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__sitelink_tbl fmtr_slink = new Wdata_fmtr__sitelink_tbl(); + public Bry_fmtr Fmtr_main() {return fmtr_main;} private final Bry_fmtr fmtr_main = Bry_fmtr.new_("~{toc}~{claims}~{labels}~{aliases}~{descriptions}~{links}~{json}", "toc", "claims", "labels", "aliases", "descriptions", "links", "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(); + @gplx.Internal protected void Init_by_ctor(Json_parser jdoc_parser, Wdata_lbl_wkr lbl_wkr, Url_encoder href_encoder) { + lbl_mgr.Wkr_(lbl_wkr); + fmtr_toc.Init_by_ctor(href_encoder); + fmtr_claim.Init_by_ctor(lbl_mgr); + fmtr_label.Init_by_ctor(new Wdata_fmtr__langtext_row()); + fmtr_alias.Init_by_ctor(new Wdata_fmtr__alias_row()); + fmtr_descr.Init_by_ctor(new Wdata_fmtr__langtext_row()); + fmtr_slink.Init_by_ctor(lbl_mgr); + fmtr_json.Init_by_ctor(jdoc_parser); + } + public void Init_by_lang(Wdata_hwtr_msgs msgs) { + this.msgs = msgs; + fmtr_claim.Init_by_lang(msgs, msgs.Claim_tbl_hdr(), msgs.Claim_col_hdr_prop_id(), msgs.Claim_col_hdr_prop_name(), msgs.Claim_col_hdr_val(), msgs.Claim_col_hdr_ref(), msgs.Claim_col_hdr_qual(), msgs.Claim_col_hdr_rank()); + fmtr_label.Init_by_lang(msgs.Label_tbl_hdr(), msgs.Label_col_hdr_lang(), msgs.Label_col_hdr_text()); + fmtr_alias.Init_by_lang(msgs.Alias_tbl_hdr(), msgs.Alias_col_hdr_lang(), msgs.Alias_col_hdr_text()); + fmtr_descr.Init_by_lang(msgs.Descr_tbl_hdr(), msgs.Descr_col_hdr_lang(), msgs.Descr_col_hdr_text()); + fmtr_slink.Init_by_lang(msgs); + fmtr_json.Init_by_lang(msgs.Json_tbl_hdr()); + } + public void Init_by_wdoc(Wdata_doc wdoc) { + fmtr_toc .Init_by_wdoc(wdoc); + fmtr_claim.Init_by_wdoc(fmtr_toc, wdoc.Claim_list()); + fmtr_label.Init_by_wdoc(fmtr_toc, wdoc.Label_list()); + fmtr_alias.Init_by_wdoc(fmtr_toc, wdoc.Alias_list()); + fmtr_descr.Init_by_wdoc(fmtr_toc, wdoc.Descr_list()); + fmtr_slink.Init_by_wdoc(fmtr_toc, wdoc.Slink_list()); + fmtr_json.Init_by_wdoc (fmtr_toc, wdoc.Jdoc()); + lbl_mgr.Gather_labels(wdoc); + } + public byte[] Write(Wdata_doc wdoc) { + fmtr_main.Bld_bfr_many(bfr, "", fmtr_claim, fmtr_label, fmtr_alias, fmtr_descr, fmtr_slink, fmtr_json); + return bfr.XtoAryAndClear(); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr_tst.java new file mode 100644 index 000000000..7a72335b2 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_mgr_tst.java @@ -0,0 +1,264 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import org.junit.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; +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 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 + ( "" + , "

    Labels

    " + , "" + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    LanguageLabel
    enen_label
    dede_label
    " + )); + } + @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 + ( "" + , "

    Descriptions

    " + , "" + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    LanguageDescription
    enen_descr
    dede_descr
    " + )); + } + @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 + ( "" + , "

    Aliases

    " + , "" + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    LanguageAlias
    enen_1
    en_2
    dede_1
    " + )); + } + @Test public void Write_slink() { + fxt.Test_doc(fxt.Wdoc_bldr() + .Add_sitelink("enwiki", "Earth") + .Add_sitelink("dewiki", "Erde").Xto_wdoc(), String_.Concat_lines_nl_skip_last + ( "" + , "

    Links

    " + , "" + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    SiteLinkBadges
    enwikiEarth
    dewikiErde
    " + )); + } + @Test public void Write_claim() { + fxt + .Init_resolved_pid(1, "prop_1") + .Test_doc(fxt.Wdoc_bldr() + .Add_claims + ( fxt.Wdata_fxt().Make_claim_str(1, "abc") + ).Xto_wdoc(), String_.Concat_lines_nl_skip_last + ( "" + , "

    Claims

    " + , "" + , "" + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , " " + , "
    IdNameValueReferencesQualifiersRank
    1prop_1abcnormal
    " + )); + } + @Test public void Write_claim_monolingualtext() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto") + , "[en] Motto" + ); + } + @Test public void Write_claim_time() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06") + , "2001-02-03 04:05:06" + ); + } + @Test public void Write_claim_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 Write_claim_quantity_same() { + fxt + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "units", "60", "40") + , "50 ±10 units" + ); + } + @Test public void Write_claim_entity() { + fxt + .Init_resolved_qid(1, "item_1") + .Test_claim_val + ( fxt.Wdata_fxt().Make_claim_entity(1, 1) + , "item_1" + ); + } + @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 + ( "" + , "

    JSON

    " + , "" + , "" + , "{ \"node\":" + , " [ \"val_0\"" + , " , \"val_1\"" + , " ]" + , "}" + , "" + )); + } +} +class Wdata_hwtr_mgr_fxt { + private Wdata_hwtr_mgr doc_hwtr; private OrderedHash resolved_pids = OrderedHash_.new_bry_(), resolved_qids = OrderedHash_.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 = new Wdata_hwtr_msgs(Make_msgs()); + doc_hwtr.Init_by_ctor(new Json_parser(), new Wdata_lbl_wkr__test(resolved_pids, resolved_qids), Url_encoder.new_html_href_mw_()); + doc_hwtr.Init_by_lang(msgs); + } + resolved_pids.Clear(); + resolved_qids.Clear(); + } + private byte[][] Make_msgs() { + return Bry_.Ary + ( "Contents" + , "Labels", "Language", "Label" + , "Aliases", "Language", "Alias" + , "Descriptions", "Language", "Description" + , "Links" + , "Links (Wikipedia)", "Links (Wiktionary)", "Links (Wikisource)", "Links (Wikivoyage)" + , "Links (Wikiquote)", "Links (Wikibooks)", "Links (Wikiversity)", "Links (Wikinews)", "Links (Special wikis)" + , "Site", "Link", "Badges" + , "Claims", "Id", "Name", "Value", "References", "Qualifiers", "Rank" + , "JSON" + , ", ", " ", "(~{0})" + , "+", "-", "±" + , "—", "?" + , "preferred", "normal", "deprecated" + , "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + , "~{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}", "jul" + , "N", "S", "E", "W" + , "°", "′", "″" + , " m" + ); + } + 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_pids.Add(Wdata_lbl_itm.Make_ttl(Bool_.Y, pid), new Wdata_langtext_itm(Bry_.new_ascii_("en"), Bry_.new_ascii_(lbl))); return this;} + public Wdata_hwtr_mgr_fxt Init_resolved_qid(int qid, String lbl) {resolved_qids.Add(Wdata_lbl_itm.Make_ttl(Bool_.N, qid), new Wdata_langtext_itm(Bry_.new_ascii_("en"), Bry_.new_ascii_(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_utf8_(actl)); + } + public void Test_claim_val(Wdata_claim_itm_core claim, String expd) { + doc_hwtr.Init_by_wdoc(wdoc_bldr.Add_claims(claim).Xto_wdoc()); + byte[] actl = doc_hwtr.Fmtr_claim().Fmtr_row().Calc_val(claim); + Tfds.Eq(expd, String_.new_utf8_(actl)); + } + public void Test_json(Wdata_doc wdoc, String expd) { + Wdata_fmtr__json fmtr_json = doc_hwtr.Fmtr_json(); + fmtr_json.Init_by_wdoc(doc_hwtr.Fmtr_toc(), wdoc.Jdoc()); + Bry_bfr tmp_bfr = Bry_bfr.new_(); + fmtr_json.XferAry(tmp_bfr, 0); + Tfds.Eq_str_lines(expd, tmp_bfr.XtoStrAndClear()); + } +} +class Wdata_lbl_wkr__test implements Wdata_lbl_wkr { + private OrderedHash resolved_pids, resolved_qids; + public Wdata_lbl_wkr__test(OrderedHash resolved_pids, OrderedHash resolved_qids) {this.resolved_pids = resolved_pids; this.resolved_qids = resolved_qids;} + public void Resolve(Wdata_lbl_list pid_regy, Wdata_lbl_list qid_regy) { + pid_regy.Resolve(resolved_pids); + qid_regy.Resolve(resolved_qids); + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_msgs.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_msgs.java new file mode 100644 index 000000000..0c1387ae1 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_hwtr_msgs.java @@ -0,0 +1,206 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.langs.msgs.*; +public class Wdata_hwtr_msgs { + public Wdata_hwtr_msgs(byte[][] brys) { int offset = 0; // String[] strs = String_.Ary(brys); // TEST + toc_tbl_hdr = brys[offset + 0]; + label_tbl_hdr = brys[offset + 1]; + label_col_hdr_lang = brys[offset + 2]; + label_col_hdr_text = brys[offset + 3]; + alias_tbl_hdr = brys[offset + 4]; + alias_col_hdr_lang = brys[offset + 5]; + alias_col_hdr_text = brys[offset + 6]; + descr_tbl_hdr = brys[offset + 7]; + descr_col_hdr_lang = brys[offset + 8]; + descr_col_hdr_text = brys[offset + 9]; offset += 10; + slink_tbl_hdr = brys[offset + 0]; + slink_tbl_hdr_w = brys[offset + 1]; + slink_tbl_hdr_d = brys[offset + 2]; + slink_tbl_hdr_s = brys[offset + 3]; + slink_tbl_hdr_v = brys[offset + 4]; + slink_tbl_hdr_q = brys[offset + 5]; + slink_tbl_hdr_b = brys[offset + 6]; + slink_tbl_hdr_u = brys[offset + 7]; + slink_tbl_hdr_n = brys[offset + 8]; + slink_tbl_hdr_x = brys[offset + 9]; offset += 10; + slink_col_hdr_site = brys[offset + 0]; + slink_col_hdr_text = brys[offset + 1]; + slink_col_hdr_bdgs = brys[offset + 2]; + claim_tbl_hdr = brys[offset + 3]; + claim_col_hdr_prop_id = brys[offset + 4]; + claim_col_hdr_prop_name = brys[offset + 5]; + claim_col_hdr_val = brys[offset + 6]; + claim_col_hdr_ref = brys[offset + 7]; + claim_col_hdr_qual = brys[offset + 8]; + claim_col_hdr_rank = brys[offset + 9]; + json_tbl_hdr = brys[offset + 10]; offset += 11; + sym_list_comma = brys[offset + 0]; + sym_list_word = brys[offset + 1]; + sym_fmt_parentheses = brys[offset + 2]; + sym_plus = brys[offset + 3]; + sym_minus = brys[offset + 4]; + sym_plusminus = brys[offset + 5]; offset += 6; + val_tid_novalue = brys[offset + 0]; + val_tid_somevalue = brys[offset + 1]; + rank_preferred = brys[offset + 2]; + rank_normal = brys[offset + 3]; + rank_deprecated = brys[offset + 4]; offset += 5; + 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_1e10_01 = brys[offset + 0]; + time_year_1e10_02 = brys[offset + 1]; + time_year_1e10_03 = brys[offset + 2]; + time_year_1e10_04 = brys[offset + 3]; + time_year_1e10_05 = brys[offset + 4]; + time_year_1e10_06 = brys[offset + 5]; + time_year_1e10_07 = brys[offset + 6]; + time_year_1e10_08 = brys[offset + 7]; + time_year_1e10_09 = brys[offset + 8]; offset += 9; + 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]; + } + public static Wdata_hwtr_msgs new_(Xow_wiki wiki) { + byte[][] brys = new_brys(wiki + , "toc" + , "xowa-wikidata-labels" , "xowa-wikidata-language" , "xowa-wikidata-label" + , "xowa-wikidata-aliasesHead" , "xowa-wikidata-language" , "xowa-wikidata-aliases" + , "xowa-wikidata-descriptions" , "xowa-wikidata-language" , "xowa-wikidata-description" + , "xowa-wikidata-links" + , "xowa-wikidata-links-wiki" , "xowa-wikidata-links-wiktionary" , "xowa-wikidata-links-wikisource", "xowa-wikidata-links-wikivoyage" + , "xowa-wikidata-links-wikiquote" , "xowa-wikidata-links-wikibooks" , "xowa-wikidata-links-wikiversity", "xowa-wikidata-links-wikinews", "xowa-wikidata-links-special" + , "xowa-wikidata-wiki" , "xowa-wikidata-link" , "xowa-wikidata-badges" + , "xowa-wikidata-claims" , "xowa-wikidata-property-id" , "xowa-wikidata-property", "xowa-wikidata-value", "xowa-wikidata-references", "xowa-wikidata-qualifiers", "Wikibase-diffview-rank" + , "xowa-wikidata-json" + , "comma-separator", "word-separator", "parentheses" + , "xowa-wikidata-plus", "xowa-wikidata-minus", "xowa-wikidata-plusminus" + , "xowa-wikidata-novalue", "xowa-wikidata-somevalue" + , "xowa-wikidata-preferred", "xowa-wikidata-normal", "xowa-wikidata-deprecated" + , "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" + , "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_wiki wiki, String... ids) { + int len = ids.length; + byte[][] rv = new byte[len][]; + for (int i = 0; i < len; ++i) + rv[i] = gplx.html.Html_utl.Escape_html_as_bry(wiki.Msg_mgr().Val_by_key_obj(ids[i])); + return rv; + } + public byte[] Toc_tbl_hdr() {return toc_tbl_hdr;} private final byte[] toc_tbl_hdr; + public byte[] Label_tbl_hdr() {return label_tbl_hdr;} private final byte[] label_tbl_hdr; + public byte[] Label_col_hdr_lang() {return label_col_hdr_lang;} private final byte[] label_col_hdr_lang; + public byte[] Label_col_hdr_text() {return label_col_hdr_text;} private final byte[] label_col_hdr_text; + public byte[] Alias_tbl_hdr() {return alias_tbl_hdr;} private final byte[] alias_tbl_hdr; + public byte[] Alias_col_hdr_lang() {return alias_col_hdr_lang;} private final byte[] alias_col_hdr_lang; + public byte[] Alias_col_hdr_text() {return alias_col_hdr_text;} private final byte[] alias_col_hdr_text; + public byte[] Descr_tbl_hdr() {return descr_tbl_hdr;} private final byte[] descr_tbl_hdr; + public byte[] Descr_col_hdr_lang() {return descr_col_hdr_lang;} private final byte[] descr_col_hdr_lang; + public byte[] Descr_col_hdr_text() {return descr_col_hdr_text;} private final byte[] descr_col_hdr_text; + public byte[] Slink_tbl_hdr() {return slink_tbl_hdr;} private final byte[] slink_tbl_hdr; + 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_site() {return slink_col_hdr_site;} private final byte[] slink_col_hdr_site; + public byte[] Slink_col_hdr_text() {return slink_col_hdr_text;} private final byte[] slink_col_hdr_text; + public byte[] Slink_col_hdr_bdgs() {return slink_col_hdr_bdgs;} private final byte[] slink_col_hdr_bdgs; + public byte[] Claim_tbl_hdr() {return claim_tbl_hdr;} private final byte[] claim_tbl_hdr; + public byte[] Claim_col_hdr_prop_id() {return claim_col_hdr_prop_id;} private final byte[] claim_col_hdr_prop_id; + public byte[] Claim_col_hdr_prop_name() {return claim_col_hdr_prop_name;} private final byte[] claim_col_hdr_prop_name; + public byte[] Claim_col_hdr_val() {return claim_col_hdr_val;} private final byte[] claim_col_hdr_val; + public byte[] Claim_col_hdr_ref() {return claim_col_hdr_ref;} private final byte[] claim_col_hdr_ref; + public byte[] Claim_col_hdr_qual() {return claim_col_hdr_qual;} private final byte[] claim_col_hdr_qual; + public byte[] Claim_col_hdr_rank() {return claim_col_hdr_rank;} private final byte[] claim_col_hdr_rank; + public byte[] Json_tbl_hdr() {return json_tbl_hdr;} private final byte[] json_tbl_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[] Rank_preferred() {return rank_preferred;} private final byte[] rank_preferred; + public byte[] Rank_normal() {return rank_normal;} private final byte[] rank_normal; + public byte[] Rank_deprecated() {return rank_deprecated;} private final byte[] rank_deprecated; + 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_fmt_parentheses() {return sym_fmt_parentheses;} private final byte[] sym_fmt_parentheses; + 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[] 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 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; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lang_sorter.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lang_sorter.java new file mode 100644 index 000000000..6d069de12 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lang_sorter.java @@ -0,0 +1,45 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; +class Wdata_lang_sorter implements gplx.lists.ComparerAble { + private Hash_adp_bry hash = Hash_adp_bry.cs_(); + public void Langs_(byte[][] 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_new(lang, itm); + } + } + public int compare(Object lhsObj, Object rhsObj) { + Wdata_sortable lhs = (Wdata_sortable)lhsObj; if (lhs.Sort() == -1) Sort_calc(lhs); + Wdata_sortable rhs = (Wdata_sortable)rhsObj; if (rhs.Sort() == -1) Sort_calc(rhs); + return Int_.Compare(lhs.Sort(), rhs.Sort()); + } + private void Sort_calc(Wdata_sortable data_itm) { + Wdata_lang_sorter_itm sort_itm = (Wdata_lang_sorter_itm)hash.Fetch(data_itm.Lang()); + if (sort_itm != null) data_itm.Sort_(sort_itm.Sort()); + } +} +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; +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_list.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_list.java new file mode 100644 index 000000000..526c3fe64 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_list.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; +class Wdata_lbl_list { + private HashAdp hash = HashAdp_.new_(); private Int_obj_ref hash_temp_key = Int_obj_ref.neg1_(); + public Wdata_lbl_list(boolean is_pid) {this.is_pid = is_pid;} private boolean is_pid; + public ListAdp Queue() {return queue;} private ListAdp queue = ListAdp_.new_(); + public byte[] Get_text_or_empty(int id) { + Wdata_lbl_itm rv_itm = (Wdata_lbl_itm)hash.Fetch(hash_temp_key.Val_(id)); + return rv_itm == null ? Bry_.Empty : rv_itm.Text(); + } + public void Queue_if_missing(int id) { + boolean has = hash.Has(hash_temp_key.Val_(id)); + if (!has) { + Wdata_lbl_itm itm = new Wdata_lbl_itm(is_pid, id); + hash.Add(Int_obj_ref.new_(id), itm); + queue.Add(itm); + } + } + public void Resolve(OrderedHash found) { + int len = queue.Count(); + for (int i = 0; i < len; ++i) { + Wdata_lbl_itm pending_itm = (Wdata_lbl_itm)queue.FetchAt(i); + Wdata_langtext_itm found_itm = (Wdata_langtext_itm)found.Fetch(pending_itm.Ttl()); + if (found_itm != null) + pending_itm.Load_vals(found_itm.Lang(), found_itm.Text()); + } + queue.Clear(); + } +} +class Wdata_lbl_itm { + public Wdata_lbl_itm(boolean is_pid, int id) { + this.is_pid = is_pid; this.id = id; 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 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_.Xto_bry(id)) + : Bry_.Add(Ttl_prefix_qid, Int_.Xto_bry(id)) + ; + } + private static final byte[] Ttl_prefix_pid = Bry_.new_ascii_("Property:P"), Ttl_prefix_qid = Bry_.new_ascii_("Q"); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_mgr.java b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_mgr.java new file mode 100644 index 000000000..e1627c04c --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/hwtrs/Wdata_lbl_mgr.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.xowa.xtns.wdatas.core.*; +class Wdata_lbl_mgr { + public Wdata_lbl_list Pid_regy() {return pid_regy;} private Wdata_lbl_list pid_regy = new Wdata_lbl_list(Bool_.Y); + public Wdata_lbl_list Qid_regy() {return qid_regy;} private Wdata_lbl_list qid_regy = new Wdata_lbl_list(Bool_.N); + public void Wkr_(Wdata_lbl_wkr v) {this.wkr = v;} private Wdata_lbl_wkr wkr; + public void Gather_labels(Wdata_doc wdoc) { + OrderedHash claim_list = wdoc.Claim_list(); + int len = claim_list.Count(); + for (int i = 0; i < len; ++i) { + Wdata_claim_grp grp = (Wdata_claim_grp)claim_list.FetchAt(i); + int grp_len = grp.Len(); + for (int j = 0; j < grp_len; ++j) { + Wdata_claim_itm_base itm = (Wdata_claim_itm_base)grp.Get_at(j); + pid_regy.Queue_if_missing(itm.Pid()); + switch (itm.Val_tid()) { + case Wdata_dict_val_tid.Tid_entity: + Wdata_claim_itm_entity entity = (Wdata_claim_itm_entity)itm; + qid_regy.Queue_if_missing(entity.Entity_id()); + break; + } + } + } + wkr.Resolve(pid_regy, qid_regy); + } +} +interface Wdata_lbl_wkr { + void Resolve(Wdata_lbl_list pid_regy, Wdata_lbl_list qid_regy); +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java index dc5c2e16d..38fdea05c 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/imports/Xob_wdata_db_cmd.java @@ -178,7 +178,7 @@ class Wdata_description_tbl extends Wdata_tbl_base { ); } @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.Description_list());} + @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"; } @@ -196,7 +196,7 @@ class Wdata_link_tbl extends Wdata_tbl_base { @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) { - OrderedHash hash = wdoc.Sitelink_list(); + OrderedHash hash = wdoc.Slink_list(); int len = hash.Count(); Db_stmt insert_stmt = this.Insert_stmt(); for (int i = 0; i < len; i++) { @@ -251,11 +251,11 @@ class Wdata_claim_tbl extends Wdata_tbl_base { int list_len = list.Count(); for (int i = 0; i < list_len; i++) { Wdata_claim_grp claim_grp = (Wdata_claim_grp)list.FetchAt(i); - int itms_len = claim_grp.Itms_len(); + int itms_len = claim_grp.Len(); int entity_id = -1; byte[] claim_val = Bry_.Empty; for (int j = 0; j < itms_len; j++) { - Wdata_claim_itm_core claim = claim_grp.Itms_get_at(j); + Wdata_claim_itm_core claim = claim_grp.Get_at(j); byte val_tid = claim.Val_tid(); switch (val_tid) { case Wdata_dict_val_tid.Tid_string: diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_claims_parser_v2.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_claims_parser_v2.java new file mode 100644 index 000000000..5e4b629fa --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_claims_parser_v2.java @@ -0,0 +1,243 @@ +/* +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 . +*/ +package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; +class Wdata_claims_parser_v2 { + public void Make_claim_itms(byte[] qid, ListAdp claim_itms_list, byte[] src, Json_itm_kv claim_grp) { + Json_itm_ary claim_itms_ary = Json_itm_ary.cast_(claim_grp.Val()); + int claim_itms_len = claim_itms_ary.Subs_len(); + int pid = Parse_pid(claim_grp.Key().Data_bry()); + for (int i = 0; i < claim_itms_len; ++i) { + Json_itm_nde claim_itm_nde = Json_itm_nde.cast_(claim_itms_ary.Subs_get_at(i)); + Wdata_claim_itm_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 Wdata_claim_itm_core Parse_claim_itm(byte[] qid, Json_itm_nde nde, int pid) { + int len = nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_claim.Dict; + byte rank_tid = Wdata_dict_rank.Tid_unknown; + Wdata_claim_itm_core claim_itm = null; Wdata_claim_grp_list qualifiers = null; int[] qualifiers_order = null; Wdata_references_grp[] snaks_grp = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + switch (tid) { + case Wdata_dict_claim.Tid_mainsnak: claim_itm = Parse_mainsnak(qid, Json_itm_nde.cast_(sub.Val()), pid); break; + case Wdata_dict_claim.Tid_rank: rank_tid = Wdata_dict_rank.Xto_tid(sub.Val().Data_bry()); break; + case Wdata_dict_claim.Tid_references: snaks_grp = Parse_references(qid, Json_itm_ary.cast_(sub.Val())); break; + case Wdata_dict_claim.Tid_qualifiers: qualifiers = Parse_qualifiers(qid, Json_itm_nde.cast_(sub.Val())); break; + case Wdata_dict_claim.Tid_qualifiers_order: qualifiers_order = Parse_pid_order(Json_itm_ary.cast_(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 Wdata_references_grp[] Parse_references(byte[] qid, Json_itm_ary owner) { + int len = owner.Subs_len(); + Wdata_references_grp[] rv = new Wdata_references_grp[len]; + for (int i = 0; i < len; ++i) { + Json_itm_nde grp_nde = Json_itm_nde.cast_(owner.Subs_get_at(i)); + rv[i] = Parse_references_grp(qid, grp_nde); + } + return rv; + } + private Wdata_references_grp Parse_references_grp(byte[] qid, Json_itm_nde owner) { + int len = owner.Subs_len(); + Hash_adp_bry dict = Wdata_dict_reference.Dict; + Wdata_claim_grp_list snaks = null; int[] snaks_order = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(owner.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.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_itm_nde.cast_(sub.Val())); break; + case Wdata_dict_reference.Tid_snaks_order: snaks_order = Parse_pid_order(Json_itm_ary.cast_(sub.Val())); break; + } + } + return new Wdata_references_grp(snaks, snaks_order); + } + public Wdata_claim_grp_list Parse_qualifiers(byte[] qid, Json_itm_nde qualifiers_nde) { + Wdata_claim_grp_list rv = new Wdata_claim_grp_list(); + int len = qualifiers_nde.Subs_len(); + for (int i = 0; i < len; ++i) { + Json_itm_kv qualifier_kv = Json_itm_kv.cast_(qualifiers_nde.Subs_get_at(i)); + int pid = Parse_pid(qualifier_kv.Key().Data_bry()); + Wdata_claim_grp claims_grp = Parse_props_grp(qid, pid, Json_itm_ary.cast_(qualifier_kv.Val())); + rv.Add(claims_grp); + } + return rv; + } + public int[] Parse_pid_order(Json_itm_ary ary) { + int len = ary.Subs_len(); + int[] rv = new int[len]; + for (int i = 0; i < len; ++i) { + Json_itm pid_itm = ary.Subs_get_at(i); + rv[i] = Parse_pid(pid_itm.Data_bry()); + } + return rv; + } + private Wdata_claim_grp Parse_props_grp(byte[] qid, int pid, Json_itm_ary props_ary) { + ListAdp list = ListAdp_.new_(); + int len = props_ary.Subs_len(); + for (int i = 0; i < len; ++i) { + Json_itm_nde qualifier_nde = Json_itm_nde.cast_(props_ary.Subs_get_at(i)); + Wdata_claim_itm_core qualifier_itm = Parse_mainsnak(qid, qualifier_nde, pid); + list.Add(qualifier_itm); + } + return new Wdata_claim_grp(Int_obj_ref.new_(pid), (Wdata_claim_itm_core[])list.XtoAryAndClear(Wdata_claim_itm_core.class)); + } + public Wdata_claim_itm_core Parse_mainsnak(byte[] qid, Json_itm_nde nde, int pid) { + int len = nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_mainsnak.Dict; + byte snak_tid = Byte_.MaxValue_127; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + switch (tid) { + case Wdata_dict_mainsnak.Tid_snaktype: snak_tid = Wdata_dict_snak_tid.Xto_tid(sub.Val().Data_bry()); break; + case Wdata_dict_mainsnak.Tid_datavalue: return Parse_datavalue(qid, pid, snak_tid, Json_itm_nde.cast_(sub.Val())); + case Wdata_dict_mainsnak.Tid_property: break; // ignore: pid already available above + case Wdata_dict_mainsnak.Tid_hash: break; // ignore: "84487fc3f93b4f74ab1cc5a47d78f596f0b49390" + } + } + return new Wdata_claim_itm_system(pid, Wdata_dict_val_tid.Tid_unknown, snak_tid); // NOTE: mainsnak can be null, especially for qualifiers; PAGE:Q2!P576; DATE:2014-09-20 + } + public Wdata_claim_itm_core Parse_datavalue(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) { + int len = nde.Subs_len(); + Hash_adp_bry dict = Wdata_dict_datavalue.Dict; + Json_itm value_itm = null; byte value_tid = Wdata_dict_val_tid.Tid_unknown; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + switch (tid) { + case Wdata_dict_datavalue.Tid_type: value_tid = Wdata_dict_val_tid.Xto_tid(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" + } + } + switch (value_tid) { + case Wdata_dict_val_tid.Tid_string: return new Wdata_claim_itm_str(pid, snak_tid, value_itm.Data_bry()); + case Wdata_dict_val_tid.Tid_entity: return Parse_datavalue_entity (qid, pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_time: return Parse_datavalue_time (qid, pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_quantity: return Parse_datavalue_quantity (qid, pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_globecoordinate: return Parse_datavalue_globecoordinate (qid, pid, snak_tid, Json_itm_nde.cast_(value_itm)); + case Wdata_dict_val_tid.Tid_monolingualtext: return Parse_datavalue_monolingualtext (qid, pid, snak_tid, Json_itm_nde.cast_(value_itm)); + } + throw Err_.new_("unknown val_tid; val_tid={0}", value_tid); + } + private Wdata_claim_itm_entity Parse_datavalue_entity(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_entity.Dict; + int len = nde.Subs_len(); + byte[] entity_id_bry = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + switch (tid) { + case Wdata_dict_value_entity.Tid_entity_type: break; // ignore: "item" + case Wdata_dict_value_entity.Tid_numeric_id: entity_id_bry = sub.Val().Data_bry(); break; + } + } + if (entity_id_bry == null) throw Err_.new_("pid is invalid entity; pid={0}", pid); + return new Wdata_claim_itm_entity(pid, snak_tid, entity_id_bry); + } + private Wdata_claim_itm_monolingualtext Parse_datavalue_monolingualtext(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_monolingualtext.Dict; + int len = nde.Subs_len(); + byte[] lang = null, text = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_monolingualtext.Tid_text: text = sub_val_bry; break; + case Wdata_dict_value_monolingualtext.Tid_language: lang = sub_val_bry; break; + } + } + if (lang == null || text == null) throw Err_.new_("pid is invalid monolingualtext; pid={0}", pid); + return new Wdata_claim_itm_monolingualtext(pid, snak_tid, lang, text); + } + private Wdata_claim_itm_globecoordinate Parse_datavalue_globecoordinate(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_globecoordinate.Dict; + int len = nde.Subs_len(); + byte[] lat = null, lng = null, alt = null, prc = null, glb = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_globecoordinate.Tid_latitude: lat = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_longitude: lng = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_altitude: alt = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_precision: prc = sub_val_bry; break; + case Wdata_dict_value_globecoordinate.Tid_globe: glb = sub_val_bry; break; + } + } + if (lat == null || lng == null) throw Err_.new_("pid is invalid globecoordinate; pid={0}", pid); + return new Wdata_claim_itm_globecoordinate(pid, snak_tid, lat, lng, alt, prc, glb); + } + private Wdata_claim_itm_quantity Parse_datavalue_quantity(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_quantity.Dict; + int len = nde.Subs_len(); + byte[] amount = null, unit = null, ubound = null, lbound = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_quantity.Tid_amount: amount = sub_val_bry; break; + case Wdata_dict_value_quantity.Tid_unit: unit = sub_val_bry; break; + case Wdata_dict_value_quantity.Tid_upperbound: ubound = sub_val_bry; break; + case Wdata_dict_value_quantity.Tid_lowerbound: lbound = sub_val_bry; break; + } + } + if (amount == null) throw Err_.new_("pid is invalid quantity; pid={0}", pid); + return new Wdata_claim_itm_quantity(pid, snak_tid, amount, unit, ubound, lbound); + } + private Wdata_claim_itm_time Parse_datavalue_time(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) { + Hash_adp_bry dict = Wdata_dict_value_time.Dict; + int len = nde.Subs_len(); + byte[] time = null, timezone = null, before = null, after = null, precision = null, calendarmodel = null; + for (int i = 0; i < len; ++i) { + Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; + byte[] sub_val_bry = sub.Val().Data_bry(); + switch (tid) { + case Wdata_dict_value_time.Tid_time: time = sub_val_bry; break; + case Wdata_dict_value_time.Tid_timezone: timezone = sub_val_bry; break; + case Wdata_dict_value_time.Tid_before: before = sub_val_bry; break; + case Wdata_dict_value_time.Tid_after: after = sub_val_bry; break; + case Wdata_dict_value_time.Tid_precision: precision = sub_val_bry; break; + case Wdata_dict_value_time.Tid_calendarmodel: calendarmodel = sub_val_bry; break; + } + } + if (time == null) throw Err_.new_("pid is invalid time; pid={0}", pid); + return new Wdata_claim_itm_time(pid, snak_tid, time, timezone, before, after, precision, calendarmodel); + } + private static int Parse_pid(byte[] pid_bry) { + int rv = Bry_.Xto_int_or(pid_bry, 1, pid_bry.length, -1); if (rv == -1) throw Err_.new_("invalid pid; pid={0}", String_.new_utf8_(pid_bry)); + return rv; + } +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser.java index bb6dfebbf..1bb2bff05 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser.java @@ -22,6 +22,9 @@ public interface Wdata_doc_parser { OrderedHash Parse_sitelinks(byte[] qid, Json_doc doc); OrderedHash Parse_langvals(byte[] qid, Json_doc doc, boolean label_or_description); OrderedHash Parse_aliases(byte[] qid, Json_doc doc); - OrderedHash Parse_claims(Json_doc doc); - Wdata_claim_itm_base Parse_claims_data(int pid, byte snak_tid, Json_itm_nde nde); + OrderedHash Parse_claims(byte[] qid, Json_doc doc); + Wdata_claim_itm_base Parse_claims_data(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde); + Wdata_claim_grp_list Parse_qualifiers(byte[] qid, Json_itm_nde nde); + int[] Parse_pid_order(byte[] qid, Json_itm_ary ary); + Wdata_references_grp[] Parse_references(byte[] qid, Json_itm_ary owner); } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_fxt_base.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_fxt_base.java new file mode 100644 index 000000000..8fb1717f6 --- /dev/null +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_fxt_base.java @@ -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 . +*/ +package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; +import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; +abstract class Wdata_doc_parser_fxt_base { + protected Wdata_doc_parser parser; + public void Init() { + if (parser == null) 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_utf8_(site), Bry_.new_utf8_(name), Bry_.Ary(badges));} + public Wdata_langtext_itm Make_langval(String lang, String text) {return new Wdata_langtext_itm(Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} + public Wdata_alias_itm Make_alias(String lang, String... vals) {return new Wdata_alias_itm(Bry_.new_utf8_(lang), Bry_.Ary(vals));} + public Wdata_claim_itm_core Make_claim_str(int pid, String val) {return new Wdata_claim_itm_str(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(val));} + public Wdata_claim_itm_core Make_claim_entity(int pid, int entityId) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Int_.Xto_bry(entityId));} + public Wdata_claim_itm_core Make_claim_monolingualtext(int pid, String lang, String text) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} + public Wdata_claim_itm_core Make_claim_globecoordinate(int pid, String lat, String lng, String prc) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lat), Bry_.new_utf8_(lng), Bry_.new_ascii_("null"), Bry_.new_utf8_(prc), Bry_.new_ascii_("http://www.wikidata.org/entity/Q2"));} + public Wdata_claim_itm_core Make_claim_quantity(int pid, int val, int unit, int ubound, int lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(Int_.Xto_str(val)), Bry_.new_utf8_(Int_.Xto_str(unit)), Bry_.new_utf8_(Int_.Xto_str(ubound)), Bry_.new_utf8_(Int_.Xto_str(lbound)));} + public Wdata_claim_itm_core Make_claim_time(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_time.Xto_time(val), Wdata_dict_value_time.Val_timezone_bry, Wdata_dict_value_time.Val_before_bry, Wdata_dict_value_time.Val_after_bry, Wdata_dict_value_time.Val_precision_bry, Wdata_dict_value_time.Val_calendarmodel_bry);} + public Wdata_claim_itm_core Make_claim_novalue(int pid) {return new Wdata_claim_itm_system(pid, Wdata_dict_val_tid.Tid_unknown, Wdata_dict_snak_tid.Tid_novalue);} + public void Test_entity(String raw, String expd) {Tfds.Eq(expd, String_.new_utf8_(parser.Parse_qid(Json_doc.new_apos_(raw))));} + public void Test_sitelinks(String raw, Wdata_sitelink_itm... expd) { + OrderedHash actl_hash = parser.Parse_sitelinks(Q1_bry, Json_doc.new_apos_(raw)); + Tfds.Eq_ary_str((Wdata_sitelink_itm[])actl_hash.XtoAry(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) { + OrderedHash actl_hash = parser.Parse_langvals(Q1_bry, Json_doc.new_apos_(raw), labels_or_descriptions); + Tfds.Eq_ary_str((Wdata_langtext_itm[])actl_hash.XtoAry(Wdata_langtext_itm.class), expd); + } + public void Test_aliases(String raw, Wdata_alias_itm... expd) { + OrderedHash actl_hash = parser.Parse_aliases(Q1_bry, Json_doc.new_apos_(raw)); + Tfds.Eq_ary_str((Wdata_alias_itm[])actl_hash.XtoAry(Wdata_alias_itm.class), expd); + } + public void Test_claims(String raw, Wdata_claim_itm_core... expd) { + OrderedHash actl_hash = parser.Parse_claims(Q1_bry, Json_doc.new_apos_(raw)); + ListAdp actl_list = Wdata_claim_grp.Xto_list(actl_hash); + Tfds.Eq_ary_str((Wdata_claim_itm_core[])actl_list.XtoAry(Wdata_claim_itm_core.class), expd); + } + public void Test_claims_data(String raw, Wdata_claim_itm_core expd) { + Json_doc jdoc = Json_doc.new_apos_(raw); + Wdata_claim_itm_base actl = parser.Parse_claims_data(Q1_bry, 1, Wdata_dict_snak_tid.Tid_value, jdoc.Root()); + Tfds.Eq(expd.toString(), actl.toString()); + } + public void Test_qualifiers(String raw, Wdata_claim_itm_base... expd_itms) { + Json_doc jdoc = Json_doc.new_apos_(raw); + Json_itm_nde qualifiers_nde = Json_itm_nde.cast_(Json_itm_kv.cast_(jdoc.Root().Subs_get_at(0)).Val()); + Wdata_claim_grp_list actl = parser.Parse_qualifiers(Q1_bry, qualifiers_nde); + Tfds.Eq_ary_str(expd_itms, Xto_ary(actl)); + } + public void Test_references(String raw, int[] expd_order, Wdata_claim_itm_base... expd_itms) { + Json_doc jdoc = Json_doc.new_apos_(raw); + Json_itm_ary owner = Json_itm_ary.cast_(Json_itm_kv.cast_(jdoc.Root().Subs_get_at(0)).Val()); + Wdata_references_grp[] actl = parser.Parse_references(Q1_bry, owner); + Wdata_references_grp actl_grp = actl[0]; + Tfds.Eq_ary(expd_order, actl_grp.References_order()); + Tfds.Eq_ary_str(expd_itms, Xto_ary(actl_grp.References())); + } + public void Test_pid_order(String raw, int... expd) { + Json_doc jdoc = Json_doc.new_apos_(raw); + Json_itm_ary nde = Json_itm_ary.cast_(Json_itm_kv.cast_(jdoc.Root().Subs_get_at(0)).Val()); + int[] actl = parser.Parse_pid_order(Q1_bry, nde); + Tfds.Eq_ary(expd, actl); + } + Wdata_claim_itm_base[] Xto_ary(Wdata_claim_grp_list list) { + ListAdp rv = ListAdp_.new_(); + int list_len = list.Len(); + for (int i = 0; i < list_len; ++i) { + Wdata_claim_grp grp = list.Get_at(i); + int grp_len = grp.Len(); + for (int j = 0; j < grp_len; ++j) { + Wdata_claim_itm_core itm = grp.Get_at(j); + rv.Add(itm); + } + } + return (Wdata_claim_itm_base[])rv.XtoAryAndClear(Wdata_claim_itm_base.class); + } + private static final byte[] Q1_bry = Bry_.new_ascii_("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();} +} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java index 473bbe22c..5e0b158a8 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1.java @@ -110,7 +110,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser { return rv; } catch (Exception e) {throw Err_.err_(e, "failed to parse aliases; qid={0}", String_.new_utf8_(qid));} } - public OrderedHash Parse_claims(Json_doc doc) { + public OrderedHash Parse_claims(byte[] qid, Json_doc doc) { try { Json_itm_ary list_nde = Json_itm_ary.cast_(doc.Get_grp(Bry_claims)); if (list_nde == null) return Empty_ordered_hash_generic; ListAdp temp_list = ListAdp_.new_(); @@ -124,7 +124,7 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser { return Claims_list_to_hash(temp_list); } catch (Exception e) {throw Err_.err_(e, "failed to parse claims; qid={0}", String_.new_utf8_(doc.Src()));} } - public Wdata_claim_itm_base Parse_claims_data(int pid, byte snak_tid, Json_itm_nde nde) {throw Err_.not_implemented_();} + public Wdata_claim_itm_base Parse_claims_data(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) {throw Err_.not_implemented_();} public static OrderedHash Claims_list_to_hash(ListAdp full_list) { full_list.Sort(); OrderedHash rv = OrderedHash_.new_(); ListAdp temp_itms = ListAdp_.new_(); @@ -238,6 +238,9 @@ public class Wdata_doc_parser_v1 implements Wdata_doc_parser { } return rv; } + public Wdata_claim_grp_list Parse_qualifiers(byte[] qid, Json_itm_nde nde) {throw Err_.not_implemented_();} + public Wdata_references_grp[] Parse_references(byte[] qid, Json_itm_ary owner) {throw Err_.not_implemented_();} + public int[] Parse_pid_order(byte[] qid, Json_itm_ary ary) {throw Err_.not_implemented_();} public static final String Str_entity = "entity" , Str_id = "id" diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1_tst.java index 97b474855..e91af34f8 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v1_tst.java @@ -182,48 +182,6 @@ public class Wdata_doc_parser_v1_tst { ); } } -abstract class Wdata_doc_parser_fxt_base { - protected Wdata_doc_parser parser; - public void Init() { - if (parser == null) 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_utf8_(site), Bry_.new_utf8_(name), Bry_.Ary(badges));} - public Wdata_langtext_itm Make_langval(String lang, String text) {return new Wdata_langtext_itm(Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} - public Wdata_alias_itm Make_alias(String lang, String... vals) {return new Wdata_alias_itm(Bry_.new_utf8_(lang), Bry_.Ary(vals));} - public Wdata_claim_itm_core Make_claim_str(int pid, String val) {return new Wdata_claim_itm_str(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(val));} - public Wdata_claim_itm_core Make_claim_entity(int pid, int entityId) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Int_.Xto_bry(entityId));} - public Wdata_claim_itm_core Make_claim_monolingualtext(int pid, String lang, String text) {return new Wdata_claim_itm_monolingualtext(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lang), Bry_.new_utf8_(text));} - public Wdata_claim_itm_core Make_claim_globecoordinate(int pid, String lat, String lng, String prc) {return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(lat), Bry_.new_utf8_(lng), Bry_.new_ascii_("null"), Bry_.new_utf8_(prc), Bry_.new_ascii_("http://www.wikidata.org/entity/Q2"));} - public Wdata_claim_itm_core Make_claim_quantity(int pid, int val, int unit, int ubound, int lbound) {return new Wdata_claim_itm_quantity(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_utf8_(Int_.Xto_str(val)), Bry_.new_utf8_(Int_.Xto_str(unit)), Bry_.new_utf8_(Int_.Xto_str(ubound)), Bry_.new_utf8_(Int_.Xto_str(lbound)));} - public Wdata_claim_itm_core Make_claim_time(int pid, String val) {return new Wdata_claim_itm_time(pid, Wdata_dict_snak_tid.Tid_value, Wdata_doc_bldr.Xto_time(val), Wdata_dict_value_time.Val_timezone_bry, Wdata_dict_value_time.Val_before_bry, Wdata_dict_value_time.Val_after_bry, Wdata_dict_value_time.Val_precision_bry, Wdata_dict_value_time.Val_calendarmodel_bry);} - public void Test_entity(String raw, String expd) {Tfds.Eq(expd, String_.new_utf8_(parser.Parse_qid(Json_doc.new_apos_(raw))));} - public void Test_sitelinks(String raw, Wdata_sitelink_itm... expd) { - OrderedHash actl_hash = parser.Parse_sitelinks(Q1_bry, Json_doc.new_apos_(raw)); - Tfds.Eq_ary_str((Wdata_sitelink_itm[])actl_hash.XtoAry(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) { - OrderedHash actl_hash = parser.Parse_langvals(Q1_bry, Json_doc.new_apos_(raw), labels_or_descriptions); - Tfds.Eq_ary_str((Wdata_langtext_itm[])actl_hash.XtoAry(Wdata_langtext_itm.class), expd); - } - public void Test_aliases(String raw, Wdata_alias_itm... expd) { - OrderedHash actl_hash = parser.Parse_aliases(Q1_bry, Json_doc.new_apos_(raw)); - Tfds.Eq_ary_str((Wdata_alias_itm[])actl_hash.XtoAry(Wdata_alias_itm.class), expd); - } - public void Test_claims(String raw, Wdata_claim_itm_core... expd) { - OrderedHash actl_hash = parser.Parse_claims(Json_doc.new_apos_(raw)); - ListAdp actl_list = Wdata_claim_grp.Xto_list(actl_hash); - Tfds.Eq_ary_str((Wdata_claim_itm_core[])actl_list.XtoAry(Wdata_claim_itm_core.class), expd); - } - public void Test_claims_data(String raw, Wdata_claim_itm_core expd) { - Json_doc jdoc = Json_doc.new_apos_(raw); - Wdata_claim_itm_base actl = parser.Parse_claims_data(1, Wdata_dict_snak_tid.Tid_value, jdoc.Root()); - Tfds.Eq(expd.toString(), actl.toString()); - } - private static final byte[] Q1_bry = Bry_.new_ascii_("Q1"); -} 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();} } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2.java index d4b002a90..41fb369ac 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2.java @@ -18,7 +18,7 @@ along with this program. If not, see . package gplx.xowa.xtns.wdatas.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*; import gplx.json.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.core.btries.*; public class Wdata_doc_parser_v2 implements Wdata_doc_parser { - private Wdata_claims_parser__v2 claims_parser = new Wdata_claims_parser__v2(); + 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); @@ -38,7 +38,7 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser { Json_itm_kv site_kv = null, name_kv = null; Json_itm_ary badges_ary = null; for (int j = 0; j < data_nde_len; ++j) { Json_itm_kv sub = Json_itm_kv.cast_(data_nde.Subs_get_at(j)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; switch (tid) { case Wdata_dict_sitelink.Tid_site: site_kv = Json_itm_kv.cast_(sub); break; case Wdata_dict_sitelink.Tid_title: name_kv = Json_itm_kv.cast_(sub); break; @@ -66,7 +66,7 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser { int data_nde_len = data_nde.Subs_len(); for (int j = 0; j < data_nde_len; ++j) { Json_itm_kv sub = Json_itm_kv.cast_(data_nde.Subs_get_at(j)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.Tid_invalid) continue; switch (tid) { case Wdata_dict_langtext.Tid_language: break; case Wdata_dict_langtext.Tid_value: text_kv = Json_itm_kv.cast_(sub); break; @@ -95,7 +95,7 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser { int k_len = lang_nde.Subs_len(); for (int k = 0; k < k_len; ++k) { Json_itm_kv sub = Json_itm_kv.cast_(lang_nde.Subs_get_at(k)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); + byte tid = Wdata_dict_utl.Get_tid_or_invalid(qid, dict, sub.Key().Data_bry()); if (tid == Wdata_dict_utl.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; @@ -109,7 +109,7 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser { return rv; } catch (Exception e) {throw Err_.err_(e, "failed to parse sitelinks; qid={0}", String_.new_utf8_(qid));} } - public OrderedHash Parse_claims(Json_doc doc) { + public OrderedHash Parse_claims(byte[] qid, Json_doc doc) { try { Json_itm_nde list_nde = Json_itm_nde.cast_(doc.Get_grp(Bry_claims)); if (list_nde == null) return Wdata_doc_parser_v1.Empty_ordered_hash_generic; ListAdp temp_list = ListAdp_.new_(); @@ -117,12 +117,15 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser { int len = list_nde.Subs_len(); for (int i = 0; i < len; i++) { Json_itm_kv claim_nde = Json_itm_kv.cast_(list_nde.Subs_get_at(i)); - claims_parser.Make_claim_itms(temp_list, src, claim_nde); + 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_.err_(e, "failed to parse claims; qid={0}", String_.new_utf8_(doc.Src()));} } - public Wdata_claim_itm_base Parse_claims_data(int pid, byte snak_tid, Json_itm_nde nde) {return claims_parser.Parse_datavalue(pid, snak_tid, nde);} + public Wdata_claim_itm_base Parse_claims_data(byte[] qid, int pid, byte snak_tid, Json_itm_nde nde) {return claims_parser.Parse_datavalue(qid, pid, snak_tid, nde);} + public Wdata_claim_grp_list Parse_qualifiers(byte[] qid, Json_itm_nde nde) {return claims_parser.Parse_qualifiers(qid, nde);} + public Wdata_references_grp[] Parse_references(byte[] qid, Json_itm_ary owner) {return claims_parser.Parse_references(qid, owner);} + public int[] Parse_pid_order(byte[] qid, Json_itm_ary ary) {return claims_parser.Parse_pid_order(ary);} public static final String Str_id = "id" , Str_sitelinks = "sitelinks" @@ -142,164 +145,3 @@ public class Wdata_doc_parser_v2 implements Wdata_doc_parser { , Bry_type = Bry_.new_ascii_(Str_type) ; } -class Wdata_claims_parser__v2 { - public void Make_claim_itms(ListAdp claim_itms_list, byte[] src, Json_itm_kv claim_grp) { - Json_itm_ary claim_itms_ary = Json_itm_ary.cast_(claim_grp.Val()); - int claim_itms_len = claim_itms_ary.Subs_len(); - byte[] pid_bry = claim_grp.Key().Data_bry(); - int pid = Bry_.Xto_int_or(pid_bry, 1, pid_bry.length, -1); - for (int i = 0; i < claim_itms_len; ++i) { - Json_itm_nde claim_itm_nde = Json_itm_nde.cast_(claim_itms_ary.Subs_get_at(i)); - Wdata_claim_itm_base itm = Parse_claim_itm(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 Wdata_claim_itm_base Parse_claim_itm(Json_itm_nde nde, int pid) { - int len = nde.Subs_len(); - Hash_adp_bry dict = Wdata_dict_claim.Dict; - byte rank_tid = Wdata_dict_rank.Tid_unknown; - Wdata_claim_itm_base claim_itm = null; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - switch (tid) { - case Wdata_dict_claim.Tid_mainsnak: claim_itm = Parse_mainsnak(Json_itm_nde.cast_(sub.Val()), pid); break; - case Wdata_dict_claim.Tid_rank: rank_tid = Wdata_dict_rank.Xto_tid(sub.Val().Data_bry()); break; - case Wdata_dict_claim.Tid_references: break; - case Wdata_dict_claim.Tid_qualifiers: break; - case Wdata_dict_claim.Tid_qualifiers_order: 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); - return claim_itm; - } - public Wdata_claim_itm_base Parse_mainsnak(Json_itm_nde nde, int pid) { - int len = nde.Subs_len(); - Hash_adp_bry dict = Wdata_dict_mainsnak.Dict; - byte snak_tid = Byte_.MaxValue_127; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - switch (tid) { - case Wdata_dict_mainsnak.Tid_snaktype: snak_tid = Wdata_dict_snak_tid.Xto_tid(sub.Val().Data_bry()); break; - case Wdata_dict_mainsnak.Tid_datavalue: return Parse_datavalue(pid, snak_tid, Json_itm_nde.cast_(sub.Val())); - case Wdata_dict_mainsnak.Tid_property: break; // ignore: pid already available above - case Wdata_dict_mainsnak.Tid_hash: break; // ignore: "84487fc3f93b4f74ab1cc5a47d78f596f0b49390" - } - } - return null; // NOTE: mainsnak can be null; PAGE:Q2!P576; DATE:2014-09-20 - } - public Wdata_claim_itm_base Parse_datavalue(int pid, byte snak_tid, Json_itm_nde nde) { - int len = nde.Subs_len(); - Hash_adp_bry dict = Wdata_dict_datavalue.Dict; - Json_itm value_itm = null; byte value_tid = Wdata_dict_val_tid.Tid_unknown; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - switch (tid) { - case Wdata_dict_datavalue.Tid_type: value_tid = Wdata_dict_val_tid.Xto_tid(sub.Val().Data_bry()); break; - case Wdata_dict_datavalue.Tid_value: value_itm = sub.Val(); break; - } - } - switch (value_tid) { - case Wdata_dict_val_tid.Tid_string: return new Wdata_claim_itm_str(pid, snak_tid, value_itm.Data_bry()); - case Wdata_dict_val_tid.Tid_entity: return Parse_datavalue_entity (pid, snak_tid, Json_itm_nde.cast_(value_itm)); - case Wdata_dict_val_tid.Tid_time: return Parse_datavalue_time (pid, snak_tid, Json_itm_nde.cast_(value_itm)); - case Wdata_dict_val_tid.Tid_quantity: return Parse_datavalue_quantity (pid, snak_tid, Json_itm_nde.cast_(value_itm)); - case Wdata_dict_val_tid.Tid_globecoordinate: return Parse_datavalue_globecoordinate (pid, snak_tid, Json_itm_nde.cast_(value_itm)); - case Wdata_dict_val_tid.Tid_monolingualtext: return Parse_datavalue_monolingualtext (pid, snak_tid, Json_itm_nde.cast_(value_itm)); - } - throw Err_.new_("unknown val_tid; val_tid={0}", value_tid); - } - private Wdata_claim_itm_base Parse_datavalue_entity(int pid, byte snak_tid, Json_itm_nde nde) { - Hash_adp_bry dict = Wdata_dict_value_entity.Dict; - int len = nde.Subs_len(); - byte[] entity_id_bry = null; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - switch (tid) { - case Wdata_dict_value_entity.Tid_entity_type: break; // ignore: "item" - case Wdata_dict_value_entity.Tid_numeric_id: entity_id_bry = sub.Val().Data_bry(); break; - } - } - if (entity_id_bry == null) throw Err_.new_("pid is invalid entity; pid={0}", pid); - return new Wdata_claim_itm_entity(pid, snak_tid, entity_id_bry); - } - private Wdata_claim_itm_base Parse_datavalue_monolingualtext(int pid, byte snak_tid, Json_itm_nde nde) { - Hash_adp_bry dict = Wdata_dict_value_monolingualtext.Dict; - int len = nde.Subs_len(); - byte[] lang = null, text = null; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - byte[] sub_val_bry = sub.Val().Data_bry(); - switch (tid) { - case Wdata_dict_value_monolingualtext.Tid_text: text = sub_val_bry; break; - case Wdata_dict_value_monolingualtext.Tid_language: lang = sub_val_bry; break; - } - } - if (lang == null || text == null) throw Err_.new_("pid is invalid monolingualtext; pid={0}", pid); - return new Wdata_claim_itm_monolingualtext(pid, snak_tid, lang, text); - } - private Wdata_claim_itm_base Parse_datavalue_globecoordinate(int pid, byte snak_tid, Json_itm_nde nde) { - Hash_adp_bry dict = Wdata_dict_value_globecoordinate.Dict; - int len = nde.Subs_len(); - byte[] lat = null, lng = null, alt = null, prc = null, glb = null; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - byte[] sub_val_bry = sub.Val().Data_bry(); - switch (tid) { - case Wdata_dict_value_globecoordinate.Tid_latitude: lat = sub_val_bry; break; - case Wdata_dict_value_globecoordinate.Tid_longitude: lng = sub_val_bry; break; - case Wdata_dict_value_globecoordinate.Tid_altitude: alt = sub_val_bry; break; - case Wdata_dict_value_globecoordinate.Tid_precision: prc = sub_val_bry; break; - case Wdata_dict_value_globecoordinate.Tid_globe: glb = sub_val_bry; break; - } - } - if (lat == null || lng == null) throw Err_.new_("pid is invalid globecoordinate; pid={0}", pid); - return new Wdata_claim_itm_globecoordinate(pid, snak_tid, lat, lng, alt, prc, glb); - } - private Wdata_claim_itm_base Parse_datavalue_quantity(int pid, byte snak_tid, Json_itm_nde nde) { - Hash_adp_bry dict = Wdata_dict_value_quantity.Dict; - int len = nde.Subs_len(); - byte[] amount = null, unit = null, ubound = null, lbound = null; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - byte[] sub_val_bry = sub.Val().Data_bry(); - switch (tid) { - case Wdata_dict_value_quantity.Tid_amount: amount = sub_val_bry; break; - case Wdata_dict_value_quantity.Tid_unit: unit = sub_val_bry; break; - case Wdata_dict_value_quantity.Tid_upperbound: ubound = sub_val_bry; break; - case Wdata_dict_value_quantity.Tid_lowerbound: lbound = sub_val_bry; break; - } - } - if (amount == null) throw Err_.new_("pid is invalid quantity; pid={0}", pid); - return new Wdata_claim_itm_quantity(pid, snak_tid, amount, unit, ubound, lbound); - } - private Wdata_claim_itm_base Parse_datavalue_time(int pid, byte snak_tid, Json_itm_nde nde) { - Hash_adp_bry dict = Wdata_dict_value_time.Dict; - int len = nde.Subs_len(); - byte[] time = null, timezone = null, before = null, after = null, precision = null, calendarmodel = null; - for (int i = 0; i < len; ++i) { - Json_itm_kv sub = Json_itm_kv.cast_(nde.Subs_get_at(i)); - byte tid = Wdata_dict_utl.Get_tid_or_fail(dict, sub.Key().Data_bry()); - byte[] sub_val_bry = sub.Val().Data_bry(); - switch (tid) { - case Wdata_dict_value_time.Tid_time: time = sub_val_bry; break; - case Wdata_dict_value_time.Tid_timezone: timezone = sub_val_bry; break; - case Wdata_dict_value_time.Tid_before: before = sub_val_bry; break; - case Wdata_dict_value_time.Tid_after: after = sub_val_bry; break; - case Wdata_dict_value_time.Tid_precision: precision = sub_val_bry; break; - case Wdata_dict_value_time.Tid_calendarmodel: calendarmodel = sub_val_bry; break; - } - } - if (time == null) throw Err_.new_("pid is invalid time; pid={0}", pid); - return new Wdata_claim_itm_time(pid, snak_tid, time, timezone, before, after, precision, calendarmodel); - } -} diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2_tst.java index c0a5f3402..17ff66792 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/parsers/Wdata_doc_parser_v2_tst.java @@ -169,6 +169,24 @@ public class Wdata_doc_parser_v2_tst { , fxt.Make_claim_str(1, "abc") ); } + @Test public void Claims_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 Claims_data_string() { fxt.Test_claims_data(String_.Concat_lines_nl_skip_last ( "{ 'value':'abc'" @@ -247,7 +265,104 @@ public class Wdata_doc_parser_v2_tst { , fxt.Make_claim_time(1, "2001-02-03 04:05:06") ); } -} -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();} + @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(1, 11), fxt.Make_claim_entity(1, 12), fxt.Make_claim_entity(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(2, 21), fxt.Make_claim_entity(3, 31)) + ; + } } diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java index b3f148584..d34e7bcca 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/pfuncs/Wdata_pf_property_tst.java @@ -21,83 +21,83 @@ public class Wdata_pf_property_tst { @Before public void init() {fxt.Init();} Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt(); @Test public void String() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_str_(1, "a"))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_str(1, "a"))); fxt.Test_parse("{{#property:p1}}", "a"); fxt.Test_parse("{{#property:p2}}", ""); } @Test public void Entity() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc()); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); + fxt.Init_pages_add(fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc()); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_entity(1, 2))); fxt.Test_parse("{{#property:p1}}", "b"); } @Test public void Entity_fr() { // PURPOSE: non-English wiki should default to English label if non-English label not available; DATE:2013-12-19 fxt.Wiki().Wdata_wiki_lang_(Bry_.new_ascii_("fr")); // set wiki to French fxt.Init_links_add("frwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); // create wdata page Q1 with prop entity reference to Q2 - fxt.Init_pages_add(fxt.page_bldr_("q2").Label_add("en", "b").Xto_page_doc()); // create wdata page Q2 with label in en (not fr) + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_entity(1, 2))); // create wdata page Q1 with prop entity reference to Q2 + fxt.Init_pages_add(fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc()); // create wdata page Q2 with label in en (not fr) fxt.Test_parse("{{#property:p1}}", "b"); // parse; should get en label } @Test public void Entity_missing() { // PURPOSE: 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 fxt.Init_links_add("enwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_entity_(1, 2))); // create wdata page Q1 with prop entity reference to Q2; note that Q2 is not created + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_entity(1, 2))); // create wdata page Q1 with prop entity reference to Q2; note that Q2 is not created fxt.Test_parse("{{#property:p1}}", ""); // parse; get "" } @Test public void Time() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_time_(1, "2012-01-02 03:04:05"))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_time(1, "2012-01-02 03:04:05"))); fxt.Test_parse("{{#property:p1}}", "+00000002012-01-02T03:04:05Z"); } @Test public void Geodata() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_geodata_(1, "1.2345", "6.789"))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_geo(1, "1.2345", "6.789"))); fxt.Test_parse("{{#property:p1}}", "1.2345, 6.789"); } @Test public void Quantity() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_quantity_(1, "+1,234", "2", "+1,236", "+1232"))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1,234", "2", "+1,236", "+1232"))); fxt.Test_parse("{{#property:p1}}", "1,234±2"); } @Test public void Monolingualtext() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_monolingualtext_(1, "Lorem ipsum dolor sit amet", "la"))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_monolingual(1, "la", "Lorem ipsum dolor sit amet"))); fxt.Test_parse("{{#property:p1}}", "Lorem ipsum dolor sit amet"); } @Test public void Novalue() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_novalue_(1))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_novalue(1))); fxt.Test_parse("{{#property:p1}}", "novalue"); } @Test public void Somevalue() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_somevalue_(1))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_somevalue(1))); fxt.Test_parse("{{#property:p1}}", "somevalue"); } @Test public void Multiple() { fxt.Init_links_add("enwiki", "Test_page", "q1"); - fxt.Init_pages_add(fxt.doc_("q1", fxt.prop_str_(1, "a"), fxt.prop_str_(1, "b"))); + fxt.Init_pages_add(fxt.doc_("q1", fxt.Make_claim_str(1, "a"), fxt.Make_claim_str(1, "b"))); fxt.Test_parse("{{#property:p1}}", "a, b"); } @Test public void Q() { fxt.Init_links_add("enwiki", "Test_page", "q2"); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Init_pages_add(fxt.doc_("q2", fxt.Make_claim_str(1, "a"))); fxt.Test_parse("{{#property:p1|q=q2}}", "a"); } @Test public void Of() { fxt.Init_links_add("enwiki", "Of_page", "q2"); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Init_pages_add(fxt.doc_("q2", fxt.Make_claim_str(1, "a"))); fxt.Test_parse("{{#property:p1|of=Of_page}}", "a"); } @Test public void Pid_as_name() { fxt.Init_links_add("enwiki", "Test_page", "q2"); fxt.Init_pids_add("en", "astronomic symbol", 1); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Init_pages_add(fxt.doc_("q2", fxt.Make_claim_str(1, "a"))); fxt.Test_parse("{{#property:astronomic symbol}}", "a"); } @Test public void Empty_arg() { // PURPOSE: {{#property:p1|}} should not fail / warn; DATE:2013-11-15 fxt.Init_links_add("enwiki", "Test_page", "q2"); fxt.Init_pids_add("en", "astronomic symbol", 1); - fxt.Init_pages_add(fxt.doc_("q2", fxt.prop_str_(1, "a"))); + fxt.Init_pages_add(fxt.doc_("q2", fxt.Make_claim_str(1, "a"))); fxt.Test_parse("{{#property:p1|}}", "a"); } @Test public void Data() { @@ -119,7 +119,6 @@ class Wdata_pf_property_data_fxt { if (app == null) { parser_fxt = new Xop_fxt(); app = parser_fxt.App(); - page_bldr = new Wdata_doc_bldr(app.Wiki_mgr().Wdata_mgr()); wdata_mgr = app.Wiki_mgr().Wdata_mgr(); } Io_mgr._.InitEngine_mem(); @@ -128,7 +127,7 @@ class Wdata_pf_property_data_fxt { expd_id_int = -1; expd_q = expd_of = null; return this; - } private Xoa_app app; Wdata_wiki_mgr wdata_mgr; Wdata_doc_bldr page_bldr; Xop_fxt parser_fxt; + } private Xoa_app app; private Wdata_wiki_mgr wdata_mgr; private Xop_fxt parser_fxt; public Wdata_pf_property_data_fxt Expd_id_int_(int v) {expd_id_int = v; return this;} private int expd_id_int; public Wdata_pf_property_data_fxt Expd_q_(String v) {expd_q = Bry_.new_ascii_(v); return this;} private byte[] expd_q; public Wdata_pf_property_data_fxt Expd_of_(String v) {expd_of = Bry_.new_ascii_(v); return this;} private byte[] expd_of; diff --git a/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page_tst.java b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page_tst.java index 2d8d6197e..0dc2984b6 100644 --- a/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page_tst.java +++ b/400_xowa/src/gplx/xowa/xtns/wdatas/specials/Wdata_itemByTitle_page_tst.java @@ -52,7 +52,7 @@ class Wdata_itemByTitle_page_fxt { } private Xop_fxt parser_fxt; private Xoa_app app; private Wdata_itemByTitle_page special_page; private Xow_wiki wiki; Wdata_wiki_mgr_fxt wdata_fxt; public void Init_wdata_page(String qid_ttl, String text) { - Wdata_doc doc = wdata_fxt.doc_(qid_ttl); + Wdata_doc doc = wdata_fxt.Wdoc_bldr(qid_ttl).Xto_wdoc(); app.Wiki_mgr().Wdata_mgr().Pages_add(Bry_.new_ascii_(qid_ttl), doc); parser_fxt.Init_page_create(app.Wiki_mgr().Wdata_mgr().Wdata_wiki(), qid_ttl, text); } diff --git a/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java b/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java index 68bb04aea..d282c1937 100644 --- a/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java +++ b/400_xowa/src_120_wiki/gplx/xowa/Xow_wiki.java @@ -135,7 +135,7 @@ public class Xow_wiki implements GfoInvkAble { public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return GetPageByTtl(url, ttl, lang, tab, true);} public Xoa_page GetPageByTtl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab, boolean parse_page) { if (init_needed) Init_wiki(app.User()); - Xoa_page page = data_mgr.Get_page(url, ttl, false, false); // get page from data_mgr + Xoa_page page = data_mgr.Get_page(url, ttl, false, false); // get page from data_mgr if (page.Missing()) { // page doesn't exist if (ttl.Ns().Id_file()) { Xow_wiki commons_wiki = app.Wiki_mgr().Get_by_key_or_null(commons_wiki_key); diff --git a/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java b/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java index b4c8281b1..8019506e7 100644 --- a/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java +++ b/400_xowa/src_400_parser/gplx/xowa/Xoa_ttl.java @@ -213,9 +213,12 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. if (amp_itm.Tid() == Xop_amp_trie_itm.Tid_name) { switch (amp_itm.Char_int()) { case 160: // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]] - b_ary = Bry_space; - break; + if (ltr_bgn != -1) add_ws = true; // apply same ws rules as Space, NewLine; needed for converting multiple ws into one; EX:"   " -> " " x> " "; PAGEen.w:Greek_government-debt_crisis; DATE:2014-09-25 + cur = match_pos; // set cur after ";" + continue; case Byte_ascii.Amp: + b_ary = Byte_ascii.Amp_bry; // NTOE: if & convert to &; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23 + break; case Byte_ascii.Quote: case Byte_ascii.Lt: case Byte_ascii.Gt: @@ -352,7 +355,6 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF. tors_txt = tors_ns.Name_txt_w_colon(); return true; } - private byte[] Bry_space = Bry_.new_ascii_(" "); public static byte[] Replace_spaces(byte[] raw) {return Bry_.Replace(raw, Byte_ascii.Space, Byte_ascii.Underline);} public static byte[] Replace_unders(byte[] raw) {return Bry_.Replace(raw, Byte_ascii.Underline, Byte_ascii.Space);} private int wik_bgn = -1, ns_bgn = -1, page_bgn = 0, leaf_bgn = -1, anch_bgn = -1, root_bgn = -1; diff --git a/400_xowa/src_400_parser/gplx/xowa/Xop_redirect_mgr_tst.java b/400_xowa/src_400_parser/gplx/xowa/Xop_redirect_mgr_tst.java index 04b4c98a5..9c4fa019a 100644 --- a/400_xowa/src_400_parser/gplx/xowa/Xop_redirect_mgr_tst.java +++ b/400_xowa/src_400_parser/gplx/xowa/Xop_redirect_mgr_tst.java @@ -36,6 +36,7 @@ public class Xop_redirect_mgr_tst { } @Test public void Url_decode() {fxt.Test_redirect("#REDIRECT [[A%28B%29]]" , "A(B)");} // PURPOSE: url-decode links; PAGE:en.w:Watcher_(Buffy_the_Vampire_Slayer); DATE:2014-08-18 @Test public void Url_decode_plus() {fxt.Test_redirect("#REDIRECT [[A%28B%29+]]", "A(B)+");} // PURPOSE: do not url-decode +; PAGE:en.w:Template:Positionskarte+; DATE:2014-08-22 + @Test public void Amp() {fxt.Test_redirect("#REDIRECT [[A & B]]", "A & B");} // PURPOSE: & -> &; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23 @Test public void Frame_ttl() { // PURPOSE: redirect should set invk frame title to redirect_trg, not original; PAGE:en.w:Statutory_city DATE:2014-08-22 fxt.Test_frame_ttl("Template:A", "#REDIRECT [[Template:B]]", "Template:B", "Template:B"); } diff --git a/400_xowa/src_490_xnde/gplx/xowa/Xop_xatr_parser.java b/400_xowa/src_490_xnde/gplx/xowa/Xop_xatr_parser.java index 58291ca02..6f015c988 100644 --- a/400_xowa/src_490_xnde/gplx/xowa/Xop_xatr_parser.java +++ b/400_xowa/src_490_xnde/gplx/xowa/Xop_xatr_parser.java @@ -23,7 +23,7 @@ public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_AT private int atr_bgn = -1, key_bgn = -1, key_end = -1, eq_pos = -1, val_bgn = -1, val_end = -1; boolean valid = true; private byte quote_byte = Byte_ascii.Nil; private Hash_adp_bry repeated_atrs_hash = Hash_adp_bry.ci_ascii_(); // ASCII:xnde_atrs - private Bry_bfr key_bfr = Bry_bfr.new_(), val_bfr = Bry_bfr.new_(); boolean key_bfr_on = false, val_bfr_on = false; + private Bry_bfr key_bfr = Bry_bfr.new_(), val_bfr = Bry_bfr.new_(); boolean key_bfr_on = false, val_bfr_on = false, ws_is_before_val = false; public Bry_obj_ref Bry_obj() {return bry_ref;} private Bry_obj_ref bry_ref = Bry_obj_ref.null_(); public int Xnde_find_gt_find(byte[] src, int pos, int end) { bry_ref.Val_(null); @@ -84,6 +84,7 @@ public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_AT mode = Mode_atr_bgn; val_bfr.Clear(); val_bfr_on = false; + ws_is_before_val = false; continue; } else @@ -219,6 +220,7 @@ public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_AT case Mode_val_bgn: switch (b) { case Byte_ascii.Space: case Byte_ascii.NewLine: case Byte_ascii.Tab: // skip-ws + ws_is_before_val = true; break; case Byte_ascii.Quote: case Byte_ascii.Apos: mode = Mode_val_quote; quote_byte = b; prv_is_ws = false; @@ -262,15 +264,11 @@ public class Xop_xatr_parser { // REF.MW:Sanitizer.php|decodeTagAttributes;MW_AT Make(log_mgr, src, i + 1); // NOTE: set atr_end *after* quote } prv_is_ws = false; if (val_bfr_on) val_bfr.Add_byte(b); // INLINE: add char -// else { -// if (!val_bfr_on) val_bfr.Add_mid(src, val_bgn, i + 1); // +1 to include ' -// val_bfr_on = true; -// } break; case Byte_ascii.Lt: // "<" try to find nowiki inside atr int gt_pos = Xnde_find_gt(log_mgr, src, i, end); if (gt_pos == String_.Find_none) { -// valid = false; mode = Mode_invalid; // DELETE: 2012-11-13; unpaired < should not mark atr invalid; EX: style='margin:1ema
  • b" -> "
  • a
  • b" End_tag(ctx, root, prv_xnde, src, src_len, bgn_pos - 1, bgn_pos - 1, tagId, true, tag); } - else if (!tag.Nest() && Stack_find_xnde(ctx, tagId)) return ctx.Lxr_make_log_(Xop_xnde_log.Invalid_nest, src, bgn_pos, gtPos); else if (tag.SingleOnly()) inline = true; //

    not allowed; convert
    to

    will be escaped else if (tag.NoInline() && inline) { Xop_xnde_tkn xnde_inline = Xnde_bgn(ctx, tkn_mkr, root, tag, Xop_xnde_tkn.CloseMode_open, src, bgn_pos, open_tag_end, atrs_bgn, atrs_end, atrs); diff --git a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__basic_tst.java b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__basic_tst.java index 80acce3a6..a4dd78934 100644 --- a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__basic_tst.java +++ b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__basic_tst.java @@ -68,15 +68,6 @@ public class Xop_xnde_wkr__basic_tst { @Test public void Escaped() { fxt.Init_log_(Xop_xnde_log.Escaped_xnde).Test_parse_page_wiki("
    ", fxt.tkn_xnde_(0, 18).Subs_(fxt.tkn_bry_(5, 12)));// TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 } - @Test public void Nest() {// REVISIT: 2nd should be converted to ; other ignored; WHEN: with example - fxt.Init_log_(Xop_xnde_log.Invalid_nest, Xop_xnde_log.Escaped_xnde).Test_parse_page_wiki("abcde" - , fxt.tkn_txt_ ( 0, 1) - , fxt.tkn_xnde_ ( 1, 13).Subs_(fxt.tkn_txt_(4, 9)) - , fxt.tkn_txt_ (13, 14) - , fxt.tkn_bry_(14, 18) // TIDY.dangling: tidy will correct dangling node; DATE:2014-07-22 - , fxt.tkn_txt_ (18, 19) - ); - } @Test public void Xtn() { fxt.Test_parse_page_wiki("
    ", fxt.tkn_xnde_(0, 18).Subs_(fxt.tkn_txt_(6, 11))); // NOTE: no dangling nde b/c .Xtn skips } diff --git a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__err_dangling_tst.java b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__err_dangling_tst.java index 4c3c21ef4..8b4f9adce 100644 --- a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__err_dangling_tst.java +++ b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__err_dangling_tst.java @@ -30,9 +30,9 @@ public class Xop_xnde_wkr__err_dangling_tst { } @Test public void Nested() { fxt.Test_parse_page_wiki_str - ( "
    a
    " - , "
    a
    " - ); + ( "
    a
    " + , "
    a
    " + ); } @Test public void Center() { fxt.Init_log_(Xop_xnde_log.Dangling_xnde).Test_parse_page_wiki("a
    b" @@ -47,6 +47,12 @@ public class Xop_xnde_wkr__err_dangling_tst { , fxt.tkn_xnde_ (5, 13).Subs_(fxt.tkn_txt_(8, 9)) ); } + @Test public void Alternating() { // PURPOSE: confirmation test for alternating dangling nodes; PAGE:en.w:Portal:Pornography/Selected_historical_image/Archive; DATE:2014-09-24 + fxt.Test_parse_page_wiki_str + ( "cde" + , "cde" + ); + } @Test public void Li() { // PURPOSE: auto-close
  • ; NOTE: no longer encloses in
      ; DATE:2014-06-26 fxt.Test_parse_page_wiki_str ( "
    • a
    • b" diff --git a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_basic_tst.java b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_basic_tst.java index bbfab71b9..42089ac75 100644 --- a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_basic_tst.java +++ b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_basic_tst.java @@ -69,15 +69,15 @@ public class Xop_xnde_wkr__include_basic_tst { -({{{1}}}={{{1}}}round-5)-({{{1}}}={{{1}}}round-4)-({{{1}}}={{{1}}}round-3)-({{{1}}}={{{1}}}round-2)-({{{1}}}={{{1}}}round-1) {{pp-template}}Called by {{lt|precision/0}} -==includeonly== +==includeonly -- aka: do not eval in template == main: abc
      tmpl: {{mwo_include_only|a|b|c}} -==noinclude== +==noinclude -- aka: eval in template only== main: abc
      tmpl: {{mwo_no_include|a|b|c}} -==onlyinclude== +==onlyinclude -- aka: only include in template only (ignore everything else) == main: abc
      tmpl: {{mwo_only_include|a|b|c}} */ \ No newline at end of file diff --git a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_uncommon_tst.java b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_uncommon_tst.java index 1c32b819d..ca3027708 100644 --- a/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_uncommon_tst.java +++ b/400_xowa/src_490_xnde/gplx/xowa/Xop_xnde_wkr__include_uncommon_tst.java @@ -172,10 +172,6 @@ public class Xop_xnde_wkr__include_uncommon_tst { ( "
      a
      " )); } - @Test public void Noinclude_inline_w_space_inside_safesubst() { // PURPOSE: "" did not work with safesubst b/c of space; PAGE:en.w:Wikipedia:Featured_picture_candidates; DATE:2014-06-24 - fxt.Test_parse_tmpl_str_test("{{SAFESUBST:#if:val_exists|y|n}}", "{{test}}", "y"); - } - // @Test public void Pre_and_includeonly2() { // fxt.Init_defn_add("pre2", ">{{{1}}}"); // fxt.Test_parse_page_all_str @@ -184,4 +180,15 @@ public class Xop_xnde_wkr__include_uncommon_tst { // ( "
      a
      " // )); // } + @Test public void Noinclude_inline_w_space_inside_safesubst() { // PURPOSE: "" did not work with safesubst b/c of space; PAGE:en.w:Wikipedia:Featured_picture_candidates; DATE:2014-06-24 + fxt.Test_parse_tmpl_str_test("{{SAFESUBST:#if:val_exists|y|n}}", "{{test}}", "y"); + } + @Test public void Subst() {// PURPOSE: handle subst-includeonly-subst combination; PAGE:pt.w:Argentina DATE:2014-09-24 + fxt.Init_defn_clear(); + fxt.Init_defn_add("test", "{{subst:#switch:1|1=y|default=n}}"); + //fxt.Init_defn_add("test", "{{subst:#switch:1|1=y|default=n}}"); // keeping around for debugging purposes + //fxt.Init_defn_add("test", "{{#switch:1|1=y|default=n}}"); // keeping around for debugging purposes + fxt.Test_parse_page_all_str("{{test}}", "{{subst:#switch:1|1=y|default=n}}"); // note that subst is preserved b/c of + fxt.Test_parse_page_all_str("{{subst:test}}", "y"); // note that expression is evaluated b/c of subst: + } } diff --git a/400_xowa/src_500_tmpl/gplx/xowa/Arg_itm_tkn.java b/400_xowa/src_500_tmpl/gplx/xowa/Arg_itm_tkn.java index cc67223fb..5d4192f59 100644 --- a/400_xowa/src_500_tmpl/gplx/xowa/Arg_itm_tkn.java +++ b/400_xowa/src_500_tmpl/gplx/xowa/Arg_itm_tkn.java @@ -25,6 +25,7 @@ public interface Arg_itm_tkn extends Xop_tkn_itm { byte[] Dat_ary(); Arg_itm_tkn Dat_ary_(byte[] dat_ary); byte[] Dat_to_bry(byte[] src); + boolean Dat_ary_had_subst(); void Dat_ary_had_subst_y_(); byte Itm_static(); Arg_itm_tkn Itm_static_(boolean v); Arg_itm_tkn Subs_add_ary(Xop_tkn_itm... ary); } @@ -35,6 +36,7 @@ class Arg_itm_tkn_null extends Xop_tkn_null implements Arg_itm_tkn { public int public byte[] Dat_ary() {return Bry_.Empty;} public Arg_itm_tkn Dat_ary_(byte[] dat_ary) {return this;} public byte[] Dat_to_bry(byte[] src) {return Bry_.Empty;} public Arg_itm_tkn Subs_add_ary(Xop_tkn_itm... ary) {return this;} + public boolean Dat_ary_had_subst() {return false;} public void Dat_ary_had_subst_y_() {} public byte Itm_static() {return Bool_.__byte;} public Arg_itm_tkn Itm_static_(boolean v) {return this;} public static final Arg_itm_tkn_null Null_arg_itm = new Arg_itm_tkn_null(); Arg_itm_tkn_null() {} } @@ -48,6 +50,7 @@ class Arg_itm_tkn_base extends Xop_tkn_itm_base implements Arg_itm_tkn { public byte[] Dat_ary() {return dat_ary;} private byte[] dat_ary = Bry_.Empty; public Arg_itm_tkn Dat_ary_(byte[] dat_ary) {this.dat_ary = dat_ary; return this;} public Arg_itm_tkn Dat_rng_(int bgn, int end) {dat_bgn = bgn; dat_end = end; return this;} + public boolean Dat_ary_had_subst() {return dat_ary_had_subst;} public void Dat_ary_had_subst_y_() {dat_ary_had_subst = true;} private boolean dat_ary_had_subst = false; public Arg_itm_tkn Dat_rng_ary_(byte[] src, int bgn, int end) { dat_bgn = bgn; dat_end = end; dat_ary = Bry_.Mid(src, bgn, end); diff --git a/400_xowa/src_500_tmpl/gplx/xowa/Xot_fmtr.java b/400_xowa/src_500_tmpl/gplx/xowa/Xot_fmtr.java index b5f4689ba..09fa0e4b6 100644 --- a/400_xowa/src_500_tmpl/gplx/xowa/Xot_fmtr.java +++ b/400_xowa/src_500_tmpl/gplx/xowa/Xot_fmtr.java @@ -56,6 +56,7 @@ class Xot_fmtr_prm implements Xot_fmtr { --depth; trg.Add(Xop_curly_end_lxr.Hook); } + public void Write(byte b) {trg.Add_byte(b);} public void Reg_arg(Xop_ctx ctx, byte[] src, int arg_idx, Arg_nde_tkn self_tkn) { self_tkn.Key_tkn().Tmpl_fmt(ctx, src, this); if (self_tkn.KeyTkn_exists()) { diff --git a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java index 74f822a1b..daff9fdf0 100644 --- a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java +++ b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_tkn.java @@ -51,6 +51,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk { byte[] name_ary_orig = Bry_.Empty; int name_bgn = 0, name_ary_len = 0; boolean subst_found = false; + boolean name_had_subst = false; if (defn == Xot_defn_.Null) { // tmpl_name is not exact match; may be dynamic, subst, transclusion, etc.. if (name_key_tkn.Itm_static() == Bool_.N_byte) { // tmpl is dynamic; EX:{{{{{1}}}|a}} Bry_bfr name_tkn_bfr = Bry_bfr.new_(name_tkn.Src_end() - name_tkn.Src_bgn()); @@ -61,6 +62,7 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk { } else // tmpl is static; note that dat_ary is still valid but rest of name may not be; EX: {{subst:name{{{1}}}}} name_ary = Bry_.Mid(src, name_key_tkn.Dat_bgn(), name_key_tkn.Dat_end()); + name_had_subst = name_key_tkn.Dat_ary_had_subst(); name_ary_orig = name_ary; // cache name_ary_orig name_ary_len = name_ary.length; name_bgn = Bry_finder.Find_fwd_while_not_ws(name_ary, 0, name_ary_len); @@ -99,28 +101,18 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk { int colon_pos = -1; switch (finder.Tid()) { case Xot_defn_.Tid_subst: // subst is added verbatim; EX: {{subst:!}} -> {{subst:!}}; logic below is to handle printing of arg which could be standardized if src[] was available for tmpl -// if (ctx.Parse_tid() == Xop_parser_.Parse_tid_tmpl) { - bfr.Add(Xop_curly_bgn_lxr.Hook).Add(name_ary); - for (int i = 0; i < args_len; i++) { - Arg_nde_tkn nde = args[i]; - bfr.Add_byte(Byte_ascii.Pipe); - nde.Tmpl_fmt(ctx, src, Xot_fmtr_prm._); - } - Xot_fmtr_prm._.Print(bfr); - bfr.Add(Xop_curly_end_lxr.Hook); - return true; // NOTE: nothing else to do; return -// } -// else { -// name_ary = Bry_.Mid(name_ary, finder.Subst_end(), name_ary_len); // chop off "safesubst:" -// name_ary_len = name_ary.length; -// if (defn != Xot_defn_.Null) { // func found -// if (finder.Colon_pos() != -1) colon_pos = finder.Func().Name().length; // set colon_pos; SEE NOTE_1 -// } -// subst_found = true; -// } -// break; + bfr.Add(Xop_curly_bgn_lxr.Hook).Add(name_ary); + for (int i = 0; i < args_len; i++) { + Arg_nde_tkn nde = args[i]; + // bfr.Add_byte(Byte_ascii.Pipe); + Xot_fmtr_prm._.Write(Byte_ascii.Pipe); + nde.Tmpl_fmt(ctx, src, Xot_fmtr_prm._); + } + Xot_fmtr_prm._.Print(bfr); + bfr.Add(Xop_curly_end_lxr.Hook); + return true; // NOTE: nothing else to do; return case Xot_defn_.Tid_safesubst: - name_ary = Bry_.Mid(name_ary, finder.Subst_end(), name_ary_len); // chop off "safesubst:" + name_ary = Bry_.Mid(name_ary, finder.Subst_end(), name_ary_len); // chop off "safesubst:" name_ary_len = name_ary.length; if (defn != Xot_defn_.Null) { // func found if (finder.Colon_pos() != -1) colon_pos = finder.Func().Name().length; // set colon_pos; SEE NOTE_1 @@ -270,6 +262,10 @@ public class Xot_invk_tkn extends Xop_tkn_itm_base implements Xot_invk { else { rv = defn_tmpl.Tmpl_evaluate(ctx, invk_tmpl, rslt_bfr); prepend_mgr.End(ctx, bfr, rslt_bfr.Bfr(), rslt_bfr.Len(), Bool_.Y); + if (name_had_subst) { // current invk had "subst:"; parse incoming invk again to remove effects of subst; PAGE:pt.w:Argentina DATE:2014-09-24 + byte[] tmp_src = rslt_bfr.XtoAryAndClear(); + rslt_bfr.Add(wiki.Parser().Parse_text_to_wtxt(tmp_src)); // this could be cleaner / more optimized + } if (Cache_enabled) { byte[] rslt_val = rslt_bfr.XtoAryAndClear(); bfr.Add(rslt_val); diff --git a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_wkr.java b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_wkr.java index 4c4ecd0cb..89c8443b1 100644 --- a/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_wkr.java +++ b/400_xowa/src_500_tmpl/gplx/xowa/Xot_invk_wkr.java @@ -74,8 +74,10 @@ public class Xot_invk_wkr implements Xop_ctx_wkr, Xop_arg_wkr { if ((ctx.Parse_tid() == Xop_parser_.Parse_tid_tmpl && finder_typeId == Xot_defn_.Tid_subst) // NOTE: if subst, but in tmpl stage, do not actually subst; PAGE:en.w:Unreferenced; DATE:2013-01-31 || ctx.Cur_page().Ttl().Ns().Id_tmpl()) { // also, if on tmpl page, never evaluate (questionable, but seems to be needed) } - else + else { key_tkn.Dat_rng_ary_(src, subst_end, txt_end); // redo txt_rng to ignore subst + key_tkn.Dat_ary_had_subst_y_(); + } if (finder_func != Xot_defn_.Null) { colon_pos = finder.Colon_pos(); txt_bgn = subst_end; diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 000000000..23714921b --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,15 @@ +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 +[http://www.gnu.org/licenses/agpl.txt 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 . diff --git a/README.md b/README.md deleted file mode 100644 index b9bf4685e..000000000 --- a/README.md +++ /dev/null @@ -1,23 +0,0 @@ -## xowa: the xowa offline wiki application - -### Summary -XOWA is an application for reading Wikipedia and other wikis offline. - -### Environment -The xowa_source was built with Eclipse Indigo on Windows. For simplicity's sake, the remainder of these instructions will target Windows machines. There are no OS dependencies, so the same instructions apply to other OS's, except the paths will need to be updated. - -There are no explicit dependencies on Eclipse, so the source code should be usable in other Java IDEs. - -## Instructions -* Download '''xowa_app_windows_*''' from https://sourceforge.net/projects/xowa/files/ and unzip to the proper directory. The following will be required: - * All files under C:\xowa\user\anonymous\ - * The main cfg file: C:\xowa\xowa.gfs - * The swt.jar at C:\xowa\bin\wnt\swt\swt.jar -* Download the xowa repo -* Unzip it to C:\xowa\dev\. You will have a folder called C:\xowa\dev\400_xowa\ as well as many others. -* Move the swt.jar from C:\xowa\bin\wnt\swt\swt.jar to C:\xowa\dev\150_gfui\lib\swt\swt.jar -* Launch Eclipse. Choose a workbench folder of C:\xowa\dev -* Select all four projects. Do File -> Refresh. -* Right-click on 400_xowa in the Package Explorer. Select Debug As -> Java Application. Select Xowa_main. XOWA should launch. -* Right-click on 400_xowa in the Package Explorer. Select Debug As -> JUnit Test. All tests should pass. - diff --git a/README.txt b/README.txt new file mode 100644 index 000000000..50274cc21 --- /dev/null +++ b/README.txt @@ -0,0 +1,61 @@ +== Overview == +XOWA is an offline Wikipedia application. It is meant to be used with the dumps at https://dumps.wikimedia.org. + +This is the initial draft of a README. Most of the instructions below are Windows-centric, and will be updated later to a more machine-agnostic form. + +In addition, the enclosed build.xml assumes a Windows environment with an XOWA installation at C:\xowa. This too will be updated at a later date to be more portable. + +== Requirements == +XOWA is written in Java and requires 1.6 or above. It has seven dependencies: + +# JUnit 4.8.2 (default version with Eclipse) +# [https://download.eclipse.org/eclipse/downloads/drops4/R-4.2.1-201209141800/#SWT SWT 4.2.1]: GUI library +# [https://sourceforge.net/projects/xowa/files/support/luaj/ luaj_xowa.jar]: Lua library +# [https://sourceforge.net/projects/jtidy/files/JTidy/r938/jtidy-r938.jar/download jtidy-r938.jar]: HTML tidy library +# [https://bitbucket.org/xerial/sqlite-jdbc/downloads sqlite-jdbc-3.7.15-SNAPSHOT-2.jar]: Database library +# [https://dev.mysql.com/downloads/connector/j/ mysql-connector-java-5.1.12-bin.jar]: Database library +# [https://jdbc.postgresql.org/download.html postgresql-8.4-701.jdbc4.jar]: Database library + +Note that the last two libraries are not currently used in XOWA. + +== Environment == +The '''xowa_source.7z''' was built with Eclipse Indigo on Windows. For simplicity's sake, the remainder of these instructions will target Windows machines. There are no OS dependencies, so the same instructions apply to other OS's, except the paths will need to be updated. + +There are no explicit dependencies on Eclipse, so the source code should be usable in other Java IDEs. + +== Instructions == +* Download '''xowa_app_windows_*''' and unzip to the proper directory. The following will be required: +** All files under {{fsysname|C:\xowa\user\anonymous\}} +** The main cfg file: {{fsysname|C:\xowa\xowa.gfs}} +** The swt.jar at {{fsysname|C:\xowa\bin\your_platform_name\swt\swt.jar}} +* Download '''xowa_source.7z''' +* Unzip it to {{fsysname|C:\xowa\dev\}}. You will have a folder called {{fsysname|C:\xowa\dev\400_xowa}} as well as many others. +* Move the swt.jar from {{fsysname|C:\xowa\bin\your_platform_name\swt\swt.jar}} to {{fsysname|C:\xowa\dev\150_gfui\lib\swt\swt.jar}} +* Launch Eclipse. Choose a workbench folder of {{fsysname|C:\xowa\dev}} +* Select all four projects. Do File -> Refresh. +* Right-click on 400_xowa in the Package Explorer. Select Debug As -> Java Application. Select Xowa_main. XOWA should launch. +* Right-click on 400_xowa in the Package Explorer. Select Debug As -> JUnit Test. All tests should pass. + +== Eclipse-specific settings == +This section documents specific project customizations that differ from the standard Eclipse defaults. + +=== Project properties === +Resource -> Text file encoding -> Other -> UTF-8 + +=== Preferences === +These settings are available under Window -> Preferences + +*Disable Spelling +:General -> Editors -> Text Editors -> Spelling +*Ignore Warnings +:Java -> Compiler -> Errors/Warnings +:: Annotations -> Unhandled token in '@SuppressWarnings' +:: Potential programming problems -> Serializable class without serialVersionUID +:: Generic Types -> Unnecessary generic type operation +:: Generic Types -> Usage of a raw type +:: Unnecessary Code -> Unused import + +=== Configuration arguments === +*Configuration arguments +:Run -> Debug Configurations -> Arguments +::--root_dir C:\xowa\ --show_license n --show_args n diff --git a/build.xml b/build.xml new file mode 100644 index 000000000..89eeeae06 --- /dev/null +++ b/build.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 b/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 index 344a1a0ed..6778de16f 100644 Binary files a/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 and b/tst/400_xowa/root/wiki/en.wikipedia.org/en.wikipedia.org.002.sqlite3 differ