mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.8.1.1'
This commit is contained in:
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.xtns.cites.*; import gplx.xowa.xtns.imaps.*; import gplx.xowa.xtns.relatedSites.*; import gplx.xowa.xtns.proofreadPage.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.xtns.cites.*; import gplx.xowa.xtns.imaps.*; import gplx.xowa.xtns.relatedSites.*; import gplx.xowa.xtns.proofreadPage.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.xowa.xtns.insiders.*; import gplx.xowa.xtns.indicators.*; import gplx.xowa.xtns.pagebanners.*;
|
||||
public class Xow_xtn_mgr implements Gfo_invk {
|
||||
private Ordered_hash regy = Ordered_hash_.New_bry();
|
||||
|
||||
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
class Gallery_box_w_fmtr_arg implements gplx.core.brys.Bfr_arg {
|
||||
private int width;
|
||||
public Gallery_box_w_fmtr_arg Init(int uid, int width) {this.width = width; return this;}
|
||||
private final int width;
|
||||
public Gallery_box_w_fmtr_arg(int width) {this.width = width;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add(Style_bgn);
|
||||
bfr.Add_int_variable(width);
|
||||
|
||||
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
class Gallery_img_pad_fmtr_arg implements gplx.core.brys.Bfr_arg {
|
||||
private int vpad;
|
||||
public Gallery_img_pad_fmtr_arg Init(int uid, int vpad) {this.vpad = vpad; return this;}
|
||||
private final int vpad;
|
||||
public Gallery_img_pad_fmtr_arg(int vpad) {this.vpad = vpad;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add(Style_bgn);
|
||||
bfr.Add_int_variable(vpad);
|
||||
|
||||
@@ -21,8 +21,6 @@ import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.p
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.parsers.htmls.*;
|
||||
import gplx.xowa.files.*;
|
||||
public class Gallery_mgr_wtr {
|
||||
private static final Gallery_img_pad_fmtr_arg div_3_fmtr_arg = new Gallery_img_pad_fmtr_arg();
|
||||
private static final Gallery_box_w_fmtr_arg li_fmtr_arg = new Gallery_box_w_fmtr_arg();
|
||||
public static void Write_mgr(Bry_bfr bfr, Gallery_mgr_base mgr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Gallery_xnde xnde) {
|
||||
// init
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
@@ -124,7 +122,7 @@ public class Gallery_mgr_wtr {
|
||||
|
||||
// write div_3
|
||||
div_3_margin = mgr.Get_vpad(mgr.Itm_default_h(), html_h_expand);
|
||||
Gallery_mgr_wtr_.Fmtr__div1__vpad.Bld_bfr_many(tmp_bfr, div_3_fmtr_arg.Init(img_uid, div_3_margin)); // <div style="margin:~{vpad}px auto;">
|
||||
Gallery_mgr_wtr_.Fmtr__div1__vpad.Bld_bfr_many(tmp_bfr, new Gallery_img_pad_fmtr_arg(div_3_margin)); // <div style="margin:~{vpad}px auto;">
|
||||
|
||||
// write <img>
|
||||
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_file(tmp_bfr, ctx, hctx, src, lnki, xfer_itm, alt);
|
||||
@@ -134,7 +132,7 @@ public class Gallery_mgr_wtr {
|
||||
|
||||
// write <li>
|
||||
int div_1_w = mgr.Get_gb_width(html_w_expand, html_h_expand);
|
||||
Gallery_mgr_wtr_.Fmtr__li__lhs.Bld_bfr_many(bfr, li_id_atr, li_fmtr_arg.Init(img_uid, div_1_w));
|
||||
Gallery_mgr_wtr_.Fmtr__li__lhs.Bld_bfr_many(bfr, li_id_atr, new Gallery_box_w_fmtr_arg(div_1_w));
|
||||
bfr.Add(itm_html);
|
||||
|
||||
// get show_filenames_link
|
||||
|
||||
@@ -108,7 +108,7 @@ public class Imap_parser {
|
||||
boolean shape_is_poly = shape_tid == Imap_part_.Tid_shape_poly;
|
||||
int pos = Bry_find_.Trim_fwd_space_tab(src, tid_end_pos, itm_end); // gobble any leading spaces
|
||||
int grp_end = Bry_find_.Find_fwd(src, Byte_ascii.Brack_bgn, pos, itm_end); // find first "["; note that this is a lazy way of detecting start of lnki / lnke; MW has complicated regex, but hopefully this will be enough; DATE:2014-10-22
|
||||
if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "imap_No valid link was found");}
|
||||
if (grp_end == -1) {return Add_err(Bool_.Y, itm_bgn, itm_end, "imap.parse:No valid link was found");}
|
||||
int num_bgn = -1, comma_pos = -1, pts_len = 0;
|
||||
while (true) {
|
||||
boolean last = pos == grp_end;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Indicator_html_bldr implements gplx.core.brys.Bfr_arg {
|
||||
bldr_itm.Init(list);
|
||||
fmtr_grp.Bld_bfr_many(bfr, bldr_itm);
|
||||
}
|
||||
private static final Bry_fmtr
|
||||
private static final Bry_fmtr
|
||||
fmtr_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class='mw-indicators'>~{itms}"
|
||||
@@ -54,7 +54,7 @@ class Indicator_html_bldr_itm implements gplx.core.brys.Bfr_arg {
|
||||
fmtr_itm.Bld_bfr_many(bfr, xnde.Name(), xnde.Html());
|
||||
}
|
||||
}
|
||||
private static final Bry_fmtr
|
||||
private static final Bry_fmtr
|
||||
fmtr_itm = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div id='mw-indicator-~{name}' class='mw-indicator'>~{html}</div>"
|
||||
|
||||
@@ -16,11 +16,12 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.listings; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
|
||||
public class Listing_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.New__tmp();
|
||||
public Listing_xnde(int tag_id) {}
|
||||
private byte[] xatr_name, xatr_alt, xatr_address, xatr_directions, xatr_phone, xatr_tollfree, xatr_email, xatr_fax, xatr_url, xatr_hours, xatr_price, xatr_checkin, xatr_checkout;
|
||||
private int xatr_lat = Xatr_meridian_null, xatr_long = Xatr_meridian_null;
|
||||
@@ -171,14 +172,14 @@ public class Listing_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
if (xatr_checkin != null || xatr_checkout != null) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
if (xatr_checkin != null) {
|
||||
byte[] checkin_val = xtn_mgr.Checkin_msg().Fmt(tmp_bfr, xatr_checkin);
|
||||
byte[] checkin_val = xtn_mgr.Checkin_msg().Fmt(tmp_bfr, tmp_fmtr, xatr_checkin);
|
||||
wtr.Txt_raw(checkin_val);
|
||||
if (xatr_checkout != null)
|
||||
wtr.Txt(Txt_comma_space);
|
||||
|
||||
}
|
||||
if (xatr_checkout != null) {
|
||||
byte[] checkout_val = xtn_mgr.Checkout_msg().Fmt(tmp_bfr, xatr_checkout);
|
||||
byte[] checkout_val = xtn_mgr.Checkout_msg().Fmt(tmp_bfr, tmp_fmtr, xatr_checkout);
|
||||
wtr.Txt_raw(checkout_val);
|
||||
}
|
||||
wtr.Txt(Txt_dot_space);
|
||||
@@ -194,16 +195,18 @@ public class Listing_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
if (xatr_lat >= Xatr_meridian_null || xatr_long >= Xatr_meridian_null) return null; // check that lat and long are valid
|
||||
Xol_msg_itm position_template = xtn_mgr.Position_template();
|
||||
if (position_template == null) return null;
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128().Mkr_rls();
|
||||
byte[] rv = position_template.Fmt(tmp_bfr, xatr_lat, xatr_long);
|
||||
tmp_bfr.Add(Bry__invk_bgn); // "{{"
|
||||
tmp_bfr.Add(rv); // rv is not message, but actually template precursor
|
||||
tmp_bfr.Add(Bry__invk_end); // "}}"
|
||||
Xop_ctx sub_ctx = Xop_ctx.New__sub__reuse_page(ctx);
|
||||
rv = wiki.Parser_mgr().Main().Parse_text_to_html(sub_ctx, tmp_bfr.To_bry_and_clear());
|
||||
Xol_msg_itm position_text = xtn_mgr.Position_text();
|
||||
if (Bry_.Len_eq_0(position_text.Val())) return rv;
|
||||
return position_text.Fmt(tmp_bfr, rv);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
try {
|
||||
byte[] rv = position_template.Fmt(tmp_bfr, tmp_fmtr, xatr_lat, xatr_long);
|
||||
tmp_bfr.Add(Bry__invk_bgn); // "{{"
|
||||
tmp_bfr.Add(rv); // rv is not message, but actually template precursor
|
||||
tmp_bfr.Add(Bry__invk_end); // "}}"
|
||||
Xop_ctx sub_ctx = Xop_ctx.New__sub__reuse_page(ctx);
|
||||
rv = wiki.Parser_mgr().Main().Parse_text_to_html(sub_ctx, tmp_bfr.To_bry_and_clear());
|
||||
Xol_msg_itm position_text = xtn_mgr.Position_text();
|
||||
if (Bry_.Len_eq_0(position_text.Val())) return rv;
|
||||
return position_text.Fmt(tmp_bfr, tmp_fmtr, rv);
|
||||
} finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
private static final int Xatr_meridian_null = 361;
|
||||
public static final byte[]
|
||||
|
||||
@@ -26,19 +26,21 @@ public class Xof_math_html_wtr {
|
||||
Xoae_app app = ctx.App(); Xowe_wiki wiki = ctx.Wiki(); Xoae_page page = ctx.Page();
|
||||
boolean renderer_is_latex = !app.File_mgr().Math_mgr().Renderer_is_mathjax();
|
||||
byte[] math_bry = Bry_.Mid(src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
math_bry = Escape_tex(tmp_bfr, !renderer_is_latex, math_bry);
|
||||
byte[] math_bry_clean = wiki.Html_mgr().Js_cleaner().Clean(wiki, math_bry, 0, math_bry.length); // check for js;
|
||||
if (math_bry_clean != null) math_bry = math_bry_clean; // js found; use clean version; DATE:2013-08-26
|
||||
boolean enabled = app.File_mgr().Math_mgr().Enabled();
|
||||
Xof_math_itm math_itm = ctx.Tmp_mgr().Math_itm();
|
||||
if (renderer_is_latex && app.File_mgr().Math_mgr().Find_itm(math_itm, page.Wiki().Domain_str(), math_bry)) {
|
||||
bfr.Add(Xoh_consts.Img_bgn);
|
||||
bfr.Add_str_u8(math_itm.Png_url().To_http_file_str());
|
||||
bfr.Add(Xoh_consts.__inline_quote);
|
||||
}
|
||||
else
|
||||
Write_for_mathjax(bfr, page, enabled, renderer_is_latex, math_bry, tmp_bfr, math_itm);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
math_bry = Escape_tex(tmp_bfr, !renderer_is_latex, math_bry);
|
||||
byte[] math_bry_clean = wiki.Html_mgr().Js_cleaner().Clean(wiki, math_bry, 0, math_bry.length); // check for js;
|
||||
if (math_bry_clean != null) math_bry = math_bry_clean; // js found; use clean version; DATE:2013-08-26
|
||||
boolean enabled = app.File_mgr().Math_mgr().Enabled();
|
||||
Xof_math_itm math_itm = ctx.Tmp_mgr().Math_itm();
|
||||
if (renderer_is_latex && app.File_mgr().Math_mgr().Find_itm(math_itm, page.Wiki().Domain_str(), math_bry)) {
|
||||
bfr.Add(Xoh_consts.Img_bgn);
|
||||
bfr.Add_str_u8(math_itm.Png_url().To_http_file_str());
|
||||
bfr.Add(Xoh_consts.__inline_quote);
|
||||
}
|
||||
else
|
||||
Write_for_mathjax(bfr, page, enabled, renderer_is_latex, math_bry, tmp_bfr, math_itm);
|
||||
} finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
private void Write_for_mathjax(Bry_bfr bfr, Xoae_page page, boolean enabled, boolean renderer_is_latex, byte[] math_bry, Bry_bfr tmp_bfr, Xof_math_itm math_itm) {
|
||||
int id = page.File_math().Count();
|
||||
|
||||
@@ -57,8 +57,8 @@ public class Pf_func_ {
|
||||
}
|
||||
else if (lhs_len == 0 || rhs_len == 0) // one side is empty String and the other side is String; return false;
|
||||
return false;
|
||||
Number_parser lhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_0();
|
||||
Number_parser rhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_1();
|
||||
Gfo_number_parser lhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_0();
|
||||
Gfo_number_parser rhs_parser = ctx.Tmp_mgr().Pfunc_num_parser_1();
|
||||
lhs_parser.Parse(lhs, 0, lhs_len);
|
||||
if (lhs_parser.Has_err()) return false;
|
||||
rhs_parser.Parse(rhs, 0, rhs_len);
|
||||
@@ -396,9 +396,9 @@ public class Pf_func_ {
|
||||
case Xol_kwd_grp_.Id_pagebanner: return new gplx.xowa.xtns.pagebanners.Pgbnr_func();
|
||||
case Xol_kwd_grp_.Id_new_window_link: return new gplx.xowa.xtns.new_window_links.New_window_link_func();
|
||||
|
||||
case Xol_kwd_grp_.Id_property: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_property();
|
||||
case Xol_kwd_grp_.Id_noexternallanglinks: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_noExternalLangLinks();
|
||||
case Xol_kwd_grp_.Id_wbreponame: return new gplx.xowa.xtns.wdatas.pfuncs.Wdata_pf_wbreponame();
|
||||
case Xol_kwd_grp_.Id_property: return new gplx.xowa.xtns.wbases.pfuncs.Wdata_pf_property();
|
||||
case Xol_kwd_grp_.Id_noexternallanglinks: return new gplx.xowa.xtns.wbases.pfuncs.Wdata_pf_noExternalLangLinks();
|
||||
case Xol_kwd_grp_.Id_wbreponame: return new gplx.xowa.xtns.wbases.pfuncs.Wdata_pf_wbreponame();
|
||||
|
||||
case Xol_kwd_grp_.Id_mapSources_deg2dd: return gplx.xowa.xtns.mapSources.Map_deg2dd_func.Instance;
|
||||
case Xol_kwd_grp_.Id_mapSources_dd2dms: return gplx.xowa.xtns.mapSources.Map_dd2dms_func.Instance;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Pfunc_expr_shunter {
|
||||
private final Btrie_fast_mgr trie = expression_(); private final Btrie_rv trv = new Btrie_rv();
|
||||
private final Val_stack val_stack = new Val_stack();
|
||||
private final Func_tkn_stack prc_stack = new Func_tkn_stack();
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.tmp_();
|
||||
private final Bry_fmtr tmp_fmtr = Bry_fmtr.New__tmp();
|
||||
public Bry_bfr Err() {return err_bfr;} private final Bry_bfr err_bfr = Bry_bfr_.New();
|
||||
public Decimal_adp Err_set(Xop_ctx ctx, int msgId) {return Err_set(ctx, msgId, Bry_.Empty);}
|
||||
public Decimal_adp Err_set(Xop_ctx ctx, int msg_id, byte[] arg) {
|
||||
|
||||
@@ -30,9 +30,11 @@ public class Pfunc_replace extends Pf_func_base {
|
||||
byte[] repl = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 1, Bry_.Empty);
|
||||
byte[] limit_bry = Pf_func_.Eval_arg_or(ctx, src, caller, self, self_args_len, 2, null);
|
||||
int limit = limit_bry == null ? Int_.Max_value : Bry_.To_int_or_neg1(limit_bry);
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
byte[] rv = Bry_.Replace(tmp_bfr, argx, find, repl, 0, argx.length, limit);
|
||||
tmp_bfr.Mkr_rls();
|
||||
bfr.Add(rv);
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b128();
|
||||
try {
|
||||
byte[] rv = Bry_.Replace(tmp_bfr, argx, find, repl, 0, argx.length, limit);
|
||||
bfr.Add(rv);
|
||||
}
|
||||
finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ public class Pft_func_date_int extends Pf_func_base {
|
||||
Xowe_wiki wiki = ctx.Wiki(); Xol_lang_itm lang = ctx.Lang();
|
||||
Pft_func_formatdate_bldr date_fmt_bldr = wiki.Parser_mgr().Date_fmt_bldr();
|
||||
switch (date_tid) {
|
||||
case Date_tid_lcl: date = DateAdp_.Now(); break;
|
||||
case Date_tid_utc: date = DateAdp_.Now().XtoUtc(); break;
|
||||
case Date_tid_lcl: date = Datetime_now.Get(); break;
|
||||
case Date_tid_utc: date = Datetime_now.Get().XtoUtc(); break;
|
||||
case Date_tid_rev: date = ctx.Page().Db().Page().Modified_on(); break;
|
||||
default: throw Err_.new_unhandled(date_tid);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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_date_lcl_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void setup() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
|
||||
@After public void teardown() {Tfds.Now_enabled_n_();}
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void setup() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
|
||||
@After public void teardown() {Datetime_now.Manual_n_();}
|
||||
@Test public void Lcl_year() {fxt.Test_parse_tmpl_str_test("{{LOCALYEAR}}" , "{{test}}", "2012");}
|
||||
@Test public void Lcl_month_int() {fxt.Test_parse_tmpl_str_test("{{LOCALMONTH1}}" , "{{test}}", "1");}
|
||||
@Test public void Lcl_month_int_len2() {fxt.Test_parse_tmpl_str_test("{{LOCALMONTH}}" , "{{test}}", "01");}
|
||||
|
||||
@@ -24,8 +24,8 @@ public class Pft_func_date_name extends Pf_func_base {
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
DateAdp date = DateAdp_.MinValue;
|
||||
switch (date_tid) {
|
||||
case Pft_func_date_int.Date_tid_lcl: date = DateAdp_.Now(); break;
|
||||
case Pft_func_date_int.Date_tid_utc: date = DateAdp_.Now().XtoUtc(); break;
|
||||
case Pft_func_date_int.Date_tid_lcl: date = Datetime_now.Get(); break;
|
||||
case Pft_func_date_int.Date_tid_utc: date = Datetime_now.Get().XtoUtc(); break;
|
||||
case Pft_func_date_int.Date_tid_rev: date = ctx.Page().Db().Page().Modified_on(); break;
|
||||
default: throw Err_.new_unhandled(date_tid);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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_date_utc_tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void setup() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2011, 12, 31, 22, 4, 5, 6));} // ENV:Assumes Eastern Standard Time (-5)
|
||||
@After public void teardown() {Tfds.Now_enabled_n_();}
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void setup() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2011, 12, 31, 22, 4, 5, 6));} // ENV:Assumes Eastern Standard Time (-5)
|
||||
@After public void teardown() {Datetime_now.Manual_n_();}
|
||||
@Test public void Utc_year() {fxt.Test_parse_tmpl_str_test("{{CURRENTYEAR}}" , "{{test}}", "2012");}
|
||||
@Test public void Utc_month_int() {fxt.Test_parse_tmpl_str_test("{{CURRENTMONTH1}}" , "{{test}}", "1");}
|
||||
@Test public void Utc_month_int_len2() {fxt.Test_parse_tmpl_str_test("{{CURRENTMONTH}}" , "{{test}}", "01");}
|
||||
|
||||
@@ -35,7 +35,10 @@ public class Pft_func_formatdate extends Pf_func_base {
|
||||
bfr.Add(date_bry);
|
||||
return;
|
||||
}
|
||||
DateAdp date = Pft_func_time.ParseDate(date_bry, false, ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls());
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
DateAdp date = null;
|
||||
try {date = Pft_func_time.ParseDate(date_bry, false, tmp_bfr);}
|
||||
finally {tmp_bfr.Mkr_rls();}
|
||||
if (date == null) {bfr.Add(date_bry); return;} // date not parseable; return self; DATE:2014-04-13
|
||||
ctx.Wiki().Parser_mgr().Date_fmt_bldr().Format(bfr, ctx.Wiki(), ctx.Lang(), date, (Pft_fmt_itm[])o);
|
||||
}
|
||||
|
||||
@@ -35,13 +35,16 @@ public class Pft_func_formatdate_bldr {
|
||||
chained_fmt = fmt_itm;
|
||||
else {
|
||||
if (chained_fmt != null) {
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
synchronized (tmp_bfr) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
try {
|
||||
fmt_itm.Fmt(tmp_bfr, wiki, lang, date, this);
|
||||
chained_fmt.Fmt(tmp_bfr, wiki, lang, date, this);
|
||||
bfr.Add(tmp_bfr.To_bry_and_rls());
|
||||
bfr.Add(tmp_bfr.To_bry_and_clear());
|
||||
chained_fmt = null;
|
||||
}
|
||||
finally {
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
}
|
||||
else
|
||||
fmt_itm.Fmt(bfr, wiki, lang, date, this);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Pft_func_time extends Pf_func_base {
|
||||
}
|
||||
}
|
||||
public static DateAdp ParseDate(byte[] date, boolean utc, Bry_bfr error_bfr) {
|
||||
if (date == Bry_.Empty) return utc ? DateAdp_.Now().XtoUtc() : DateAdp_.Now();
|
||||
if (date == Bry_.Empty) return utc ? Datetime_now.Get().XtoUtc() : Datetime_now.Get();
|
||||
try {
|
||||
DateAdp rv = new Pxd_parser().Parse(date, error_bfr);
|
||||
return rv;
|
||||
|
||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
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 final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {Tfds.Now_enabled_n_();}
|
||||
@Before public void init() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {Datetime_now.Manual_n_();}
|
||||
@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");}
|
||||
@@ -68,7 +68,7 @@ public class Pft_func_time__basic__tst {
|
||||
@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 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 Datetime_now.Get() 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
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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 final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));} private final 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}}" , "<strong class=\"error\">Invalid month: 14</strong>");} // mdy is invalid; DATE:2014-09-23
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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__uncommon__tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset(); Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
|
||||
@After public void term() {Tfds.Now_enabled_n_();}
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset(); Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));}
|
||||
@After public void term() {Datetime_now.Manual_n_();}
|
||||
@Test public void Year_5_digits() {fxt.Test_parse_tmpl_str_test("{{#time:Y-m-d|00123-4-5}}" , "{{test}}" , "2003-04-05");} // PURPOSE: emulate PHP's incorrect date parsing; EX:ca.w:Nicolau_de_Mira; DATE:2014-04-17
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ class Pft_func_time_foreign_fxt {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
public void Clear() {
|
||||
fxt.Reset();
|
||||
Tfds.Now_set(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));
|
||||
Datetime_now.Manual_(DateAdp_.new_(2012, 1, 2, 3, 4, 5, 6));
|
||||
}
|
||||
public void Term() {
|
||||
Tfds.Now_enabled_n_();
|
||||
Datetime_now.Manual_n_();
|
||||
}
|
||||
public Pft_func_time_foreign_fxt Init_msg(String key, String val) {
|
||||
Xol_msg_itm msg = fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_u8(key));
|
||||
|
||||
@@ -89,7 +89,7 @@ class DateAdpBldr {
|
||||
return date;
|
||||
}
|
||||
else
|
||||
return DateAdp_.Now(); // not dirtied; default to now;
|
||||
return Datetime_now.Get(); // not dirtied; default to now;
|
||||
}
|
||||
public DateAdpBldr Date_(DateAdp v) {date = v; return this;} DateAdp date = null;
|
||||
public void Seg_set(int idx, int val) {
|
||||
|
||||
@@ -188,7 +188,7 @@ class Pxd_itm_unit extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
}
|
||||
@Override public boolean Time_ini(DateAdpBldr bldr) {
|
||||
DateAdp cur = bldr.Date();
|
||||
if (cur == null) cur = DateAdp_.Now();
|
||||
if (cur == null) cur = Datetime_now.Get();
|
||||
int val = seg_val * seg_multiple;
|
||||
switch (this.Seg_idx()) {
|
||||
case DateAdp_.SegIdx_second: cur = cur.Add_second(val); break;
|
||||
@@ -256,7 +256,7 @@ class Pxd_itm_day_relative extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
public Pxd_itm MakeNew(int ary_idx) {return new Pxd_itm_day_relative(adj, ary_idx);}
|
||||
@Override public boolean Eval(Pxd_parser state) {return true;}
|
||||
@Override public boolean Time_ini(DateAdpBldr bldr) {
|
||||
DateAdp date = DateAdp_.Now();
|
||||
DateAdp date = Datetime_now.Get();
|
||||
if (adj != 0) date = date.Add_day(adj);
|
||||
bldr.Seg_set(DateAdp_.SegIdx_year , date.Year());
|
||||
bldr.Seg_set(DateAdp_.SegIdx_month , date.Month());
|
||||
@@ -278,7 +278,7 @@ class Pxd_itm_time_relative extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
public Pxd_itm MakeNew(int ary_idx) {return new Pxd_itm_time_relative(ary_idx);}
|
||||
@Override public boolean Eval(Pxd_parser state) {return true;}
|
||||
@Override public boolean Time_ini(DateAdpBldr bldr) {
|
||||
DateAdp date = DateAdp_.Now();
|
||||
DateAdp date = Datetime_now.Get();
|
||||
bldr.Seg_set(DateAdp_.SegIdx_year , date.Year());
|
||||
bldr.Seg_set(DateAdp_.SegIdx_month , date.Month());
|
||||
bldr.Seg_set(DateAdp_.SegIdx_day , date.Day());
|
||||
@@ -347,7 +347,7 @@ class Pxd_itm_dow_name extends Pxd_itm_base implements Pxd_itm_prototype {
|
||||
public Pxd_itm MakeNew(int ary_idx) {return new Pxd_itm_dow_name(ary_idx, dow_name, dow_idx);}
|
||||
@Override public boolean Eval(Pxd_parser state) {return true;}
|
||||
@Override public boolean Time_ini(DateAdpBldr bldr) {
|
||||
DateAdp now = DateAdp_.Now();
|
||||
DateAdp now = Datetime_now.Get();
|
||||
int adj = dow_idx - now.DayOfWeek(); // adj = requested_dow - current_dow; EX: requesting Friday, and today is Wednesday; adj = 2 (4 - 2); DATE:2014-05-02
|
||||
if (adj < 0) adj += 7; // requested_down is before current_dow; add 7 to get the next day
|
||||
bldr.Date_(bldr.Date().Add_day(adj));
|
||||
|
||||
@@ -145,7 +145,7 @@ class Pxd_parser {
|
||||
return DateAdp_.MinValue;
|
||||
}
|
||||
}
|
||||
DateAdp now = DateAdp_.Now();
|
||||
DateAdp now = Datetime_now.Get();
|
||||
DateAdpBldr bldr = new DateAdpBldr(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0);
|
||||
for (int i = 0; i < tkns_len; i++) {
|
||||
Pxd_itm itm = (Pxd_itm)tkns[i];
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.xowa.xtns.pfuncs.times; import gplx.*; import gplx.xowa.*; import g
|
||||
import org.junit.*;
|
||||
public class Pxd_parser_tst {
|
||||
Bry_bfr bfr = Bry_bfr_.New_w_size(16); Pxd_parser parser = new Pxd_parser();
|
||||
@Before public void init() {Tfds.Now_enabled_y_(); Tfds.Now_set(test_date);} DateAdp test_date = DateAdp_.parse_fmt("2012-02-27", "yyyy-MM-dd");
|
||||
@After public void teardown() {Tfds.Now_enabled_n_();}
|
||||
@Before public void init() {Datetime_now.Manual_y_(); Datetime_now.Manual_(test_date);} DateAdp test_date = DateAdp_.parse_fmt("2012-02-27", "yyyy-MM-dd");
|
||||
@After public void teardown() {Datetime_now.Manual_n_();}
|
||||
@Test public void Month_name_0__day__year() {tst_date_("Mar 2 2001" , "2001-03-02");} // y:Mar-02-2001;Mar.02.2001;Mar 02, 2001 n:Mar/02/2001;Feb,05,2011
|
||||
@Test public void Month_name_0__day__year__bad_day() {tst_date_("Mar 32 2001" , "Invalid day: 32");}
|
||||
@Test public void Month_name_0__day__year__bad_year() {tst_date_("Mar 3 999" , "0999-03-03");}
|
||||
|
||||
@@ -35,7 +35,9 @@ public class Pfunc_anchorencode extends Pf_func_base { // EX: {{anchorencode:a b
|
||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
|
||||
if (anchor_ctx == null) Func_init(ctx);
|
||||
byte[] val_ary = Eval_argx(ctx, src, caller, self); if (val_ary == Bry_.Empty) return;
|
||||
Anchor_encode(val_ary, bfr, ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls());
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
try {Anchor_encode(val_ary, bfr, tmp_bfr);}
|
||||
finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
public static void Anchor_encode(byte[] src, Bry_bfr bfr, Bry_bfr tmp_bfr) {
|
||||
Xop_root_tkn root = anchor_ctx.Tkn_mkr().Root(src);
|
||||
|
||||
@@ -34,7 +34,9 @@ public class Pfunc_rel2abs extends Pf_func_base {
|
||||
byte[] qry = Eval_argx(ctx, src, caller, self);
|
||||
byte[] orig = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self.Args_len(), 0);
|
||||
if (orig.length == 0) orig = ctx.Page().Ttl().Full_txt_w_ttl_case();
|
||||
bfr.Add(Rel2abs(ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls(), qry, orig));
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
try {bfr.Add(Rel2abs(tmp_bfr, qry, orig));}
|
||||
finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
public static boolean Rel2abs_ttl(byte[] ttl, int bgn, int end) {
|
||||
int last = end - 1;
|
||||
|
||||
@@ -38,19 +38,21 @@ public class Pfunc_urlfunc extends Pf_func_base { // EX: {{lc:A}} -> a
|
||||
else
|
||||
trg.Add(gplx.core.net.Gfo_protocol_itm.Bry_relative); // "//"
|
||||
trg.Add(xwiki.Domain_bry()) // "commons.wikimedia.org"
|
||||
.Add(Xoh_href_.Bry__wiki) // "/wiki/"
|
||||
.Add(Xoh_href_.Bry__wiki) // "/wiki/"
|
||||
.Add_mid(ttl_ary, xwiki.Key_bry().length + 1, ttl_ary.length); // "A#b?c=d"; +1 for colon after "commons:"; NOTE: ugly way of getting rest of url, but ttl currently does not have Full_wo_wiki
|
||||
}
|
||||
else {
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
switch (tid) {
|
||||
case Tid_local: tmp_bfr.Add(ctx.Wiki().Props().ArticlePath());break;
|
||||
case Tid_full: tmp_bfr.Add(Bry_relative_url).Add(ctx.Wiki().Props().Server_name()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
case Tid_canonical: tmp_bfr.Add(ctx.Wiki().Props().Server()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
tmp_bfr.Add(ttl_ary);
|
||||
trg.Add_bfr_and_clear(tmp_bfr);
|
||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
switch (tid) {
|
||||
case Tid_local: tmp_bfr.Add(ctx.Wiki().Props().ArticlePath());break;
|
||||
case Tid_full: tmp_bfr.Add(Bry_relative_url).Add(ctx.Wiki().Props().Server_name()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
case Tid_canonical: tmp_bfr.Add(ctx.Wiki().Props().Server()).Add(ctx.Wiki().Props().ArticlePath()); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
tmp_bfr.Add(ttl_ary);
|
||||
trg.Add_bfr_and_clear(tmp_bfr);
|
||||
} finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
if (qry_arg != Bry_.Empty) trg.Add_byte(Byte_ascii.Question).Add(qry_arg);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class Pfunc_pagesincategory_tstr {
|
||||
public void Init_category_counts(String category_title, int pages, int subcs, int files) {
|
||||
int page_id = 1;
|
||||
page_tbl.Insert_bgn();
|
||||
page_tbl.Insert_cmd_by_batch(page_id, Xow_ns_.Tid__category, Bry_.new_u8(category_title), Bool_.N, DateAdp_.Now(), 1, 1, 1, 1);
|
||||
page_tbl.Insert_cmd_by_batch(page_id, Xow_ns_.Tid__category, Bry_.new_u8(category_title), Bool_.N, Datetime_now.Get(), 1, 1, 1, 1);
|
||||
page_tbl.Insert_end();
|
||||
cat_core_tbl.Insert_bgn();
|
||||
cat_core_tbl.Insert_cmd_by_batch(page_id, pages, subcs, files, Byte_.Zero, 1);
|
||||
|
||||
@@ -39,43 +39,45 @@ public class Poem_nde implements Xox_xnde {
|
||||
bfr.Add(Div_poem_end);
|
||||
}
|
||||
private static byte[] Parse_lines(Bry_bfr_mkr bfr_mkr, byte[] src, int src_bgn, int src_end) {
|
||||
Bry_bfr bfr = bfr_mkr.Get_k004().Mkr_rls();
|
||||
int line_bgn = src_bgn; boolean line_is_1st = true;
|
||||
while (line_bgn < src_end) { // iterate over each \n
|
||||
boolean indent_enabled = false;
|
||||
if (line_is_1st) line_is_1st = false;
|
||||
else {
|
||||
int line_end_w_br = line_bgn + Xowa_br_mark.length;
|
||||
if ( line_end_w_br < src_end // check for out of bounds; PAGE:en.s:The Hebrew Nation did not write it; DATE:2015-01-31
|
||||
&& Bry_.Match(src, line_bgn, line_end_w_br, Xowa_br_mark)) // "<br/>\n" already inserted by XOWA; do not insert again; DATE:2014-10-20
|
||||
bfr.Add_byte_nl();
|
||||
else
|
||||
bfr.Add(Gfh_tag_.Br_inl).Add_byte_nl().Add(Xowa_br_mark); // add "<br/>\n" unless 1st line; EX: "<poem>\n\s" should not add leading "<br/>\n"
|
||||
}
|
||||
switch (src[line_bgn]) {
|
||||
case Byte_ascii.Space: // "\n\s" -> "\n "
|
||||
int space_end = Bry_find_.Find_fwd_while(src, line_bgn, src_end, Byte_ascii.Space);
|
||||
int space_count = space_end - line_bgn;
|
||||
line_bgn = space_end;
|
||||
for (int i = 0; i < space_count; ++i)
|
||||
bfr.Add(Gfh_entity_.Nbsp_num_bry);
|
||||
break;
|
||||
case Byte_ascii.Colon: { // "\n:" -> <span class='mw-poem-indented' style='display: inline-block; margin-left: #em;'>
|
||||
int colon_end = Bry_find_.Find_fwd_while(src, line_bgn, src_end, Byte_ascii.Colon);
|
||||
int colon_count = colon_end - line_bgn;
|
||||
line_bgn = colon_end;
|
||||
bfr.Add(Indent_bgn).Add_int_variable(colon_count).Add(Indent_end); // add <span class='mw-poem-indented' style='display: inline-block; margin-left: #em;'>
|
||||
indent_enabled = true;
|
||||
break;
|
||||
Bry_bfr bfr = bfr_mkr.Get_k004();
|
||||
try {
|
||||
int line_bgn = src_bgn; boolean line_is_1st = true;
|
||||
while (line_bgn < src_end) { // iterate over each \n
|
||||
boolean indent_enabled = false;
|
||||
if (line_is_1st) line_is_1st = false;
|
||||
else {
|
||||
int line_end_w_br = line_bgn + Xowa_br_mark.length;
|
||||
if ( line_end_w_br < src_end // check for out of bounds; PAGE:en.s:The Hebrew Nation did not write it; DATE:2015-01-31
|
||||
&& Bry_.Match(src, line_bgn, line_end_w_br, Xowa_br_mark)) // "<br/>\n" already inserted by XOWA; do not insert again; DATE:2014-10-20
|
||||
bfr.Add_byte_nl();
|
||||
else
|
||||
bfr.Add(Gfh_tag_.Br_inl).Add_byte_nl().Add(Xowa_br_mark); // add "<br/>\n" unless 1st line; EX: "<poem>\n\s" should not add leading "<br/>\n"
|
||||
}
|
||||
switch (src[line_bgn]) {
|
||||
case Byte_ascii.Space: // "\n\s" -> "\n "
|
||||
int space_end = Bry_find_.Find_fwd_while(src, line_bgn, src_end, Byte_ascii.Space);
|
||||
int space_count = space_end - line_bgn;
|
||||
line_bgn = space_end;
|
||||
for (int i = 0; i < space_count; ++i)
|
||||
bfr.Add(Gfh_entity_.Nbsp_num_bry);
|
||||
break;
|
||||
case Byte_ascii.Colon: { // "\n:" -> <span class='mw-poem-indented' style='display: inline-block; margin-left: #em;'>
|
||||
int colon_end = Bry_find_.Find_fwd_while(src, line_bgn, src_end, Byte_ascii.Colon);
|
||||
int colon_count = colon_end - line_bgn;
|
||||
line_bgn = colon_end;
|
||||
bfr.Add(Indent_bgn).Add_int_variable(colon_count).Add(Indent_end); // add <span class='mw-poem-indented' style='display: inline-block; margin-left: #em;'>
|
||||
indent_enabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int line_end = Bry_find_.Find_fwd(src, Byte_ascii.Nl, line_bgn, src_end); // find end "\n"
|
||||
if (line_end == Bry_find_.Not_found) line_end = src_end; // no "\n"; use eos;
|
||||
bfr.Add_mid(src, line_bgn, line_end); // add everything from line_bgn to line_end
|
||||
if (indent_enabled) bfr.Add(Gfh_tag_.Span_rhs); // if "\n:", add </span>
|
||||
line_bgn = line_end + 1; // +1 to skip over end "\n"
|
||||
}
|
||||
int line_end = Bry_find_.Find_fwd(src, Byte_ascii.Nl, line_bgn, src_end); // find end "\n"
|
||||
if (line_end == Bry_find_.Not_found) line_end = src_end; // no "\n"; use eos;
|
||||
bfr.Add_mid(src, line_bgn, line_end); // add everything from line_bgn to line_end
|
||||
if (indent_enabled) bfr.Add(Gfh_tag_.Span_rhs); // if "\n:", add </span>
|
||||
line_bgn = line_end + 1; // +1 to skip over end "\n"
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
return bfr.To_bry_and_clear();
|
||||
} finally {bfr.Mkr_rls();}
|
||||
}
|
||||
private static byte[]
|
||||
Div_poem_bgn = Bry_.new_a7("<div class=\"poem\">\n<p>\n") // NOTE: always enclose in <p>; MW does this implicitly in its modified parse; DATE:2014-04-27
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
Bry_bfr full_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
Hash_adp_bry lst_page_regy = ctx.Lst_page_regy(); if (lst_page_regy == null) lst_page_regy = Hash_adp_bry.cs(); // SEE:NOTE:page_regy; DATE:2014-01-01
|
||||
page.Html_data().Indicators().Enabled_(Bool_.N); // disable <indicator> b/c <page> should not add to current page; PAGE:en.s:The_Parochial_System_(Wilberforce,_1838); DATE:2015-04-29
|
||||
byte[] page_bry = Bld_wikitext(full_bfr, lst_page_regy);
|
||||
byte[] page_bry = Bld_wikitext(full_bfr, wiki.Parser_mgr().Pp_num_parser(), lst_page_regy);
|
||||
if (page_bry != null)
|
||||
xtn_root = Bld_root_nde(full_bfr, lst_page_regy, page_bry); // NOTE: this effectively reparses page twice; needed b/c of "if {| : ; # *, auto add new_line" which can build different tokens
|
||||
page.Pages_recursed_(false);
|
||||
@@ -98,7 +98,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
bgn_sect_bry = end_sect_bry = null;
|
||||
return true;
|
||||
}
|
||||
private byte[] Bld_wikitext(Bry_bfr full_bfr, Hash_adp_bry lst_page_regy) {
|
||||
private byte[] Bld_wikitext(Bry_bfr full_bfr, Gfo_number_parser num_parser, Hash_adp_bry lst_page_regy) {
|
||||
Pp_index_page index_page = Pp_index_parser.Parse(wiki, ctx, index_ttl, ns_page_id);
|
||||
int index_page_ttls_len = index_page.Page_ttls().Count();
|
||||
byte[] rv = Bry_.Empty;
|
||||
@@ -107,7 +107,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
if ( index_page.Pagelist_xndes().Count() > 0 // pagelist exists; don't get from args
|
||||
|| index_page_ttls_len == 0 // no [[Page:]] in [[Index:]]
|
||||
) // NOTE: this simulates MW's if (empty($links)); REF.MW:ProofreadPageRenderer.php|renderPages
|
||||
ttls = Get_ttls_from_xnde_args();
|
||||
ttls = Get_ttls_from_xnde_args(num_parser);
|
||||
else {
|
||||
Int_obj_ref bgn_page_ref = Int_obj_ref.New_neg1(), end_page_ref = Int_obj_ref.New_neg1();
|
||||
ttls = index_page.Get_ttls_rng(wiki, ns_page_id, bgn_page_bry, end_page_bry, bgn_page_ref, end_page_ref);
|
||||
@@ -149,15 +149,6 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static final byte[]
|
||||
Bry_tmpl = Bry_.new_a7("{{:MediaWiki:Proofreadpage_header_template")
|
||||
, Bry_value = Bry_.new_a7("|value=")
|
||||
, Bry_toc_cur = Bry_.new_a7("|current=")
|
||||
, Bry_toc_prv = Bry_.new_a7("|prev=")
|
||||
, Bry_toc_nxt = Bry_.new_a7("|next=")
|
||||
, Bry_page_bgn = Bry_.new_a7("|from=")
|
||||
, Bry_page_end = Bry_.new_a7("|to=")
|
||||
;
|
||||
private byte[] Bld_wikitext_for_header(Bry_bfr full_bfr, Pp_index_page index_page, byte[] rv) {
|
||||
List_adp main_lnkis = index_page.Main_lnkis();
|
||||
int main_lnkis_len = main_lnkis.Count();
|
||||
@@ -210,12 +201,12 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
full_bfr.Add(rv);
|
||||
return full_bfr.To_bry_and_clear();
|
||||
}
|
||||
private Xoa_ttl[] Get_ttls_from_xnde_args() {
|
||||
private Xoa_ttl[] Get_ttls_from_xnde_args(Gfo_number_parser num_parser) {
|
||||
if (!Chk_step()) return Ttls_null;
|
||||
List_adp list = List_adp_.New();
|
||||
list = Get_ttls_from_xnde_args__include(list); if (list == null) return Ttls_null;
|
||||
list = Get_ttls_from_xnde_args__rng(list); if (list == null) return Ttls_null;
|
||||
list = Get_ttls_from_xnde_args__exclude(list); if (list == null) return Ttls_null;
|
||||
list = Get_ttls_from_xnde_args__include(list); if (list == null) return Ttls_null;
|
||||
list = Get_ttls_from_xnde_args__rng(num_parser, list); if (list == null) return Ttls_null;
|
||||
list = Get_ttls_from_xnde_args__exclude(list); if (list == null) return Ttls_null;
|
||||
if (include != null || exclude != null) // sort if include / exclude specified; will skip sort if only range specified
|
||||
list.Sort();
|
||||
return Get_ttls_from_xnde_args__ttls(list);
|
||||
@@ -226,10 +217,10 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
if (include_pages == null) return list; // ignore invalid include; DATE:2014-02-22
|
||||
int include_pages_len = include_pages.length;
|
||||
for (int i = 0; i < include_pages_len; i++)
|
||||
list.Add(Int_obj_val.new_(include_pages[i]));
|
||||
list.Add(new Int_obj_val(include_pages[i]));
|
||||
return list;
|
||||
}
|
||||
private List_adp Get_ttls_from_xnde_args__rng(List_adp list) {
|
||||
private List_adp Get_ttls_from_xnde_args__rng(Gfo_number_parser num_parser, List_adp list) {
|
||||
if (Bry_.Len_eq_0(bgn_page_bry) && Bry_.Len_eq_0(end_page_bry)) return list; // from and to are blank; exit early
|
||||
bgn_page_int = 0; // NOTE: default to 0 (1st page)
|
||||
if (Bry_.Len_gt_0(bgn_page_bry)) {
|
||||
@@ -258,7 +249,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
return null;
|
||||
}
|
||||
for (int i = bgn_page_int; i <= end_page_int; i++)
|
||||
list.Add(Int_obj_val.new_(i));
|
||||
list.Add(new Int_obj_val(i));
|
||||
return list;
|
||||
}
|
||||
private int Get_max_page_idx(Xowe_wiki wiki, Xoa_ttl index_ttl) {
|
||||
@@ -283,7 +274,7 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
Hash_adp exclude_pages_hash = Hash_adp_.New();
|
||||
int exclude_pages_len = exclude_pages.length;
|
||||
for (int i = 0; i < exclude_pages_len; i++) {
|
||||
Int_obj_val exclude_page = Int_obj_val.new_(exclude_pages[i]);
|
||||
Int_obj_val exclude_page = new Int_obj_val(exclude_pages[i]);
|
||||
if (!exclude_pages_hash.Has(exclude_page))
|
||||
exclude_pages_hash.Add(exclude_page, exclude_page);
|
||||
}
|
||||
@@ -372,6 +363,23 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
tmp_parser.Parse_text_to_wdom(rv, tmp_ctx, tmp_ctx.Tkn_mkr(), wikitext, Xop_parser_.Doc_bgn_bos);
|
||||
return rv;
|
||||
}
|
||||
private String Fail_msg_suffix() {
|
||||
String excerpt = Bry_fmtr.Escape_tilde(String_.new_u8(Bry_.Mid_by_len_safe(src, xnde_tkn.Src_bgn(), 32)));
|
||||
return String_.Format(" ttl={0} src={1}", String_.new_u8(cur_page_ttl.Full_db()), excerpt);
|
||||
}
|
||||
private String Fail_msg_basic(String msg) {return msg + ";" + Fail_msg_suffix();}
|
||||
private String Fail_msg_custom(String fmt, Object... args) {return String_.Format(fmt, args) + Fail_msg_suffix();}
|
||||
private boolean Fail_msg(String msg) {
|
||||
xtn_literal = true;
|
||||
usr_dlg.Warn_many("", "", String_.Replace(Fail_msg_basic(msg), "\n", ""));
|
||||
return false;
|
||||
}
|
||||
private boolean Fail_args(String fmt, Object... args) {
|
||||
xtn_literal = true;
|
||||
usr_dlg.Warn_many("", "", String_.Replace(Fail_msg_custom(fmt, args), "\n", ""));
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Hash_adp_bry xatrs_hash = Hash_adp_bry.ci_a7() // NOTE: these do not seem to be i18n'd; no ProofreadPage.magic.php; ProofreadPage.i18n.php only has messages; ProofreadPage.body.php refers to names literally
|
||||
.Add_str_obj("index" , Byte_obj_val.new_(Pp_pages_nde.Xatr_index_ttl))
|
||||
.Add_str_obj("from" , Byte_obj_val.new_(Pp_pages_nde.Xatr_bgn_page))
|
||||
@@ -402,24 +410,16 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
|
||||
, Xatr_toc_prv = 11
|
||||
, Xatr_toc_nxt = 12
|
||||
;
|
||||
private static final byte[]
|
||||
Bry_tmpl = Bry_.new_a7("{{:MediaWiki:Proofreadpage_header_template")
|
||||
, Bry_value = Bry_.new_a7("|value=")
|
||||
, Bry_toc_cur = Bry_.new_a7("|current=")
|
||||
, Bry_toc_prv = Bry_.new_a7("|prev=")
|
||||
, Bry_toc_nxt = Bry_.new_a7("|next=")
|
||||
, Bry_page_bgn = Bry_.new_a7("|from=")
|
||||
, Bry_page_end = Bry_.new_a7("|to=")
|
||||
;
|
||||
public static final Xoa_ttl[] Ttls_null = null;
|
||||
private static final Number_parser num_parser = new Number_parser().Ignore_space_at_end_y_(); // ignore space at end; PAGE:en.s:1911_Encyclop<6F>dia_Britannica/Boissier,_Marie_Louis_Antoine_Gaston DATE:2015-04-29
|
||||
private String Fail_msg_suffix() {
|
||||
String excerpt = Bry_fmtr.Escape_tilde(String_.new_u8(Bry_.Mid_by_len_safe(src, xnde_tkn.Src_bgn(), 32)));
|
||||
return String_.Format(" ttl={0} src={1}", String_.new_u8(cur_page_ttl.Full_db()), excerpt);
|
||||
}
|
||||
private String Fail_msg_basic(String msg) {return msg + ";" + Fail_msg_suffix();}
|
||||
private String Fail_msg_custom(String fmt, Object... args) {return String_.Format(fmt, args) + Fail_msg_suffix();}
|
||||
private boolean Fail_msg(String msg) {
|
||||
xtn_literal = true;
|
||||
usr_dlg.Warn_many("", "", String_.Replace(Fail_msg_basic(msg), "\n", ""));
|
||||
return false;
|
||||
}
|
||||
private boolean Fail_args(String fmt, Object... args) {
|
||||
xtn_literal = true;
|
||||
usr_dlg.Warn_many("", "", String_.Replace(Fail_msg_custom(fmt, args), "\n", ""));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
NOTE:page_regy
|
||||
|
||||
@@ -163,11 +163,16 @@ public class Scrib_core {
|
||||
this.frame_parent = parent_frame; this.frame_current = current_frame;
|
||||
}
|
||||
public void Invoke(Xowe_wiki wiki, Xop_ctx ctx, byte[] src, Xot_invk parent_frame, Xot_invk current_frame, Bry_bfr bfr, byte[] mod_name, byte[] mod_text, byte[] fnc_name) {
|
||||
// save current values for restoring later
|
||||
Xot_invk old_frame_parent = this.frame_parent; Xot_invk old_frame_current = this.frame_current;
|
||||
byte[] old_src = cur_src;
|
||||
|
||||
// init
|
||||
this.wiki = wiki; this.ctx = ctx; this.cur_src = src;
|
||||
lib_mw.Invoke_bgn(wiki, ctx, src);
|
||||
Xot_invk old_frame_parent = this.frame_parent; Xot_invk old_frame_current = this.frame_current;
|
||||
this.frame_parent = parent_frame; this.frame_current = current_frame;
|
||||
parent_frame.Frame_tid_(Scrib_frame_.Tid_parent); current_frame.Frame_tid_(Scrib_frame_.Tid_current);
|
||||
|
||||
try {
|
||||
Scrib_lua_mod mod = Mods_get_or_new(mod_name, mod_text);
|
||||
Keyval[] func_args = Scrib_kv_utl_.base1_many_(mod.Init_chunk_func(), String_.new_u8(fnc_name));
|
||||
@@ -188,6 +193,7 @@ public class Scrib_core {
|
||||
lib_mw.Invoke_end();
|
||||
parent_frame.Frame_tid_(Scrib_frame_.Tid_null); current_frame.Frame_tid_(Scrib_frame_.Tid_null);
|
||||
this.frame_parent = old_frame_parent; this.frame_current = old_frame_current; // NOTE: reset template frame; PAGE:en.w:Constantine_the_Great {{Christianity}}; DATE:2014-06-26
|
||||
this.cur_src = old_src;
|
||||
frame_created_list.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,12 @@ public class Scrib_kv_utl_ {
|
||||
try {return (Keyval[])ary[idx].Val();}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "scrib", "cast as Keyval[] failed", "ary", Keyval_.Ary_to_str(ary));}
|
||||
}
|
||||
public static Object Get_sub_by_key_or_null(Keyval[] ary, String key) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval sub = ary[i];
|
||||
if (String_.Eq(key, sub.Key())) return sub.Val();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,12 @@ public class Luaj_server implements Scrib_server {
|
||||
this.func_recv = func_recv;
|
||||
this.func_dbg = func_dbg;
|
||||
}
|
||||
private Globals luaj_globals;
|
||||
public Globals Luaj_globals() {return luaj_globals;} private Globals luaj_globals;
|
||||
public DebugLib Luaj_dbg() {return luaj_dbg;} private DebugLib luaj_dbg;
|
||||
public void Init(String... init_args) {
|
||||
luaj_dbg = new DebugLib(); // NOTE: needed for getfenv
|
||||
luaj_globals = JsePlatform.standardGlobals();
|
||||
luaj_globals.load(new DebugLib());
|
||||
luaj_globals.load(luaj_dbg);
|
||||
luaj_globals.load(new MWClient(luaj_globals, func_recv));
|
||||
luaj_globals.set("dbg", func_dbg);
|
||||
String root_str = init_args[2];
|
||||
|
||||
@@ -151,8 +151,10 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
private boolean Case_1st(Scrib_proc_args args, Scrib_proc_rslt rslt, boolean upper) {
|
||||
Xol_lang_itm lang = lang_(args);
|
||||
byte[] word = args.Pull_bry(1);
|
||||
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b128().Mkr_rls();
|
||||
return rslt.Init_obj(lang.Case_mgr().Case_build_1st(bfr, upper, word, 0, word.length));
|
||||
Bry_bfr bfr = core.Wiki().Utl__bfr_mkr().Get_b128();
|
||||
try {
|
||||
return rslt.Init_obj(lang.Case_mgr().Case_build_1st(bfr, upper, word, 0, word.length));
|
||||
} finally {bfr.Mkr_rls();}
|
||||
}
|
||||
public boolean Lc(Scrib_proc_args args, Scrib_proc_rslt rslt) {return Case_all(args, rslt, Bool_.N);}
|
||||
public boolean Uc(Scrib_proc_args args, Scrib_proc_rslt rslt) {return Case_all(args, rslt, Bool_.Y);}
|
||||
@@ -187,7 +189,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
Pft_fmt_itm[] fmt_ary = Pft_fmt_itm_.Parse(core.Ctx(), fmt_bry);
|
||||
DateAdp date = null;
|
||||
if (Bry_.Len_eq_0(date_bry))
|
||||
date = DateAdp_.Now();
|
||||
date = Datetime_now.Get();
|
||||
else {
|
||||
if (date_bry[0] == Byte_ascii.Plus) { // detect wikidata-style dates; EX: +00000002010-05-01T00:00:00Z; PAGE:en.w:Mountain_Province; DATE:2015-07-29
|
||||
int date_bry_len = date_bry.length;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class Scrib_lib_language_tst {
|
||||
}
|
||||
@Test public void FormatDate() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "2013-03-17", false), "2013-03-17");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d"), DateAdp_.Now().XtoStr_fmt_yyyy_MM_dd()); // empty date should default to today;
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d"), Datetime_now.Get().XtoStr_fmt_yyyy_MM_dd()); // empty date should default to today;
|
||||
}
|
||||
@Test public void FormatDate__ymd_12() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "201603160102", false), "2016-03-16"); // handle long numeric date (12 digits); PAGE:en.w:Boron; DATE:2015-07-29
|
||||
@@ -82,11 +82,11 @@ public class Scrib_lib_language_tst {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", "+00000002010-05-01T00:00:00Z", false), "2010-05-01"); // handle Wikidata style dates; PAGE:en.w:Mountain_Province; DATE:2015-07-29
|
||||
}
|
||||
@Test public void FormatDate_date_omitted() { // PURPOSE: some calls skip the date; retrieve arg_4 by int; EX: pl.w:L._Frank_Baum
|
||||
Tfds.Now_enabled_y_();
|
||||
Tfds.Now_set(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
|
||||
Datetime_now.Manual_y_();
|
||||
Datetime_now.Manual_(DateAdp_.new_(2013, 12, 19, 1, 2, 3, 4));
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Keyval_.Ary(Keyval_.int_(1, "en"), Keyval_.int_(2, "Y-m-d"), Keyval_.int_(4, false)), "2013-12-19");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_formatDate, Object_.Ary("en", "Y-m-d", ""), "2013-12-19");// PURPOSE: '' should return today, not fail; EX: th.w:สถานีรถไฟตรัง
|
||||
Tfds.Now_enabled_n_();
|
||||
Datetime_now.Manual_n_();
|
||||
}
|
||||
@Test public void Lc() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_language.Invk_lc, Object_.Ary("en", "ABC"), "abc");
|
||||
|
||||
@@ -268,7 +268,7 @@ public class Scrib_lib_mw implements Scrib_lib {
|
||||
bfr.Mkr_rls();
|
||||
return rslt.Init_obj(bfr.To_str_and_clear());
|
||||
}
|
||||
private Keyval[] CallParserFunction_parse_args(Number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, Keyval[] args) {
|
||||
private Keyval[] CallParserFunction_parse_args(Gfo_number_parser num_parser, Bry_obj_ref argx_ref, Bry_obj_ref fnc_name_ref, Keyval[] args) {
|
||||
List_adp rv = List_adp_.New();
|
||||
// flatten args
|
||||
int args_len = args.length;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public Scrib_lib_wikibase(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
@@ -35,6 +35,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
case Proc_getLabel: return GetLabel(args, rslt);
|
||||
case Proc_getEntity: return GetEntity(args, rslt);
|
||||
case Proc_getSetting: return GetSetting(args, rslt);
|
||||
case Proc_getEntityUrl: return GetEntityUrl(args, rslt);
|
||||
case Proc_renderSnak: return RenderSnak(args, rslt);
|
||||
case Proc_renderSnaks: return RenderSnaks(args, rslt);
|
||||
case Proc_getEntityId: return GetEntityId(args, rslt);
|
||||
@@ -43,26 +44,42 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
case Proc_resolvePropertyId: return ResolvePropertyId(args, rslt);
|
||||
case Proc_getSiteLinkPageName: return GetSiteLinkPageName(args, rslt);
|
||||
case Proc_incrementExpensiveFunctionCount: return IncrementExpensiveFunctionCount(args, rslt);
|
||||
case Proc_getPropertyOrder: return GetPropertyOrder(args, rslt);
|
||||
case Proc_orderProperties: return OrderProperties(args, rslt);
|
||||
default: throw Err_.new_unhandled(key);
|
||||
}
|
||||
}
|
||||
private static final int Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_renderSnak = 3, Proc_renderSnaks = 4, Proc_getEntityId = 5, Proc_getUserLang = 6, Proc_getDescription = 7, Proc_resolvePropertyId = 8, Proc_getSiteLinkPageName = 9, Proc_incrementExpensiveFunctionCount = 10;
|
||||
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount";
|
||||
private static final String[] Proc_names = String_.Ary(Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount);
|
||||
private static final int
|
||||
Proc_getLabel = 0, Proc_getEntity = 1, Proc_getSetting = 2, Proc_getEntityUrl = 3, Proc_renderSnak = 4, Proc_renderSnaks = 5, Proc_getEntityId = 6, Proc_getUserLang = 7
|
||||
, Proc_getDescription = 8, Proc_resolvePropertyId = 9, Proc_getSiteLinkPageName = 10, Proc_incrementExpensiveFunctionCount = 11, Proc_getPropertyOrder = 12, Proc_orderProperties = 13;
|
||||
public static final String Invk_getLabel = "getLabel", Invk_getEntity = "getEntity", Invk_getSetting = "getSetting", Invk_getEntityUrl = "getEntityUrl"
|
||||
, Invk_renderSnak = "renderSnak", Invk_renderSnaks = "renderSnaks", Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang"
|
||||
, Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId", Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount"
|
||||
, Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
||||
;
|
||||
private static final String[] Proc_names = String_.Ary
|
||||
( Invk_getLabel, Invk_getEntity, Invk_getSetting, Invk_getEntityUrl, Invk_renderSnak, Invk_renderSnaks, Invk_getEntityId, Invk_getUserLang
|
||||
, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount, Invk_getPropertyOrder, Invk_orderProperties
|
||||
);
|
||||
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);}
|
||||
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean GetEntity(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty(); // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry);
|
||||
return wdoc == null ? rslt.Init_ary_empty() : rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl(wdoc, true, false)); // "false": wbase now always uses v2; PAGE:ja.w:東京競馬場; DATE:2015-07-28
|
||||
}
|
||||
public boolean GetEntityUrl(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getEntityUrl not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String rv = Wdata_prop_val_visitor_.Render_snak(core.Wiki(), core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
public boolean RenderSnaks(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
String rv = Wdata_prop_val_visitor_.Render_snaks(core.Wiki(), core.Page().Url_bry_safe(), args.Pull_kv_ary_safe(0));
|
||||
return rslt.Init_obj(rv);
|
||||
}
|
||||
public boolean GetSetting(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getSetting not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "renderSnak not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean RenderSnaks(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "renderSnaks not implemented", "url", core.Page().Url().To_str(), "arg", args.Pull_bry(0));}
|
||||
public boolean GetEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0);
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
@@ -74,18 +91,15 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
return rslt.Init_obj(core.App().Usere().Lang().Key_bry());
|
||||
}
|
||||
public boolean GetDescription(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
return rslt.Init_obj(wdoc.Descr_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean ResolvePropertyId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] prop = args.Pull_bry(0); if (Bry_.Len_eq_0(prop)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(prop); if (wdoc == null) return rslt.Init_ary_empty(); // prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty(); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
||||
return rslt.Init_obj(wdoc.Label_list__get_or_fallback(core.Lang()));
|
||||
}
|
||||
public boolean GetSiteLinkPageName(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] ttl_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(ttl_bry)) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc(ttl_bry); if (wdoc == null) return rslt.Init_ary_empty();
|
||||
Wdata_doc wdoc = Get_wdoc_or_null(args, core); if (wdoc == null) return rslt.Init_ary_empty(); // NOTE: prop should be of form "P123"; do not add "P"; PAGE:no.w:Anne_Enger; DATE:2015-10-27
|
||||
Xow_domain_itm domain_itm = core.Wiki().Domain_itm();
|
||||
return rslt.Init_obj(wdoc.Slink_list__get_or_fallback(domain_itm.Abrv_wm()));
|
||||
}
|
||||
@@ -93,10 +107,15 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
||||
}
|
||||
private Wdata_doc Get_wdoc(byte[] xid_bry) {
|
||||
Xowe_wiki wiki = core.Wiki();
|
||||
Wdata_doc wdoc = wiki.Appe().Wiki_mgr().Wdata_mgr().Doc_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
||||
private static Wdata_doc Get_wdoc_or_null(Scrib_proc_args args, Scrib_core core) {
|
||||
// get qid / pid from scrib_arg[0]; if none, return null;
|
||||
byte[] xid_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(xid_bry)) return null; // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
|
||||
|
||||
// get wdoc
|
||||
Wdata_doc wdoc = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Doc_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
||||
if (wdoc == null) Wdata_wiki_mgr.Log_missing_qid(core.Ctx(), xid_bry);
|
||||
return wdoc;
|
||||
}
|
||||
public boolean GetPropertyOrder(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "getPropertyOrder not implemented", "url", core.Page().Url().To_str());}
|
||||
public boolean OrderProperties(Scrib_proc_args args, Scrib_proc_rslt rslt) {throw Err_.new_("wbase", "orderProperties not implemented", "url", core.Page().Url().To_str());}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.core.*;
|
||||
import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
public Scrib_lib_wikibase_entity(Scrib_core core) {this.core = core;} private Scrib_core core;
|
||||
public Scrib_lua_mod Mod() {return mod;} private Scrib_lua_mod mod;
|
||||
@@ -42,7 +43,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
public boolean GetGlobalSiteId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(core.Wiki().Domain_abrv()); // ;siteGlobalID: This site's global ID (e.g. <code>'itwiki'</code>), as used in the sites table. Default: <code>$wgDBname</code>.; REF:/xtns/Wikibase/docs/options.wiki
|
||||
}
|
||||
public boolean FormatPropertyValues(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
public boolean FormatPropertyValues(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
byte[] qid = args.Pull_bry(0);
|
||||
byte[] pid = args.Pull_bry(1);
|
||||
Xoae_app app = core.App(); Xowe_wiki wiki = core.Wiki();
|
||||
@@ -52,7 +53,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
||||
int pid_int = Wbase_pid_mgr.To_int_or_null(pid); // parse as num; EX: p123 -> 123; PAGE:hr.w:Hepatitis DATE:2015-11-08
|
||||
if (pid_int == Wdata_wiki_mgr.Pid_null) pid_int = wdata_mgr.Pid_mgr.Get_or_null(lang, pid); // parse as name; EX: name > 123
|
||||
if (pid_int == Wdata_wiki_mgr.Pid_null) return rslt.Init_str_empty();
|
||||
Wdata_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty();
|
||||
Wbase_claim_grp prop_grp = wdoc.Claim_list_get(pid_int); if (prop_grp == null) return rslt.Init_str_empty();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang);
|
||||
return rslt.Init_obj(bfr.To_bry_and_rls());
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.xtns.wbases.*;
|
||||
public class Scrib_lib_wikibase_entity_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear_for_lib();
|
||||
@@ -28,7 +28,7 @@ public class Scrib_lib_wikibase_entity_tst {
|
||||
}
|
||||
@Test public void FormatPropertyValues() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt().Init(fxt.Parser_fxt(), false);
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_str(3, "P3_val")).Xto_wdoc());
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_string(3, "P3_val")).Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3") , "P3_val"); // lookup by id
|
||||
wdata_fxt.Init_pids_add("en", "P3_val", 3);
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase_entity.Invk_formatPropertyValues, Object_.Ary("Q2", "P3_val") , "P3_val"); // lookup by name
|
||||
|
||||
@@ -16,14 +16,14 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
class Scrib_lib_wikibase_srl {
|
||||
public static Keyval[] Srl(Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
|
||||
int base_adj = legacy_style ? 0 : 1;
|
||||
List_adp rv = List_adp_.New();
|
||||
if (header_enabled) {
|
||||
rv.Add(Keyval_.new_("id", wdoc.Qid()));
|
||||
rv.Add(Keyval_.new_("type", Wdata_dict_value_entity_tid.Str_item));
|
||||
rv.Add(Keyval_.new_("type", Wbase_claim_entity_type_.Itm__item.Key_str()));
|
||||
rv.Add(Keyval_.new_("schemaVersion", base_adj + 1)); // NOTE: needed by mw.wikibase.lua
|
||||
}
|
||||
Srl_root(rv, Wdata_doc_parser_v2.Str_labels , Srl_langtexts (Wdata_dict_langtext.Str_language , Wdata_dict_langtext.Str_value, wdoc.Label_list()));
|
||||
@@ -94,7 +94,7 @@ class Scrib_lib_wikibase_srl {
|
||||
int rv_len = legacy_style ? len * 2 : len; // NOTE: legacyStyle returns 2 sets of properties: official "P" and legacy "p"; DATE:2014-05-11
|
||||
Keyval[] rv = new Keyval[rv_len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wdata_claim_grp grp = (Wdata_claim_grp)claim_grps.Get_at(i);
|
||||
Wbase_claim_grp grp = (Wbase_claim_grp)claim_grps.Get_at(i);
|
||||
String pid_str = Int_.To_str(grp.Id());
|
||||
Keyval[] grp_val = Srl_claims_prop_grp(visitor, "P" + pid_str, grp, base_adj);
|
||||
rv[i] = Keyval_.new_("P" + pid_str, grp_val);
|
||||
@@ -103,57 +103,57 @@ class Scrib_lib_wikibase_srl {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_grp(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wdata_claim_grp grp, int base_adj) {
|
||||
private static Keyval[] Srl_claims_prop_grp(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wbase_claim_grp grp, int base_adj) {
|
||||
int len = grp.Len();
|
||||
Keyval[] rv = new Keyval[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wdata_claim_itm_core itm = grp.Get_at(i);
|
||||
Wbase_claim_base itm = grp.Get_at(i);
|
||||
rv[i] = Keyval_.int_(i + base_adj, Srl_claims_prop_itm(visitor, pid, itm, base_adj)); // NOTE: must be super 0 or super 1; DATE:2014-05-09
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_itm(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wdata_claim_itm_core itm, int base_adj) {
|
||||
private static Keyval[] Srl_claims_prop_itm(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wbase_claim_base itm, int base_adj) {
|
||||
List_adp list = List_adp_.New();
|
||||
list.Add(Keyval_.new_("id", pid));
|
||||
list.Add(Keyval_.new_("mainsnak", Srl_claims_prop_itm_core(visitor, pid, itm)));
|
||||
list.Add(Keyval_.new_(Wdata_dict_claim_v1.Str_rank, Wdata_dict_rank.Xto_str(itm.Rank_tid())));
|
||||
list.Add(Keyval_.new_(Wdata_dict_claim_v1.Str_rank, Wbase_claim_rank_.To_str_or_fail(itm.Rank_tid())));
|
||||
list.Add(Keyval_.new_("type", itm.Prop_type()));
|
||||
Srl_root(list, Wdata_dict_claim.Str_qualifiers, Srl_qualifiers(visitor, itm.Qualifiers(), base_adj));
|
||||
return (Keyval[])list.To_ary_and_clear(Keyval.class);
|
||||
}
|
||||
private static Keyval[] Srl_qualifiers(Scrib_lib_wikibase_srl_visitor visitor, Wdata_claim_grp_list list, int base_adj) {
|
||||
private static Keyval[] Srl_qualifiers(Scrib_lib_wikibase_srl_visitor visitor, Wbase_claim_grp_list list, int base_adj) {
|
||||
if (list == null) return null;
|
||||
int list_len = list.Len(); if (list_len == 0) return Keyval_.Ary_empty;
|
||||
List_adp rv = List_adp_.New();
|
||||
List_adp pid_list = List_adp_.New();
|
||||
for (int i = 0; i < list_len; ++i) {
|
||||
Wdata_claim_grp grp = list.Get_at(i);
|
||||
Wbase_claim_grp grp = list.Get_at(i);
|
||||
int grp_len = grp.Len();
|
||||
pid_list.Clear();
|
||||
String itm_pid = grp.Id_str();
|
||||
for (int j = 0; j < grp_len; ++j) {
|
||||
Wdata_claim_itm_core itm = grp.Get_at(j);
|
||||
Wbase_claim_base itm = grp.Get_at(j);
|
||||
pid_list.Add(Keyval_.int_(j + base_adj, Srl_claims_prop_itm_core(visitor, itm_pid, itm))); // NOTE: was originally "+ 1"; changed to base_adj; PAGE:ru.w:Tor ru.w:Кактусовые DATE:2014-10-25
|
||||
}
|
||||
rv.Add(Keyval_.new_(itm_pid, (Keyval[])pid_list.To_ary_and_clear(Keyval.class)));
|
||||
}
|
||||
return (Keyval[])rv.To_ary_and_clear(Keyval.class);
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_itm_core(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wdata_claim_itm_core itm) {
|
||||
boolean snak_is_valued = itm.Snak_tid() == Wdata_dict_snak_tid.Tid_value; // PURPOSE: was != Wdata_dict_snak_tid.Tid_novalue; PAGE:it.s:Autore:Anonimo DATE:2015-12-06
|
||||
private static Keyval[] Srl_claims_prop_itm_core(Scrib_lib_wikibase_srl_visitor visitor, String pid, Wbase_claim_base itm) {
|
||||
boolean snak_is_valued = itm.Snak_tid() == Wbase_claim_value_type_.Tid__value; // PURPOSE: was != Wbase_claim_value_type_.Tid__novalue; PAGE:it.s:Autore:Anonimo DATE:2015-12-06
|
||||
int snak_is_valued_adj = snak_is_valued ? 1 : 0;
|
||||
Keyval[] rv = new Keyval[3 + snak_is_valued_adj];
|
||||
if (snak_is_valued) // NOTE: novalue must not return slot (no datavalue node in json); PAGE:ru.w:Лимонов,_Эдуард_Вениаминович; DATE:2015-02-16; ALSO: sv.w:Joseph_Jaquet; DATE:2015-07-31
|
||||
rv[0] = Keyval_.new_("datavalue", Srl_claims_prop_itm_core_val(visitor, itm));
|
||||
rv[0 + snak_is_valued_adj] = Keyval_.new_("property", pid);
|
||||
rv[1 + snak_is_valued_adj] = Keyval_.new_("snaktype", Wdata_dict_snak_tid.Xto_str(itm.Snak_tid()));
|
||||
rv[2 + snak_is_valued_adj] = Keyval_.new_("datatype", Wdata_dict_val_tid.To_str__srl(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
|
||||
rv[1 + snak_is_valued_adj] = Keyval_.new_("snaktype", Wbase_claim_value_type_.To_str_or_fail(itm.Snak_tid()));
|
||||
rv[2 + snak_is_valued_adj] = Keyval_.new_("datatype", Wbase_claim_type_.To_scrib_or_unknown(itm.Val_tid())); // NOTE: datatype needed for Modules; PAGE:eo.w:WikidataKoord; DATE:2015-11-08
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Srl_claims_prop_itm_core_val(Scrib_lib_wikibase_srl_visitor visitor, Wdata_claim_itm_core itm) {
|
||||
private static Keyval[] Srl_claims_prop_itm_core_val(Scrib_lib_wikibase_srl_visitor visitor, Wbase_claim_base itm) {
|
||||
switch (itm.Snak_tid()) {
|
||||
case Wdata_dict_snak_tid.Tid_somevalue: return Datavalue_somevalue;
|
||||
case Wdata_dict_snak_tid.Tid_novalue: return Datavalue_novalue; // TODO_OLD: throw exc
|
||||
case Wbase_claim_value_type_.Tid__somevalue: return Datavalue_somevalue;
|
||||
case Wbase_claim_value_type_.Tid__novalue: return Datavalue_novalue; // TODO_OLD: throw exc
|
||||
default:
|
||||
itm.Welcome(visitor);
|
||||
return visitor.Rv();
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
public class Scrib_lib_wikibase_srl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Scrib_lib_wikibase_srl_fxt fxt = new Scrib_lib_wikibase_srl_fxt();
|
||||
@Test public void Label() {
|
||||
@@ -126,7 +126,7 @@ public class Scrib_lib_wikibase_srl_tst {
|
||||
);
|
||||
}
|
||||
@Test public void Claims_str() {
|
||||
fxt.Init_prop(fxt.Wdata_fxt().Make_claim_str(2, "Moon"));
|
||||
fxt.Init_prop(fxt.Wdata_fxt().Make_claim_string(2, "Moon"));
|
||||
fxt.Test
|
||||
( "claims:"
|
||||
, " P2:"
|
||||
@@ -327,7 +327,7 @@ public class Scrib_lib_wikibase_srl_tst {
|
||||
}
|
||||
@Test public void Qualifiers() {
|
||||
Wdata_wiki_mgr_fxt wdata_fxt = fxt.Wdata_fxt();
|
||||
fxt.Init_prop(wdata_fxt.Make_claim_str(2, "Earth").Qualifiers_(wdata_fxt.Make_qualifiers(wdata_fxt.Make_qualifiers_grp(3, wdata_fxt.Make_claim_time(3, "2001-02-03 04:05:06")))));
|
||||
fxt.Init_prop(wdata_fxt.Make_claim_string(2, "Earth").Qualifiers_(wdata_fxt.Make_qualifiers(wdata_fxt.Make_qualifiers_grp(3, wdata_fxt.Make_claim_time(3, "2001-02-03 04:05:06")))));
|
||||
fxt.Test
|
||||
( "claims:"
|
||||
, " P2:"
|
||||
@@ -388,7 +388,7 @@ class Scrib_lib_wikibase_srl_fxt {
|
||||
wdoc_bldr.Add_alias(lang, ary);
|
||||
return this;
|
||||
}
|
||||
public Scrib_lib_wikibase_srl_fxt Init_prop(Wdata_claim_itm_core prop) {wdoc_bldr.Add_claims(prop); return this;}
|
||||
public Scrib_lib_wikibase_srl_fxt Init_prop(Wbase_claim_base prop) {wdoc_bldr.Add_claims(prop); return this;}
|
||||
public Scrib_lib_wikibase_srl_fxt Test(String... expd) {return Test(false, expd);}
|
||||
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, String... expd) {
|
||||
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(wdoc_bldr.Xto_wdoc(), header_enabled, base0);
|
||||
|
||||
@@ -16,80 +16,80 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.xowa.xtns.wdatas.core.*;
|
||||
class Scrib_lib_wikibase_srl_visitor implements Wdata_claim_visitor {
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
class Scrib_lib_wikibase_srl_visitor implements Wbase_claim_visitor {
|
||||
public Keyval[] Rv() {return rv;} Keyval[] rv;
|
||||
public void Visit_str(Wdata_claim_itm_str itm) {
|
||||
public void Visit_str(Wbase_claim_string itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Xto_str(itm.Val_tid()));
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.To_key_or_unknown(itm.Val_tid()));
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, String_.new_u8(itm.Val_str()));
|
||||
}
|
||||
public void Visit_entity(Wdata_claim_itm_entity itm) {
|
||||
public void Visit_entity(Wbase_claim_entity itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_entity);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__entity.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Entity_value(itm));
|
||||
}
|
||||
private static Keyval[] Entity_value(Wdata_claim_itm_core itm) {
|
||||
Wdata_claim_itm_entity claim_entity = (Wdata_claim_itm_entity)itm;
|
||||
private static Keyval[] Entity_value(Wbase_claim_base itm) {
|
||||
Wbase_claim_entity claim_entity = (Wbase_claim_entity)itm;
|
||||
Keyval[] rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_entity.Str_entity_type, claim_entity.Entity_tid_str());
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_entity.Str_numeric_id, Int_.To_str(claim_entity.Entity_id()));
|
||||
rv[0] = Keyval_.new_(Wbase_claim_entity_.Itm__entity_type.Key_str(), claim_entity.Entity_tid_str());
|
||||
rv[1] = Keyval_.new_(Wbase_claim_entity_.Itm__numeric_id.Key_str(), Int_.To_str(claim_entity.Entity_id()));
|
||||
return rv;
|
||||
}
|
||||
public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {
|
||||
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_monolingualtext);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__monolingualtext.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Monolingualtext_value(itm));
|
||||
}
|
||||
private static Keyval[] Monolingualtext_value(Wdata_claim_itm_monolingualtext itm) {
|
||||
private static Keyval[] Monolingualtext_value(Wbase_claim_monolingualtext itm) {
|
||||
Keyval[] rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_monolingualtext.Str_text , String_.new_u8(itm.Text()));
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_monolingualtext.Str_language , String_.new_u8(itm.Lang()));
|
||||
rv[0] = Keyval_.new_(Wbase_claim_monolingualtext_.Itm__text.Key_str() , String_.new_u8(itm.Text()));
|
||||
rv[1] = Keyval_.new_(Wbase_claim_monolingualtext_.Itm__language.Key_str() , String_.new_u8(itm.Lang()));
|
||||
return rv;
|
||||
}
|
||||
public void Visit_quantity(Wdata_claim_itm_quantity itm) {
|
||||
public void Visit_quantity(Wbase_claim_quantity itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_quantity);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__quantity.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Quantity_value(itm));
|
||||
}
|
||||
private static Keyval[] Quantity_value(Wdata_claim_itm_quantity itm) {
|
||||
private static Keyval[] Quantity_value(Wbase_claim_quantity itm) {
|
||||
Keyval[] rv = new Keyval[4];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_quantity.Str_amount , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_quantity.Str_unit , String_.new_u8(itm.Unit()));
|
||||
rv[2] = Keyval_.new_(Wdata_dict_value_quantity.Str_upperbound , itm.Ubound_as_num().To_str());
|
||||
rv[3] = Keyval_.new_(Wdata_dict_value_quantity.Str_lowerbound , itm.Lbound_as_num().To_str());
|
||||
rv[0] = Keyval_.new_(Wbase_claim_quantity_.Itm__amount.Key_str() , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
|
||||
rv[1] = Keyval_.new_(Wbase_claim_quantity_.Itm__unit.Key_str() , String_.new_u8(itm.Unit()));
|
||||
rv[2] = Keyval_.new_(Wbase_claim_quantity_.Itm__upperbound.Key_str() , itm.Ubound_as_num().To_str());
|
||||
rv[3] = Keyval_.new_(Wbase_claim_quantity_.Itm__lowerbound.Key_str() , itm.Lbound_as_num().To_str());
|
||||
return rv;
|
||||
}
|
||||
public void Visit_time(Wdata_claim_itm_time itm) {
|
||||
public void Visit_time(Wbase_claim_time itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_time);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__time.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Time_value(itm));
|
||||
}
|
||||
private static Keyval[] Time_value(Wdata_claim_itm_time itm) {
|
||||
private static Keyval[] Time_value(Wbase_claim_time itm) {
|
||||
Keyval[] rv = new Keyval[6];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_time.Str_time , String_.new_a7(itm.Time()));
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_time.Str_precision , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
|
||||
rv[2] = Keyval_.new_(Wdata_dict_value_time.Str_before , itm.Before_int());
|
||||
rv[3] = Keyval_.new_(Wdata_dict_value_time.Str_after , itm.After_int());
|
||||
rv[4] = Keyval_.new_(Wdata_dict_value_time.Str_timezone , Wdata_dict_value_time.Val_timezone_str); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
|
||||
rv[5] = Keyval_.new_(Wdata_dict_value_time.Str_calendarmodel , Wdata_dict_value_time.Val_calendarmodel_str);
|
||||
rv[0] = Keyval_.new_(Wbase_claim_time_.Itm__time.Key_str() , String_.new_a7(itm.Time()));
|
||||
rv[1] = Keyval_.new_(Wbase_claim_time_.Itm__precision.Key_str() , itm.Precision_int()); // NOTE: must return int, not str; DATE:2014-02-18
|
||||
rv[2] = Keyval_.new_(Wbase_claim_time_.Itm__before.Key_str() , itm.Before_int());
|
||||
rv[3] = Keyval_.new_(Wbase_claim_time_.Itm__after.Key_str() , itm.After_int());
|
||||
rv[4] = Keyval_.new_(Wbase_claim_time_.Itm__timezone.Key_str() , Wbase_claim_time_.Dflt__timezone.Val_str()); // ASSUME: always 0 b/c UTF?; DATE:2015-09-21
|
||||
rv[5] = Keyval_.new_(Wbase_claim_time_.Itm__calendarmodel.Key_str() , Wbase_claim_time_.Dflt__calendarmodel.Val_str());
|
||||
return rv;
|
||||
}
|
||||
public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) {
|
||||
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
|
||||
rv = new Keyval[2];
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wdata_dict_val_tid.Str_globecoordinate);
|
||||
rv[0] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_type, Wbase_claim_type_.Itm__globecoordinate.Key_str());
|
||||
rv[1] = Keyval_.new_(Scrib_lib_wikibase_srl.Key_value, Globecoordinate_value(itm));
|
||||
}
|
||||
private static Keyval[] Globecoordinate_value(Wdata_claim_itm_globecoordinate itm) {
|
||||
private static Keyval[] Globecoordinate_value(Wbase_claim_globecoordinate itm) {
|
||||
Keyval[] rv = new Keyval[5];
|
||||
rv[0] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_latitude , Double_.parse(String_.new_a7(itm.Lat())));
|
||||
rv[1] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_longitude , Double_.parse(String_.new_a7(itm.Lng())));
|
||||
rv[2] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_altitude , String_.new_u8(itm.Alt()));
|
||||
rv[3] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_globe , String_.new_u8(itm.Glb()));
|
||||
rv[4] = Keyval_.new_(Wdata_dict_value_globecoordinate.Str_precision , itm.Prc_as_num().To_double());
|
||||
rv[0] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__latitude.Key_str() , Double_.parse(String_.new_a7(itm.Lat())));
|
||||
rv[1] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__longitude.Key_str() , Double_.parse(String_.new_a7(itm.Lng())));
|
||||
rv[2] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__altitude.Key_str() , String_.new_u8(itm.Alt()));
|
||||
rv[3] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__globe.Key_str() , String_.new_u8(itm.Glb()));
|
||||
rv[4] = Keyval_.new_(Wbase_claim_globecoordinate_.Itm__precision.Key_str() , itm.Prc_as_num().To_double());
|
||||
return rv;
|
||||
}
|
||||
public void Visit_system(Wdata_claim_itm_system itm) {
|
||||
public void Visit_system(Wbase_claim_value itm) {
|
||||
rv = Keyval_.Ary_empty;
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
import org.junit.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
public class Scrib_lib_wikibase_tst {
|
||||
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
|
||||
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
|
||||
@@ -89,4 +88,58 @@ public class Scrib_lib_wikibase_tst {
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Property:p2").Add_label("zh-hans", "prop_a").Xto_wdoc());
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_resolvePropertyId, Object_.Ary("p2"), "prop_a");
|
||||
}
|
||||
}
|
||||
@Test public void RenderSnaks() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snaks_ary(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "P3_en"), wdata_fxt.Make_claim_monolingual(3, "de", "P3_de"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnaks, args, "P3_en, P3_de");
|
||||
}
|
||||
@Test public void RenderSnak__str() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_string(3, "test_str"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "test_str");
|
||||
}
|
||||
@Test public void RenderSnak__quantity() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_quantity(3, "123", "2", "125", "121"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "123±2");
|
||||
}
|
||||
@Test public void RenderSnak__time() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_time(3, "2012-01-02 03:04:05"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "30405 2 Jan 2012"); // NOTE: format is missing ":" b/c test does not init messages for html_wtr; DATE:2015-08-03
|
||||
}
|
||||
@Test public void RenderSnak__geo() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_geo(3, "3.4", "1.2"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "1.2, 3.4");
|
||||
}
|
||||
@Test public void RenderSnak__monolingual() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "abc_en"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "abc_en");
|
||||
}
|
||||
}
|
||||
class Wbase_snak_utl_ {
|
||||
public static Keyval[] Get_snaks_ary(Wdata_wiki_mgr_fxt wdata_fxt, Wbase_claim_base... ary) {
|
||||
Wdata_doc wdoc = wdata_fxt.Wdoc_bldr("q2").Add_claims(ary).Xto_wdoc();
|
||||
return Keyval_.Ary(Keyval_.int_(1, Get_snaks(wdoc)));
|
||||
}
|
||||
public static Keyval[] Get_snak(Wdata_wiki_mgr_fxt wdata_fxt, Wbase_claim_base itm) {
|
||||
Wdata_doc wdoc = wdata_fxt.Wdoc_bldr("q2").Add_claims(itm).Xto_wdoc();
|
||||
Keyval[] snak_props = Get_subs_by_path(Get_snaks(wdoc), 0);
|
||||
return Keyval_.Ary(Keyval_.int_(1, snak_props));
|
||||
}
|
||||
private static Keyval[] Get_snaks(Wdata_doc wdoc) {
|
||||
Keyval[] wdoc_root = Scrib_lib_wikibase_srl.Srl(wdoc, false, false);
|
||||
Keyval[] snaks = Get_subs_by_path(wdoc_root, 0, 0);
|
||||
int snaks_len = snaks.length;
|
||||
Keyval[] rv = new Keyval[snaks_len];
|
||||
for (int i = 0; i < snaks_len; ++i) {
|
||||
rv[i] = Keyval_.int_(i + List_adp_.Base1, Get_subs_by_path(snaks, i, 1));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static Keyval[] Get_subs_by_path(Keyval[] root, int... levels) {
|
||||
int len = levels.length;
|
||||
Keyval[] rv = root;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int idx = levels[i];
|
||||
rv = (Keyval[])rv[idx].Val();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.regxs.*;
|
||||
public class Scrib_regx_converter {
|
||||
private List_adp capt_list = List_adp_.New(), grps_parens = List_adp_.New(); private List_adp grps_open = List_adp_.New();
|
||||
private final List_adp capt_list = List_adp_.New(), grps_parens = List_adp_.New(); private final List_adp grps_open = List_adp_.New();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public Scrib_regx_converter() {Init();}
|
||||
public String Regx() {return regx;} private String regx;
|
||||
public List_adp Capt_list() {return capt_list;}
|
||||
@@ -100,9 +101,8 @@ public class Scrib_regx_converter {
|
||||
++i;
|
||||
if (i + 1 >= len || src[i] != Byte_ascii.Brack_bgn) throw Err_.new_("scribunto", "missing '[' after %f in pattern at pattern character $ii");
|
||||
// %f always followed by bracketed term; convert lua bracketed term to regex
|
||||
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
i = bracketedCharSetToRegex(tmp_bfr, src, i, len);
|
||||
byte[] bracketed_regx = tmp_bfr.To_bry_and_rls();
|
||||
byte[] bracketed_regx = tmp_bfr.To_bry_and_clear();
|
||||
|
||||
// scrib has following comment: 'Because %f considers the beginning and end of the String to be \0, determine if $re2 matches that and take it into account with "^" and "$".'
|
||||
// if the bracketed_regx is a negative class it will match \0; so, \W means anything not a word char, which will match \0; \w means word char which will not match \0
|
||||
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Wbase_doc_mgr {
|
||||
private final Xoae_app app;
|
||||
private final Wdata_wiki_mgr wbase_mgr;
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
public class Wbase_pid_mgr { // EX: "en|road_map" -> 15 ("Property:P15")
|
||||
private final Wdata_wiki_mgr wbase_mgr;
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Wbase_qid_mgr {// EX: "enwiki|0|Earth" -> "Q2"
|
||||
private final Wdata_wiki_mgr wbase_mgr;
|
||||
@@ -15,11 +15,11 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
public class Wdata_doc {
|
||||
private Wdata_wiki_mgr mgr; private Int_obj_ref tmp_key;
|
||||
public Wdata_doc(byte[] qid, Wdata_wiki_mgr mgr, Json_doc jdoc) {this.qid = qid; this.mgr = mgr; this.jdoc = jdoc;}
|
||||
@@ -35,10 +35,10 @@ public class Wdata_doc {
|
||||
public Ordered_hash Descr_list() {if (descr_list == null) descr_list = mgr.Wdoc_parser(jdoc).Parse_langvals(qid, jdoc, Bool_.N); return descr_list;} private Ordered_hash descr_list;
|
||||
public Ordered_hash Alias_list() {if (alias_list == null) alias_list = mgr.Wdoc_parser(jdoc).Parse_aliases(qid, jdoc); return alias_list;} private Ordered_hash alias_list;
|
||||
public Ordered_hash Claim_list() {if (claim_list == null) claim_list = mgr.Wdoc_parser(jdoc).Parse_claims(qid, jdoc); return claim_list;} private Ordered_hash claim_list;
|
||||
public Wdata_claim_grp Claim_list_get(int pid) {
|
||||
public Wbase_claim_grp Claim_list_get(int pid) {
|
||||
if (tmp_key == null) tmp_key = Int_obj_ref.New_neg1();
|
||||
Object o = this.Claim_list().Get_by(tmp_key.Val_(pid));
|
||||
return (Wdata_claim_grp)o;
|
||||
return (Wbase_claim_grp)o;
|
||||
}
|
||||
public byte[] Label_list__get(byte[] lang_key) {return Lang_text_list__get(this.Label_list(), lang_key);}
|
||||
public byte[] Label_list__get_or_fallback(Xol_lang_itm lang) {return Lang_text_list__get_or_fallback(this.Label_list(), lang);}
|
||||
@@ -15,17 +15,19 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.xtns.wbases.core.*;
|
||||
import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
public class Wdata_doc_bldr {
|
||||
private Ordered_hash descr_list, label_list, slink_list, alias_list, claim_list;
|
||||
public Wdata_doc_bldr() {this.Init();}
|
||||
public Wdata_doc_bldr Qid_(String v) {this.qid = Bry_.new_a7(v); return this;} private byte[] qid;
|
||||
public Wdata_doc_bldr Add_claims(Wdata_claim_itm_core... ary) {
|
||||
public Wdata_doc_bldr Add_claims(Wbase_claim_base... ary) {
|
||||
if (ary.length == 0) throw Err_.new_wo_type("claims must be greater than 0");
|
||||
Wdata_claim_itm_core itm = ary[0];
|
||||
Wdata_claim_grp grp = new Wdata_claim_grp(Int_obj_ref.New(itm.Pid()), ary);
|
||||
Wbase_claim_base itm = ary[0];
|
||||
Wbase_claim_grp grp = new Wbase_claim_grp(Int_obj_ref.New(itm.Pid()), ary);
|
||||
claim_list.Add(grp.Id_ref(), grp);
|
||||
return this;
|
||||
}
|
||||
@@ -15,8 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
public class Wdata_doc_wtr {
|
||||
private Json_doc_wtr wtr = new Json_doc_wtr();
|
||||
public byte[] Xto_bry(Wdata_doc wdoc) {
|
||||
@@ -85,73 +86,73 @@ public class Wdata_doc_wtr {
|
||||
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.Get_at(i);
|
||||
Wbase_claim_base prop = (Wbase_claim_base)props.Get_at(i);
|
||||
wtr.Nde_bgn();
|
||||
wtr.Key(false, Wdata_dict_claim_v1.Bry_m);
|
||||
wtr.Ary_bgn();
|
||||
wtr.Val(Bool_.N, Wdata_dict_snak_tid.Xto_bry(prop.Snak_tid()));
|
||||
wtr.Val(Bool_.N, Wbase_claim_value_type_.To_bry_or_fail(prop.Snak_tid()));
|
||||
wtr.Val(Bool_.Y, prop.Pid());
|
||||
if (prop.Snak_tid() == Wdata_dict_snak_tid.Tid_value) {
|
||||
if (prop.Snak_tid() == Wbase_claim_value_type_.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);
|
||||
case Wbase_claim_type_.Tid__string:
|
||||
Wbase_claim_string claim_str = (Wbase_claim_string)prop;
|
||||
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__string.Key_bry());
|
||||
wtr.Val(Bool_.Y, claim_str.Val_str());
|
||||
break;
|
||||
case 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);
|
||||
case Wbase_claim_type_.Tid__entity:
|
||||
Wbase_claim_entity claim_entity = (Wbase_claim_entity)prop;
|
||||
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__entity.Key_bry());
|
||||
wtr.Comma();
|
||||
wtr.Nde_bgn();
|
||||
wtr.Kv(Bool_.N, Wdata_dict_value_entity.Bry_entity_type , claim_entity.Entity_tid_bry());
|
||||
wtr.Kv(Bool_.Y, Wdata_dict_value_entity.Bry_numeric_id , claim_entity.Entity_id());
|
||||
wtr.Kv(Bool_.N, Wbase_claim_entity_.Itm__entity_type.Key_bry() , claim_entity.Entity_tid_bry());
|
||||
wtr.Kv(Bool_.Y, Wbase_claim_entity_.Itm__numeric_id.Key_bry() , claim_entity.Entity_id());
|
||||
wtr.Nde_end();
|
||||
break;
|
||||
case 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);
|
||||
case Wbase_claim_type_.Tid__time:
|
||||
Wbase_claim_time claim_time = (Wbase_claim_time)prop;
|
||||
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__time.Key_bry());
|
||||
wtr.Comma();
|
||||
wtr.Nde_bgn();
|
||||
wtr.Kv(Bool_.N, 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.Kv(Bool_.N, Wbase_claim_time_.Itm__time.Key_bry() , claim_time.Time());
|
||||
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__precision.Key_bry() , Wbase_claim_time_.Dflt__timezone.Val_bry());
|
||||
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__before.Key_bry() , Wbase_claim_time_.Dflt__before.Val_bry());
|
||||
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__after.Key_bry() , Wbase_claim_time_.Dflt__after.Val_bry());
|
||||
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__timezone.Key_bry() , Wbase_claim_time_.Dflt__timezone.Val_bry());
|
||||
wtr.Kv(Bool_.Y, Wbase_claim_time_.Itm__calendarmodel.Key_bry() , Wbase_claim_time_.Dflt__calendarmodel.Val_bry());
|
||||
wtr.Nde_end();
|
||||
break;
|
||||
case 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);
|
||||
case Wbase_claim_type_.Tid__globecoordinate: {
|
||||
Wbase_claim_globecoordinate claim_globecoordinate = (Wbase_claim_globecoordinate)prop;
|
||||
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__globecoordinate.Key_bry());
|
||||
wtr.Comma();
|
||||
wtr.Nde_bgn();
|
||||
wtr.Kv_double (Bool_.N, Wdata_dict_value_globecoordinate.Bry_latitude , Double_.parse(String_.new_a7(claim_globecoordinate.Lat())));
|
||||
wtr.Kv_double (Bool_.Y, Wdata_dict_value_globecoordinate.Bry_longitude , Double_.parse(String_.new_a7(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.Kv_double (Bool_.N, Wbase_claim_globecoordinate_.Itm__latitude.Key_bry() , Double_.parse(String_.new_a7(claim_globecoordinate.Lat())));
|
||||
wtr.Kv_double (Bool_.Y, Wbase_claim_globecoordinate_.Itm__longitude.Key_bry() , Double_.parse(String_.new_a7(claim_globecoordinate.Lng())));
|
||||
wtr.Kv (Bool_.Y, Wbase_claim_globecoordinate_.Itm__altitude.Key_bry() , null);
|
||||
wtr.Kv (Bool_.Y, Wbase_claim_globecoordinate_.Itm__globe.Key_bry() , Wbase_claim_globecoordinate_.Val_globe_dflt_bry);
|
||||
wtr.Kv_double (Bool_.Y, Wbase_claim_globecoordinate_.Itm__precision.Key_bry() , .00001d);
|
||||
wtr.Nde_end();
|
||||
break;
|
||||
}
|
||||
case 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);
|
||||
case Wbase_claim_type_.Tid__quantity: {
|
||||
Wbase_claim_quantity claim_quantity = (Wbase_claim_quantity)prop;
|
||||
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__quantity.Key_bry());
|
||||
wtr.Comma();
|
||||
wtr.Nde_bgn();
|
||||
wtr.Kv (Bool_.N, 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.Kv (Bool_.N, Wbase_claim_quantity_.Itm__amount.Key_bry() , claim_quantity.Amount()); // +1,234
|
||||
wtr.Kv (Bool_.Y, Wbase_claim_quantity_.Itm__unit.Key_bry() , claim_quantity.Unit()); // 1
|
||||
wtr.Kv (Bool_.Y, Wbase_claim_quantity_.Itm__upperbound.Key_bry() , claim_quantity.Ubound()); // +1,235
|
||||
wtr.Kv (Bool_.Y, Wbase_claim_quantity_.Itm__lowerbound.Key_bry() , claim_quantity.Lbound()); // +1,233
|
||||
wtr.Nde_end();
|
||||
break;
|
||||
}
|
||||
case 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);
|
||||
case Wbase_claim_type_.Tid__monolingualtext: {
|
||||
Wbase_claim_monolingualtext claim_monolingualtext = (Wbase_claim_monolingualtext)prop;
|
||||
wtr.Val(Bool_.Y, Wbase_claim_type_.Itm__monolingualtext.Key_bry());
|
||||
wtr.Comma();
|
||||
wtr.Nde_bgn();
|
||||
wtr.Kv (Bool_.N, 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.Kv (Bool_.N, Wbase_claim_monolingualtext_.Itm__text.Key_bry() , claim_monolingualtext.Text()); // text
|
||||
wtr.Kv (Bool_.Y, Wbase_claim_monolingualtext_.Itm__language.Key_bry() , claim_monolingualtext.Lang()); // en
|
||||
wtr.Nde_end();
|
||||
break;
|
||||
}
|
||||
@@ -161,7 +162,7 @@ public class Wdata_doc_wtr {
|
||||
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(Bool_.Y, Wdata_dict_claim_v1.Bry_rank, Wbase_claim_rank_.Tid__normal);
|
||||
wtr.Kv_ary_empty(Bool_.Y, Wdata_dict_claim_v1.Bry_refs);
|
||||
wtr.Nde_end();
|
||||
}
|
||||
@@ -15,11 +15,11 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.hwtrs.*;
|
||||
class Wdata_prop_val_visitor implements Wdata_claim_visitor {
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
class Wdata_prop_val_visitor implements Wbase_claim_visitor {
|
||||
private Wdata_wiki_mgr wdata_mgr; private Xoae_app app; private Bry_bfr bfr; private byte[] lang_key;
|
||||
private final Bry_bfr tmp_time_bfr = Bry_bfr_.Reset(255); private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_();
|
||||
private Wdata_hwtr_msgs msgs;
|
||||
@@ -27,14 +27,14 @@ class Wdata_prop_val_visitor implements Wdata_claim_visitor {
|
||||
public void Init(Bry_bfr bfr, Wdata_hwtr_msgs msgs, byte[] lang_key) {
|
||||
this.bfr = bfr; this.msgs = msgs; this.lang_key = lang_key;
|
||||
}
|
||||
public void Visit_str(Wdata_claim_itm_str itm) {
|
||||
public void Visit_str(Wbase_claim_string itm) {
|
||||
bfr.Add(itm.Val_str());
|
||||
}
|
||||
public void Visit_time(Wdata_claim_itm_time itm) {
|
||||
public void Visit_time(Wbase_claim_time itm) {
|
||||
itm.Write_to_bfr(bfr, tmp_time_bfr, tmp_time_fmtr, msgs, Bry_.Empty); // for now, don't bother passing ttl; only used for error msg; DATE:2015-08-03
|
||||
}
|
||||
public void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm) {bfr.Add(itm.Text());} // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28
|
||||
public void Visit_entity(Wdata_claim_itm_entity itm) {
|
||||
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {bfr.Add(itm.Text());} // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28
|
||||
public void Visit_entity(Wbase_claim_entity itm) {
|
||||
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(itm.Page_ttl_db());
|
||||
if (entity_doc == null) return; // NOTE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01
|
||||
byte[] label = entity_doc.Label_list__get(lang_key);
|
||||
@@ -43,22 +43,19 @@ class Wdata_prop_val_visitor implements Wdata_claim_visitor {
|
||||
if (label != null) // if label is still not found, don't add null reference
|
||||
bfr.Add(label);
|
||||
}
|
||||
public void Visit_quantity(Wdata_claim_itm_quantity itm) {
|
||||
public void Visit_quantity(Wbase_claim_quantity itm) {
|
||||
byte[] amount_bry = itm.Amount();
|
||||
long val = Bry_.To_long_or(amount_bry, Ignore_comma, 0, amount_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
|
||||
long val = Bry_.To_long_or(amount_bry, Byte_ascii.Comma_bry, 0, amount_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by(lang_key);
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(val)); // amount; EX: 1,234
|
||||
if (itm.Lbound_as_num().To_long() != val && itm.Ubound_as_num().To_long() != val) { // NOTE: do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
|
||||
bfr.Add(Bry_quantity_margin_of_error); // symbol: EX: ±
|
||||
bfr.Add(Bry__quantity_margin_of_error); // symbol: EX: ±
|
||||
bfr.Add(itm.Unit()); // unit; EX: 1
|
||||
}
|
||||
}
|
||||
public void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm) {
|
||||
bfr.Add(itm.Lat());
|
||||
bfr.Add_byte(Byte_ascii.Comma).Add_byte(Byte_ascii.Space);
|
||||
bfr.Add(itm.Lng());
|
||||
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
|
||||
Wdata_prop_val_visitor_.Render__geo(bfr, itm.Lat(), itm.Lng());
|
||||
}
|
||||
public void Visit_system(Wdata_claim_itm_system itm) {}
|
||||
private static final byte[] Ignore_comma = new byte[]{Byte_ascii.Comma};
|
||||
private static final byte[] Bry_quantity_margin_of_error = Bry_.new_u8("±");
|
||||
public void Visit_system(Wbase_claim_value itm) {}
|
||||
public static final byte[] Bry__quantity_margin_of_error = Bry_.new_u8("±");
|
||||
}
|
||||
151
400_xowa/src/gplx/xowa/xtns/wbases/Wdata_prop_val_visitor_.java
Normal file
151
400_xowa/src/gplx/xowa/xtns/wbases/Wdata_prop_val_visitor_.java
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.commas.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Wdata_prop_val_visitor_ {
|
||||
public static String Render_snaks(Xowe_wiki wiki, byte[] page_url, Keyval[] snaks) {
|
||||
String rv = null;
|
||||
int len = snaks.length;
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval[] itm = (Keyval[])snaks[i].Val();
|
||||
Render_snak(bfr, wiki, wiki.Lang(), page_url, itm, i, len);
|
||||
}
|
||||
wiki.Lang().Comma_wkr().Comma__end(bfr);
|
||||
rv = bfr.To_str_and_clear();
|
||||
} finally {bfr.Mkr_rls();}
|
||||
return rv;
|
||||
}
|
||||
public static String Render_snak(Xowe_wiki wiki, byte[] page_url, Keyval[] props) {
|
||||
String rv = null;
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
Render_snak(bfr, wiki, wiki.Lang(), page_url, props, 0, 1);
|
||||
rv = bfr.To_str_and_clear();
|
||||
} finally {bfr.Mkr_rls();}
|
||||
return rv;
|
||||
}
|
||||
private static void Render_snak(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang_itm lang, byte[] page_url, Keyval[] props, int sub_idx, int sub_len) {
|
||||
Keyval[] datavalue_ary = (Keyval[])Scrib_kv_utl_.Get_sub_by_key_or_null(props, Wdata_dict_mainsnak.Str_datavalue);
|
||||
|
||||
// loop datavalue_ary to get tid, val_obj
|
||||
byte tid = Byte_.Max_value_127;
|
||||
Object val_obj = null;
|
||||
int len = datavalue_ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String key = datavalue_ary[i].Key();
|
||||
if (String_.Eq(key, Wdata_dict_datavalue.Str_type))
|
||||
tid = Wbase_claim_type_.To_tid_or_unknown((String)datavalue_ary[i].Val());
|
||||
else if (String_.Eq(key, Wdata_dict_datavalue.Str_value))
|
||||
val_obj = datavalue_ary[i].Val();
|
||||
}
|
||||
|
||||
// render val_obj based on tid
|
||||
switch (tid) {
|
||||
case Wbase_claim_type_.Tid__entity: throw Err_.new_unimplemented();
|
||||
case Wbase_claim_type_.Tid__string: bfr.Add_str_u8((String)val_obj); break;
|
||||
case Wbase_claim_type_.Tid__time: Render__time (bfr, wiki, page_url, (Keyval[])val_obj); break;
|
||||
case Wbase_claim_type_.Tid__globecoordinate: Render__geo (bfr, lang, page_url, (Keyval[])val_obj); break;
|
||||
case Wbase_claim_type_.Tid__quantity: Render__quantity (bfr, lang, page_url, (Keyval[])val_obj); break;
|
||||
case Wbase_claim_type_.Tid__monolingualtext: Render__langtext (bfr, lang, (Keyval[])val_obj); break;
|
||||
}
|
||||
lang.Comma_wkr().Comma__itm(bfr, sub_idx, sub_len);
|
||||
}
|
||||
private static void Render__time(Bry_bfr bfr, Xowe_wiki wiki, byte[] page_url, Keyval[] kvs) {
|
||||
Wbase_date date = null;
|
||||
byte[] time = null;
|
||||
int precision_int = 0, before_int = 0, after_int = 0;
|
||||
boolean calendar_is_julian = true;
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = kvs[i];
|
||||
byte val_tid = Wbase_claim_time_.To_tid_or_invalid(page_url, kv.Key());
|
||||
switch (val_tid) {
|
||||
case Wbase_claim_time_.Tid__time: time = Bry_.new_u8((String)kv.Val()); break;
|
||||
case Wbase_claim_time_.Tid__before: before_int = Int_.cast(kv.Val()); break;
|
||||
case Wbase_claim_time_.Tid__after: after_int = Int_.cast(kv.Val()); break;
|
||||
case Wbase_claim_time_.Tid__precision: precision_int = Int_.cast(kv.Val()); break;
|
||||
case Wbase_claim_time_.Tid__calendarmodel: calendar_is_julian = Bry_.Eq(Bry_.new_u8((String)kv.Val()), Wbase_claim_time.Calendar_julian); break;
|
||||
case Wbase_claim_time_.Tid__timezone: if (!String_.Eq((String)kv.Val(), "0")) throw Err_.new_unimplemented(); break;
|
||||
}
|
||||
}
|
||||
Xow_parser_mgr parser_mgr = wiki.Parser_mgr();
|
||||
date = Wbase_date.Parse(time, precision_int, before_int, after_int, calendar_is_julian);
|
||||
Wbase_claim_time.Write_to_bfr(bfr, parser_mgr.Wbase__time__bfr(), parser_mgr.Wbase__time__fmtr()
|
||||
, parser_mgr.Wbase__time__msgs(), page_url, Bry_.Empty, date, calendar_is_julian
|
||||
);
|
||||
}
|
||||
private static void Render__quantity(Bry_bfr bfr, Xol_lang_itm lang, byte[] page_url, Keyval[] kvs) {
|
||||
byte[] amount_bry = null, lbound_bry = null, ubound_bry = null, unit_bry = null;
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = kvs[i];
|
||||
byte val_tid = Wbase_claim_quantity_.To_tid_or_invalid(page_url, kv.Key());
|
||||
byte[] val_bry = Bry_.new_u8((String)kv.Val());
|
||||
switch (val_tid) {
|
||||
case Wbase_claim_quantity_.Tid__amount: amount_bry = val_bry; break;
|
||||
case Wbase_claim_quantity_.Tid__unit: unit_bry = val_bry; break;
|
||||
case Wbase_claim_quantity_.Tid__lowerbound: lbound_bry = val_bry; break;
|
||||
case Wbase_claim_quantity_.Tid__upperbound: ubound_bry = val_bry; break;
|
||||
}
|
||||
}
|
||||
Render__quantity(bfr, lang, amount_bry, lbound_bry, ubound_bry, unit_bry);
|
||||
}
|
||||
private static void Render__quantity(Bry_bfr bfr, Xol_lang_itm lang, byte[] amount_bry, byte[] lbound_bry, byte[] ubound_bry, byte[] unit_bry) {
|
||||
long val = Bry_.To_long_or(amount_bry, Byte_ascii.Comma_bry, 0, amount_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(val));// amount; EX: 1,234
|
||||
long lbound = Bry_.To_long_or(lbound_bry, val);
|
||||
long ubound = Bry_.To_long_or(lbound_bry, val);
|
||||
if (lbound != val && ubound != val) { // NOTE: do not output <20> if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
|
||||
bfr.Add(Wdata_prop_val_visitor.Bry__quantity_margin_of_error); // symbol: EX: <20>
|
||||
bfr.Add(unit_bry); // unit; EX: 1
|
||||
}
|
||||
}
|
||||
private static void Render__geo(Bry_bfr bfr, Xol_lang_itm lang, byte[] page_url, Keyval[] kvs) {
|
||||
double lat = 0, lng = 0;
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = kvs[i];
|
||||
byte val_tid = Wbase_claim_globecoordinate_.To_tid_or_invalid(page_url, kv.Key());
|
||||
switch (val_tid) {
|
||||
case Wbase_claim_globecoordinate_.Tid__latitude: lat = Double_.cast(kv.Val()); break;
|
||||
case Wbase_claim_globecoordinate_.Tid__longitude: lng = Double_.cast(kv.Val()); break;
|
||||
default: break; // ignore others
|
||||
}
|
||||
}
|
||||
Render__geo(bfr, lat, lng);
|
||||
}
|
||||
public static void Render__geo(Bry_bfr bfr, byte[] lat, byte[] lng) {
|
||||
bfr.Add(lat);
|
||||
bfr.Add(Bry__geo_dlm);
|
||||
bfr.Add(lng);
|
||||
}
|
||||
public static void Render__geo(Bry_bfr bfr, double lat, double lng) {
|
||||
bfr.Add_double(lat);
|
||||
bfr.Add(Bry__geo_dlm);
|
||||
bfr.Add_double(lng);
|
||||
}
|
||||
private static void Render__langtext(Bry_bfr bfr, Xol_lang_itm lang, Keyval[] kvs) {
|
||||
bfr.Add_str_u8((String)Scrib_kv_utl_.Get_sub_by_key_or_null(kvs, Wbase_claim_monolingualtext_.Itm__text.Key_str()));
|
||||
}
|
||||
private static final byte[] Bry__geo_dlm = Bry_.new_a7(", ");
|
||||
}
|
||||
@@ -15,13 +15,13 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.htmls.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.apps.apis.xowa.xtns.*; import gplx.xowa.apps.apis.xowa.html.*; import gplx.xowa.users.*;
|
||||
import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.xtns.wdatas.pfuncs.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.hwtrs.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.pfuncs.*; import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
private final Xoae_app app;
|
||||
@@ -70,30 +70,30 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
public byte[] Get_claim_or(Xow_domain_itm domain, Xoa_ttl page_ttl, int pid, byte[] or) {
|
||||
byte[] qid = this.Qid_mgr.Get_or_null(domain.Abrv_wm(), page_ttl); if (qid == null) return or;
|
||||
Wdata_doc wdoc = Doc_mgr.Get_by_bry_or_null(qid); if (wdoc == null) return or;
|
||||
Wdata_claim_grp claim_grp = wdoc.Claim_list_get(pid); if (claim_grp == null || claim_grp.Len() == 0) return or;
|
||||
Wdata_claim_itm_core claim_itm = claim_grp.Get_at(0);
|
||||
Wbase_claim_grp claim_grp = wdoc.Claim_list_get(pid); if (claim_grp == null || claim_grp.Len() == 0) return or;
|
||||
Wbase_claim_base claim_itm = claim_grp.Get_at(0);
|
||||
synchronized (tmp_bfr) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
|
||||
prop_val_visitor.Init(tmp_bfr, hwtr_mgr.Msgs(), domain.Lang_orig_key());
|
||||
claim_itm.Welcome(prop_val_visitor);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
public void Resolve_to_bfr(Bry_bfr bfr, Wdata_claim_grp prop_grp, byte[] lang_key) {
|
||||
public void Resolve_to_bfr(Bry_bfr bfr, Wbase_claim_grp prop_grp, byte[] lang_key) {
|
||||
synchronized (this) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
|
||||
Hwtr_mgr_assert();
|
||||
int len = prop_grp.Len();
|
||||
Wdata_claim_itm_core selected = null;
|
||||
Wbase_claim_base selected = null;
|
||||
for (int i = 0; i < len; i++) { // NOTE: multiple props possible; EX: {{#property:P1082}}; PAGE:en.w:Earth DATE:2015-08-02
|
||||
Wdata_claim_itm_core prop = prop_grp.Get_at(i);
|
||||
Wbase_claim_base prop = prop_grp.Get_at(i);
|
||||
if (selected == null) selected = prop; // if selected not set, set it; will always set to 1st prop
|
||||
if (prop.Rank_tid() == Wdata_dict_rank.Tid_preferred) { // if prop is preferred, select it and exit;
|
||||
if (prop.Rank_tid() == Wbase_claim_rank_.Tid__preferred) { // if prop is preferred, select it and exit;
|
||||
selected = prop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (selected.Snak_tid()) {
|
||||
case 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;
|
||||
case Wbase_claim_value_type_.Tid__novalue : bfr.Add(Wbase_claim_value_type_.Itm__novalue.Key_bry()); break;
|
||||
case Wbase_claim_value_type_.Tid__somevalue : bfr.Add(Wbase_claim_value_type_.Itm__somevalue.Key_bry()); break;
|
||||
default: {
|
||||
prop_val_visitor.Init(bfr, hwtr_mgr.Msgs(), lang_key);
|
||||
selected.Welcome(prop_val_visitor);
|
||||
@@ -165,11 +165,11 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
public static boolean Wiki_page_is_json(int wiki_tid, int ns_id) {
|
||||
switch (wiki_tid) {
|
||||
case Xow_domain_tid_.Int__wikidata:
|
||||
if (ns_id == Xow_ns_.Tid__main || ns_id == gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Ns_property)
|
||||
if (ns_id == Xow_ns_.Tid__main || ns_id == gplx.xowa.xtns.wbases.Wdata_wiki_mgr.Ns_property)
|
||||
return true;
|
||||
break;
|
||||
case Xow_domain_tid_.Int__home:
|
||||
if (ns_id == gplx.xowa.xtns.wdatas.Wdata_wiki_mgr.Ns_property)
|
||||
if (ns_id == gplx.xowa.xtns.wbases.Wdata_wiki_mgr.Ns_property)
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
@@ -15,14 +15,16 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.core.primitives.*; import gplx.langs.jsons.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.guis.*; import gplx.xowa.xtns.wdatas.imports.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.guis.*; import gplx.xowa.xtns.wbases.imports.*; import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.pfuncs.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
public class Wdata_wiki_mgr_fxt {
|
||||
private final Wdata_xwiki_link_wtr wdata_lang_wtr = new Wdata_xwiki_link_wtr();
|
||||
private final Bry_bfr tmp_time_bfr = Bry_bfr_.New();
|
||||
public Xowe_wiki Wiki() {return parser_fxt.Wiki();}
|
||||
public Wdata_wiki_mgr_fxt Init() {return Init(new Xop_fxt(), true);}
|
||||
public Wdata_wiki_mgr_fxt Init(Xop_fxt parser_fxt, boolean reset) {
|
||||
@@ -45,33 +47,33 @@ public class Wdata_wiki_mgr_fxt {
|
||||
}
|
||||
public Wdata_doc_bldr Wdoc_bldr(String qid) {return wdoc_bldr.Qid_(qid);}
|
||||
public Json_doc Make_json(String src) {return app.Utl__json_parser().Parse_by_apos(src);}
|
||||
public 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_u8(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 Make_claim_time(pid, val, Bry_.Empty, Bry_.Empty);}
|
||||
public Wdata_claim_itm_core Make_claim_time(int pid, String val, int precision) {return Make_claim_time(pid, val, Int_.To_bry(precision), Bry_.Empty);}
|
||||
public Wdata_claim_itm_core Make_claim_time(int pid, String val, byte[] precision, byte[] calendar) {
|
||||
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, precision, calendar);
|
||||
public Wbase_claim_base Make_claim_novalue(int pid) {return Wbase_claim_value.New_novalue(pid);}
|
||||
public Wbase_claim_base Make_claim_somevalue(int pid) {return Wbase_claim_value.New_somevalue(pid);}
|
||||
public Wbase_claim_base Make_claim_string(int pid, String val) {return Make_claim_string(pid, Bry_.new_u8(val));}
|
||||
public Wbase_claim_base Make_claim_string(int pid, byte[] val) {return new Wbase_claim_string(pid, Wbase_claim_value_type_.Tid__value, val);}
|
||||
public Wbase_claim_base Make_claim_time(int pid, String val) {return Make_claim_time(pid, val, Bry_.Empty, Bry_.Empty);}
|
||||
public Wbase_claim_base Make_claim_time(int pid, String val, int precision) {return Make_claim_time(pid, val, Int_.To_bry(precision), Bry_.Empty);}
|
||||
public Wbase_claim_base Make_claim_time(int pid, String val, byte[] precision, byte[] calendar) {
|
||||
return new Wbase_claim_time(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_time_.To_bry(tmp_time_bfr, val), Bry_.Empty, Bry_.Empty, Bry_.Empty, precision, calendar);
|
||||
}
|
||||
public 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_u8(lang), Bry_.new_u8(text));}
|
||||
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_a7(amount), Bry_.new_a7(unit), Bry_.new_a7(ubound), Bry_.new_a7(lbound));}
|
||||
public Wdata_claim_itm_core Make_claim_entity_qid(int pid, int val) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_entity_tid.Tid_item, Int_.To_bry(val));}
|
||||
public Wdata_claim_itm_core Make_claim_entity_pid(int pid, int val) {return new Wdata_claim_itm_entity(pid, Wdata_dict_snak_tid.Tid_value, Wdata_dict_value_entity_tid.Tid_property, Int_.To_bry(val));}
|
||||
public Wdata_claim_itm_core Make_claim_geo(int pid, String lon, String lat) {return Make_claim_geo(pid, lon, lat, ".00001", null, "http://www.wikidata.org/entity/Q2");}
|
||||
public Wdata_claim_itm_core Make_claim_geo(int pid, String lon, String lat, String prc, String alt, String glb) {
|
||||
return new Wdata_claim_itm_globecoordinate(pid, Wdata_dict_snak_tid.Tid_value, Bry_.new_a7(lat), Bry_.new_a7(lon), Bry_.new_a7(alt), Bry_.new_a7(prc), Bry_.new_a7(glb));
|
||||
public Wbase_claim_base Make_claim_monolingual(int pid, String lang, String text) {return new Wbase_claim_monolingualtext(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_u8(lang), Bry_.new_u8(text));}
|
||||
public Wbase_claim_base Make_claim_quantity(int pid, String amount, String unit, String ubound, String lbound) {return new Wbase_claim_quantity(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_a7(amount), Bry_.new_a7(unit), Bry_.new_a7(ubound), Bry_.new_a7(lbound));}
|
||||
public Wbase_claim_base Make_claim_entity_qid(int pid, int val) {return new Wbase_claim_entity(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_entity_type_.Tid__item, Int_.To_bry(val));}
|
||||
public Wbase_claim_base Make_claim_entity_pid(int pid, int val) {return new Wbase_claim_entity(pid, Wbase_claim_value_type_.Tid__value, Wbase_claim_entity_type_.Tid__property, Int_.To_bry(val));}
|
||||
public Wbase_claim_base Make_claim_geo(int pid, String lon, String lat) {return Make_claim_geo(pid, lon, lat, ".00001", null, "http://www.wikidata.org/entity/Q2");}
|
||||
public Wbase_claim_base Make_claim_geo(int pid, String lon, String lat, String prc, String alt, String glb) {
|
||||
return new Wbase_claim_globecoordinate(pid, Wbase_claim_value_type_.Tid__value, Bry_.new_a7(lat), Bry_.new_a7(lon), Bry_.new_a7(alt), Bry_.new_a7(prc), Bry_.new_a7(glb));
|
||||
}
|
||||
public 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();
|
||||
public Wbase_claim_grp Make_qualifiers_grp(int pid, Wbase_claim_base... ary) {return new Wbase_claim_grp(Int_obj_ref.New(pid), ary);}
|
||||
public Wbase_claim_grp_list Make_qualifiers(Wbase_claim_grp... ary) {
|
||||
Wbase_claim_grp_list rv = new Wbase_claim_grp_list();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public Wdata_doc doc_(String qid, Wdata_claim_itm_core... props) {return wdoc_bldr.Qid_(qid).Add_claims(props).Xto_wdoc();}
|
||||
public Wdata_doc doc_(String qid, Wbase_claim_base... props) {return wdoc_bldr.Qid_(qid).Add_claims(props).Xto_wdoc();}
|
||||
public void Init_xwikis_add(String... prefixes) {
|
||||
int len = prefixes.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -94,7 +96,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
regy_mgr.Create(ttl_bry);
|
||||
regy_mgr.Save();
|
||||
|
||||
Bry_bfr bfr = app.Utl__bfr_mkr().Get_b512().Mkr_rls();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
byte[] itm = bfr.Add(ttl_bry).Add_byte(Byte_ascii.Pipe).Add(Bry_.new_a7(qid)).Add_byte_nl().To_bry_and_clear();
|
||||
Xob_xdat_file xdat_file = new Xob_xdat_file();
|
||||
xdat_file.Insert(bfr, itm);
|
||||
@@ -120,7 +122,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
Tfds.Eq(expd, String_.new_u8(qid_ttl));
|
||||
}
|
||||
public void Test_parse_pid_null(String val) {Test_parse_pid(val, Wdata_wiki_mgr.Pid_null);}
|
||||
public void Test_parse_pid(String val, int expd) {Tfds.Eq(expd, Wdata_pf_property.Parse_pid(num_parser, Bry_.new_a7(val)));} private Number_parser num_parser = new Number_parser();
|
||||
public void Test_parse_pid(String val, int expd) {Tfds.Eq(expd, Wdata_pf_property.Parse_pid(num_parser, Bry_.new_a7(val)));} private Gfo_number_parser num_parser = new Gfo_number_parser();
|
||||
public void Init__docs__add(Wdata_doc page) {wdata_mgr.Doc_mgr.Add(page.Qid(), page);}
|
||||
public void Test_parse(String raw, String expd) {
|
||||
parser_fxt.Test_parse_page_tmpl_str(raw, expd);
|
||||
@@ -15,8 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*; import gplx.xowa.xtns.wdatas.imports.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*; import gplx.xowa.xtns.wbases.imports.*;
|
||||
public class Wdata_wiki_mgr_tst {
|
||||
@Test public void Basic() {
|
||||
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.bldrs.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
@@ -15,10 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.pfuncs.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.pfuncs.*;
|
||||
public class Wdata_xwiki_link_wtr implements gplx.core.brys.Bfr_arg {
|
||||
public Wdata_xwiki_link_wtr Page_(Xoae_page page) {this.page = page; return this;} private Xoae_page page;
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
|
||||
import org.junit.*; import gplx.langs.jsons.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Wdata_xwiki_link_wtr_tst {
|
||||
@@ -15,20 +15,21 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.core.primitives.*;
|
||||
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;}
|
||||
import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
public class Wbase_claim_grp {
|
||||
public Wbase_claim_grp(Int_obj_ref id_ref, Wbase_claim_base[] itms) {this.id_ref = id_ref; this.itms = itms;}
|
||||
public Int_obj_ref Id_ref() {return id_ref;} private final Int_obj_ref id_ref;
|
||||
public int Id() {return id_ref.Val();}
|
||||
public String Id_str() {if (id_str == null) id_str = "P" + Int_.To_str(id_ref.Val()); return id_str;} private String id_str;
|
||||
public int Len() {return itms.length;} private Wdata_claim_itm_core[] itms;
|
||||
public Wdata_claim_itm_core Get_at(int i) {return itms[i];}
|
||||
public int Len() {return itms.length;} private Wbase_claim_base[] itms;
|
||||
public Wbase_claim_base Get_at(int i) {return itms[i];}
|
||||
public static List_adp Xto_list(Ordered_hash hash) {
|
||||
int len = hash.Count();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Wdata_claim_grp grp = (Wdata_claim_grp)hash.Get_at(i);
|
||||
Wbase_claim_grp grp = (Wbase_claim_grp)hash.Get_at(i);
|
||||
int grp_len = grp.Len();
|
||||
for (int j = 0; j < grp_len; ++j)
|
||||
rv.Add(grp.Get_at(j));
|
||||
@@ -15,10 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 {
|
||||
package gplx.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wbase_claim_grp_list {
|
||||
private Ordered_hash hash = Ordered_hash_.New();
|
||||
public void Add(Wdata_claim_grp itm) {hash.Add(itm.Id_ref(), itm);}
|
||||
public void Add(Wbase_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.Get_at(i);}
|
||||
public Wbase_claim_grp Get_at(int i) {return (Wbase_claim_grp)hash.Get_at(i);}
|
||||
}
|
||||
@@ -15,13 +15,14 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
public interface Wdata_claim_visitor {
|
||||
void Visit_str(Wdata_claim_itm_str itm);
|
||||
void Visit_entity(Wdata_claim_itm_entity itm);
|
||||
void Visit_monolingualtext(Wdata_claim_itm_monolingualtext itm);
|
||||
void Visit_quantity(Wdata_claim_itm_quantity itm);
|
||||
void Visit_time(Wdata_claim_itm_time itm);
|
||||
void Visit_globecoordinate(Wdata_claim_itm_globecoordinate itm);
|
||||
void Visit_system(Wdata_claim_itm_system itm);
|
||||
package gplx.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
public interface Wbase_claim_visitor {
|
||||
void Visit_str (Wbase_claim_string itm);
|
||||
void Visit_entity (Wbase_claim_entity itm);
|
||||
void Visit_monolingualtext (Wbase_claim_monolingualtext itm);
|
||||
void Visit_quantity (Wbase_claim_quantity itm);
|
||||
void Visit_time (Wbase_claim_time itm);
|
||||
void Visit_globecoordinate (Wbase_claim_globecoordinate itm);
|
||||
void Visit_system (Wbase_claim_value itm);
|
||||
}
|
||||
@@ -15,9 +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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
package gplx.xowa.xtns.wbases.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wbase_references_grp {
|
||||
public Wbase_references_grp(Wbase_claim_grp_list references, int[] references_order) {this.references = references; this.references_order = references_order;}
|
||||
public Wbase_claim_grp_list References() {return references;} private Wbase_claim_grp_list references;
|
||||
public int[] References_order() {return references_order;} private int[] references_order;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_entity_type_ {
|
||||
public static final byte
|
||||
Tid__item = 0
|
||||
, Tid__property = 1
|
||||
;
|
||||
private static final int Ary__len = 2;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__item = New(Tid__item , "item")
|
||||
, Itm__property = New(Tid__property , "property")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_fail(byte[] bry) {return ((Wbase_claim_enum)hash_by_bry.Get_by_or_fail(bry)).Tid();}
|
||||
}
|
||||
@@ -15,18 +15,14 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
public class Wdata_dict_value_string {
|
||||
public static final byte
|
||||
Tid_value = 0
|
||||
, Tid_type = 1
|
||||
;
|
||||
public static byte[]
|
||||
Bry_value = Bry_.new_a7("value")
|
||||
, Bry_type = Bry_.new_a7("type")
|
||||
;
|
||||
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)
|
||||
;
|
||||
}
|
||||
package gplx.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_enum {
|
||||
public Wbase_claim_enum(byte tid, String key_str) {
|
||||
this.tid = tid;
|
||||
this.key_str = key_str;
|
||||
this.key_bry = Bry_.new_u8(key_str);
|
||||
}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public String Key_str() {return key_str;} private final String key_str;
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_enum_ {
|
||||
public static byte To_tid_or_invalid(Hash_adp hash, byte[] url, String key) {
|
||||
Object rv_obj = hash.Get_by(key);
|
||||
if (rv_obj == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown enum key for wikibase; url=~{0} key=~{1}", url, key);
|
||||
return Tid__invalid;
|
||||
}
|
||||
return ((Wbase_claim_enum)rv_obj).Tid();
|
||||
}
|
||||
public static byte To_tid_or_invalid(Hash_adp_bry hash, byte[] url, byte[] key) {
|
||||
Object rv_obj = hash.Get_by_bry(key);
|
||||
if (rv_obj == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown enum key for wikibase; url=~{0} key=~{1}", url, key);
|
||||
return Tid__invalid;
|
||||
}
|
||||
return ((Wbase_claim_enum)rv_obj).Tid();
|
||||
}
|
||||
public static final byte Tid__invalid = Byte_.Max_value_127;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_rank_ {
|
||||
public static final byte // SERIALIZED.MW
|
||||
Tid__preferred = 2
|
||||
, Tid__normal = 1
|
||||
, Tid__deprecated = 0
|
||||
, Tid__unknown = 3
|
||||
;
|
||||
private static final int Ary__len = 4;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__preferred = New(Tid__preferred , "preferred")
|
||||
, Itm__normal = New(Tid__normal , "normal")
|
||||
, Itm__deprecated = New(Tid__deprecated , "deprecated")
|
||||
, Itm__unknown = New(Tid__unknown , "unknown")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
public static byte To_tid_or_unknown(byte[] src) {
|
||||
Object obj = hash_by_bry.Get_by_bry(src);
|
||||
return obj == null ? Tid__unknown : ((Wbase_claim_enum)obj).Tid();
|
||||
}
|
||||
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_type {
|
||||
public Wbase_claim_type(byte tid, String key_str, String key_for_scrib) {
|
||||
this.tid = tid;
|
||||
this.key_str = key_str;
|
||||
this.key_bry = Bry_.new_u8(key_str);
|
||||
this.key_for_scrib = key_for_scrib;
|
||||
}
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public String Key_str() {return key_str;} private final String key_str;
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
|
||||
public String Key_for_scrib() {return key_for_scrib;} private final String key_for_scrib;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_type_ {
|
||||
public static final byte // NOT_SERIALIZED
|
||||
Tid__unknown = 0
|
||||
, Tid__value = 1
|
||||
, Tid__bad = 1
|
||||
, Tid__string = 2
|
||||
, Tid__quantity = 3
|
||||
, Tid__time = 4
|
||||
, Tid__globecoordinate = 5
|
||||
, Tid__monolingualtext = 6
|
||||
, Tid__entity = 7
|
||||
;
|
||||
private static final int Ary__len = 13;
|
||||
private static final Wbase_claim_type[] Ary = new Wbase_claim_type[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_type
|
||||
Itm__unknown = New(Tid__unknown , "unknown")
|
||||
, Itm__bad = New(Tid__bad , "bad") // NOTE: wikidata identifies several entries as "bad"; Q1615351|'s-Graveland, Q107538|Baco; DATE:2013-10-20
|
||||
, Itm__string = New(Tid__string , "string") // EX:wd:Property:P1030
|
||||
, Itm__quantity = New(Tid__quantity , "quantity")
|
||||
, Itm__time = New(Tid__time , "time")
|
||||
, Itm__globecoordinate = New(Tid__globecoordinate , "globecoordinate" , "globe-coordinate")
|
||||
, Itm__monolingualtext = New(Tid__monolingualtext , "monolingualtext")
|
||||
, Itm__entity = New(Tid__entity , "wikibase-entityid" , "wikibase-item")
|
||||
;
|
||||
private static Wbase_claim_type New(byte tid, String key) {return New(tid, key, key);}
|
||||
private static Wbase_claim_type New(byte tid, String key, String scrib) {
|
||||
Wbase_claim_type rv = new Wbase_claim_type(tid, key, scrib);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
public static String To_key_or_unknown(byte tid) {return tid < Ary__len ? Ary[tid].Key_str() : Itm__unknown.Key_str();}
|
||||
public static String To_scrib_or_unknown(byte tid) {return tid < Ary__len ? Ary[tid].Key_for_scrib() : Itm__unknown.Key_str();}
|
||||
public static byte To_tid_or_unknown(byte[] src) {return To_tid_or_unknown(src, 0, src.length);}
|
||||
public static byte To_tid_or_unknown(byte[] src, int bgn, int end) {
|
||||
Object obj = hash_by_bry.Get_by_mid(src, bgn, end);
|
||||
return obj == null ? Tid__unknown : ((Wbase_claim_type)obj).Tid();
|
||||
}
|
||||
public static byte To_tid_or_unknown(String src) {
|
||||
Object obj = hash_by_str.Get_by(src);
|
||||
return obj == null ? Tid__unknown : ((Wbase_claim_type)obj).Tid();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
public class Wbase_claim_value_type_ {
|
||||
public static final byte // SERIALIZED.MW
|
||||
Tid__novalue = 0
|
||||
, Tid__value = 1
|
||||
, Tid__somevalue = 2
|
||||
;
|
||||
private static final int Ary__len = 3;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__novalue = New(Tid__novalue , "novalue")
|
||||
, Itm__value = New(Tid__value , "value")
|
||||
, Itm__somevalue = New(Tid__somevalue , "somevalue")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_fail(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_fail(byte[] bry) {return ((Wbase_claim_enum)hash_by_bry.Get_by_or_fail(bry)).Tid();}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public abstract class Wbase_claim_base implements CompareAble {
|
||||
public Wbase_claim_base(int pid, byte snak_tid) {
|
||||
this.pid = pid;
|
||||
this.snak_tid = snak_tid;
|
||||
}
|
||||
public int Pid() {return pid;} private final int pid;
|
||||
public byte Snak_tid() {return snak_tid;} private final byte snak_tid;
|
||||
public byte Rank_tid() {return rank_tid;} private byte rank_tid = Wbase_claim_rank_.Tid__normal; // TEST: default to normal for tests
|
||||
public String Prop_type() {return Prop_type_statement;} private static final String Prop_type_statement = "statement";
|
||||
public byte[] Wguid() {return wguid;} private byte[] wguid;
|
||||
public Wbase_claim_grp_list Qualifiers() {return qualifiers;} private Wbase_claim_grp_list qualifiers;
|
||||
public int[] Qualifiers_order() {return qualifiers_order;} private int[] qualifiers_order;
|
||||
public Wbase_references_grp[] References() {return references;} private Wbase_references_grp[] references;
|
||||
public abstract byte Val_tid();
|
||||
public abstract void Welcome(Wbase_claim_visitor visitor);
|
||||
|
||||
public void Rank_tid_(byte v) {this.rank_tid = v;}
|
||||
public void Wguid_(byte[] v) {this.wguid = v;}
|
||||
public Wbase_claim_base Qualifiers_(Wbase_claim_grp_list v) {qualifiers = v; return this;}
|
||||
public void Qualifiers_order_(int[] v) {qualifiers_order = v;}
|
||||
public void References_(Wbase_references_grp[] v) {references = v;}
|
||||
|
||||
public int compareTo(Object obj) {
|
||||
Wbase_claim_base comp = (Wbase_claim_base)obj;
|
||||
return Int_.Compare(pid, comp.pid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_entity extends Wbase_claim_base {
|
||||
public Wbase_claim_entity(int pid, byte snak_tid, byte entity_tid, byte[] entity_id_bry) {super(pid, snak_tid);
|
||||
this.entity_tid = entity_tid;
|
||||
this.entity_id_bry = entity_id_bry;
|
||||
this.entity_id = Bry_.To_int(entity_id_bry);
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__entity;}
|
||||
public int Entity_id() {return entity_id;} private final int entity_id;
|
||||
public byte[] Entity_id_bry() {return entity_id_bry;} private final byte[] entity_id_bry;
|
||||
public byte Entity_tid() {return entity_tid;} private final byte entity_tid;
|
||||
public boolean Entity_tid_is_qid() {return entity_tid == Wbase_claim_entity_type_.Tid__item;}
|
||||
public String Entity_tid_str() {return Wbase_claim_entity_type_.To_str_or_fail(entity_tid);}
|
||||
public byte[] Entity_tid_bry() {return Wbase_claim_entity_type_.To_bry_or_fail(entity_tid);}
|
||||
|
||||
public byte[] Page_ttl_db() {
|
||||
return entity_tid == Wbase_claim_entity_type_.Tid__item
|
||||
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_db, entity_id_bry)
|
||||
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, entity_id_bry)
|
||||
;
|
||||
}
|
||||
public byte[] Page_ttl_gui() {
|
||||
return entity_tid == Wbase_claim_entity_type_.Tid__item
|
||||
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_gui, entity_id_bry)
|
||||
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, entity_id_bry)
|
||||
;
|
||||
}
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_entity(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), this.Entity_tid_str(), Int_.To_str(entity_id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_entity_ {
|
||||
public static final byte
|
||||
Tid__entity_type = 0
|
||||
, Tid__numeric_id = 1
|
||||
;
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__entity_type = New(Tid__entity_type , "entity-type")
|
||||
, Itm__numeric_id = New(Tid__numeric_id , "numeric-id")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
return rv;
|
||||
}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_globecoordinate extends Wbase_claim_base {
|
||||
public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {super(pid, snak_tid);
|
||||
this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
|
||||
public byte[] Lat() {return lat;} private final byte[] lat;
|
||||
public byte[] Lng() {return lng;} private final byte[] lng;
|
||||
public byte[] Alt() {return alt;} private final byte[] alt;
|
||||
public byte[] Prc() {return prc;} private final byte[] prc;
|
||||
public byte[] Glb() {return glb;} private final byte[] glb;
|
||||
public byte[] Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
|
||||
|
||||
public void Glb_ttl_(byte[] v) {glb_ttl = v;}
|
||||
public Decimal_adp Prc_as_num() {
|
||||
if (prc_as_num == null)
|
||||
prc_as_num = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
|
||||
return prc_as_num;
|
||||
} private Decimal_adp prc_as_num;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(lat), String_.new_u8(lng), String_.new_u8(alt), String_.new_u8(prc), String_.new_u8(glb));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_globecoordinate_ {
|
||||
public static final byte
|
||||
Tid__latitude = 0
|
||||
, Tid__longitude = 1
|
||||
, Tid__altitude = 2
|
||||
, Tid__precision = 3
|
||||
, Tid__globe = 4
|
||||
;
|
||||
private static final int Ary__len = 5;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__latitude = New(Tid__latitude , "latitude")
|
||||
, Itm__longitude = New(Tid__longitude , "longitude")
|
||||
, Itm__altitude = New(Tid__altitude , "altitude")
|
||||
, Itm__precision = New(Tid__precision , "precision")
|
||||
, Itm__globe = New(Tid__globe , "globe")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
|
||||
public static String
|
||||
Val_globe_dflt_str = "http://www.wikidata.org/entity/Q2"
|
||||
;
|
||||
public static byte[]
|
||||
Val_globe_dflt_bry = Bry_.new_a7(Val_globe_dflt_str)
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_monolingualtext extends Wbase_claim_base {
|
||||
public Wbase_claim_monolingualtext(int pid, byte snak_tid, byte[] lang, byte[] text) {super(pid, snak_tid);
|
||||
this.lang = lang; this.text = text;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__monolingualtext;}
|
||||
public byte[] Lang() {return lang;} private final byte[] lang;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_monolingualtext(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(lang), String_.new_u8(text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_monolingualtext_ {
|
||||
public static final byte
|
||||
Tid__text = 0
|
||||
, Tid__language = 1
|
||||
;
|
||||
private static final int Ary__len = 2;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__text = New(Tid__text , "text")
|
||||
, Itm__language = New(Tid__language , "language")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
}
|
||||
@@ -15,38 +15,40 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.xtns.wdatas.hwtrs.*;
|
||||
public class Wdata_claim_itm_quantity extends Wdata_claim_itm_core { public Wdata_claim_itm_quantity(int pid, byte snak_tid, byte[] amount, byte[] unit, byte[] ubound, byte[] lbound) {
|
||||
this.Ctor(pid, snak_tid);
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_quantity extends Wbase_claim_base {
|
||||
public Wbase_claim_quantity(int pid, byte snak_tid, byte[] amount, byte[] unit, byte[] ubound, byte[] lbound) {super(pid, snak_tid);
|
||||
this.amount = amount; this.unit = unit; this.ubound = ubound; this.lbound = lbound;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_quantity;}
|
||||
public byte[] Amount() {return amount;} private final byte[] amount;
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__quantity;}
|
||||
public byte[] Amount() {return amount;} private final byte[] amount;
|
||||
public byte[] Ubound() {return ubound;} private final byte[] ubound;
|
||||
public byte[] Lbound() {return lbound;} private final byte[] lbound;
|
||||
public byte[] Unit() {return unit;} private final byte[] unit;
|
||||
|
||||
public Decimal_adp Amount_as_num() {
|
||||
if (amount_as_num == null) amount_as_num = To_decimal("amount", amount);
|
||||
return amount_as_num;
|
||||
} private Decimal_adp amount_as_num;
|
||||
public byte[] Ubound() {return ubound;} private final byte[] ubound;
|
||||
public Decimal_adp Ubound_as_num() {
|
||||
if (ubound_as_num == null) ubound_as_num = To_decimal("upper", ubound);
|
||||
return ubound_as_num;
|
||||
} private Decimal_adp ubound_as_num;
|
||||
public byte[] Lbound() {return lbound;} private final byte[] lbound;
|
||||
public Decimal_adp Lbound_as_num() {
|
||||
if (lbound_as_num == null) lbound_as_num = To_decimal("lower", lbound);
|
||||
return lbound_as_num;
|
||||
} private Decimal_adp lbound_as_num;
|
||||
public byte[] Unit() {return unit;} private final byte[] unit;
|
||||
private Decimal_adp To_decimal(String type, byte[] v) {
|
||||
if (v == null) throw Err_.new_("wbase", "value is null", "type", type);
|
||||
int len = v.length; if (len == 0) throw Err_.new_("wbase", "value is empty", "type", type);
|
||||
if (v[0] == Byte_ascii.Plus) v = Bry_.Mid(v, 1);
|
||||
return Decimal_adp_.parse(String_.new_a7(v));
|
||||
}
|
||||
@Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_quantity(this);}
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_quantity(this);}
|
||||
@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_u8(amount), String_.new_u8(unit), String_.new_u8(ubound), String_.new_u8(lbound));
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(amount), String_.new_u8(unit), String_.new_u8(ubound), String_.new_u8(lbound));
|
||||
}
|
||||
public static final byte[] Unit_1 = Bry_.new_a7("1");
|
||||
public static final byte[] Unit_1 = Bry_.new_a7("1");
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_quantity_ {
|
||||
public static final byte
|
||||
Tid__amount = 0
|
||||
, Tid__unit = 1
|
||||
, Tid__upperbound = 2
|
||||
, Tid__lowerbound = 3
|
||||
;
|
||||
private static final int Ary__len = 4;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__amount = New(Tid__amount , "amount")
|
||||
, Itm__unit = New(Tid__unit , "unit")
|
||||
, Itm__upperbound = New(Tid__upperbound , "upperBound")
|
||||
, Itm__lowerbound = New(Tid__lowerbound , "lowerBound")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
}
|
||||
@@ -15,16 +15,17 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.xtns.wdatas.hwtrs.*;
|
||||
public class Wdata_claim_itm_str extends Wdata_claim_itm_core { public Wdata_claim_itm_str(int pid, byte snak_tid, byte[] val) {
|
||||
this.Ctor(pid, snak_tid);
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_string extends Wbase_claim_base {
|
||||
public Wbase_claim_string(int pid, byte snak_tid, byte[] val) {super(pid, snak_tid);
|
||||
this.val = val;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wdata_dict_val_tid.Tid_string;}
|
||||
public byte[] Val_str() {return val;} private final byte[] val;
|
||||
@Override public void Welcome(Wdata_claim_visitor visitor) {visitor.Visit_str(this);}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__string;}
|
||||
public byte[] Val_str() {return val;} private final byte[] val;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_str(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wdata_dict_snak_tid.Xto_str(this.Snak_tid()), Wdata_dict_val_tid.Xto_str(this.Val_tid()), String_.new_u8(val));
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(val));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
public class Wbase_claim_time extends Wbase_claim_base {
|
||||
public Wbase_claim_time(int pid, byte snak_tid, byte[] time, byte[] timezone, byte[] before, byte[] after, byte[] precision, byte[] calendar) {super(pid, snak_tid);
|
||||
this.time = time; this.before = before; this.after = after; this.precision = precision; this.calendar = calendar;
|
||||
}
|
||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__time;}
|
||||
public byte[] Time() {return time;} private final byte[] time;
|
||||
public byte[] Before() {return before;} private final byte[] before;
|
||||
public byte[] After() {return after;} private final byte[] after;
|
||||
public byte[] Precision() {return precision;} private final byte[] precision;
|
||||
public byte[] Calendar() {return calendar;} private final byte[] calendar;
|
||||
public byte[] Calendar_ttl() {return calendar_ttl;} private byte[] calendar_ttl;
|
||||
public boolean Calendar_is_julian() {return Bry_.Eq(calendar, Calendar_julian);}
|
||||
|
||||
public void Calendar_ttl_(byte[] v) {calendar_ttl = v;}
|
||||
|
||||
public Wbase_date Time_as_date() {
|
||||
if (time_as_date == null) time_as_date = Wbase_date.Parse(time, this.Precision_int(), this.Before_int(), this.After_int(), this.Calendar_is_julian());
|
||||
return time_as_date;
|
||||
} private Wbase_date time_as_date;
|
||||
public int Precision_int() {
|
||||
if (precision_int == Int_.Min_value) {
|
||||
precision_int = Bry_.To_int_or(precision, -1);
|
||||
if (precision_int == -1) {
|
||||
precision_int = Wbase_date.Fmt_ymdhns;
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown precision: ~{0}", String_.new_u8(precision));
|
||||
}
|
||||
}
|
||||
return precision_int;
|
||||
} private int precision_int = Int_.Min_value;
|
||||
public int Before_int() {
|
||||
if (before_int == Int_.Min_value) {
|
||||
before_int = Bry_.To_int_or(before, -1);
|
||||
if (before_int == -1) {
|
||||
before_int = 0;
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown before: ~{0}", String_.new_u8(before));
|
||||
}
|
||||
}
|
||||
return before_int;
|
||||
} private int before_int = Int_.Min_value;
|
||||
public int After_int() {
|
||||
if (after_int == Int_.Min_value) {
|
||||
after_int = Bry_.To_int_or(after, -1);
|
||||
if (after_int == -1) {
|
||||
after_int = 0;
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown after: ~{0}", String_.new_u8(after));
|
||||
}
|
||||
}
|
||||
return after_int;
|
||||
} private int after_int = Int_.Min_value;
|
||||
|
||||
public void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs, byte[] ttl) {
|
||||
try {
|
||||
Wbase_date date = this.Time_as_date();
|
||||
boolean calendar_is_julian = this.Calendar_is_julian();
|
||||
byte[] calendar_display = null;
|
||||
if (calendar_is_julian) {
|
||||
date = Wbase_date.Xto_julian(date);
|
||||
calendar_display = msgs.Time_julian();
|
||||
}
|
||||
Wbase_date.Xto_str(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
|
||||
if (calendar_display != null)
|
||||
bfr.Add_byte_space().Add(calendar_display);
|
||||
} catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, this.Pid(), Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
public static void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs
|
||||
, byte[] ttl, byte[] pid, Wbase_date date, boolean calendar_is_julian) {
|
||||
try {
|
||||
byte[] calendar_display = null;
|
||||
if (calendar_is_julian) {
|
||||
date = Wbase_date.Xto_julian(date);
|
||||
calendar_display = msgs.Time_julian();
|
||||
}
|
||||
Wbase_date.Xto_str(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
|
||||
if (calendar_display != null)
|
||||
bfr.Add_byte_space().Add(calendar_display);
|
||||
} catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, pid, Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_time(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()), String_.new_u8(time), String_.new_u8(before), String_.new_u8(after), String_.new_u8(precision), String_.new_u8(calendar));
|
||||
}
|
||||
public static final byte[] Calendar_julian = Bry_.new_a7("http://www.wikidata.org/entity/Q1985786");
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*;
|
||||
public class Wbase_claim_time_ {
|
||||
public static final byte
|
||||
Tid__time = 0
|
||||
, Tid__timezone = 1
|
||||
, Tid__before = 2
|
||||
, Tid__after = 3
|
||||
, Tid__precision = 4
|
||||
, Tid__calendarmodel = 5
|
||||
;
|
||||
private static final int Ary__len = 6;
|
||||
private static final Wbase_claim_enum[] Ary = new Wbase_claim_enum[Ary__len];
|
||||
private static final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
|
||||
private static final Hash_adp hash_by_str = Hash_adp_.New();
|
||||
public static final Wbase_claim_enum
|
||||
Itm__time = New(Tid__time , "time")
|
||||
, Itm__timezone = New(Tid__timezone , "timezone")
|
||||
, Itm__before = New(Tid__before , "before")
|
||||
, Itm__after = New(Tid__after , "after")
|
||||
, Itm__precision = New(Tid__precision , "precision")
|
||||
, Itm__calendarmodel = New(Tid__calendarmodel , "calendarmodel")
|
||||
;
|
||||
private static Wbase_claim_enum New(byte tid, String key) {
|
||||
Wbase_claim_enum rv = new Wbase_claim_enum(tid, key);
|
||||
hash_by_bry.Add(rv.Key_bry(), rv);
|
||||
hash_by_str.Add(rv.Key_str(), rv);
|
||||
Ary[tid] = rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String To_str_or_invalid(byte tid) {return Ary[tid].Key_str();}
|
||||
public static byte[] To_bry_or_fail(byte tid) {return Ary[tid].Key_bry();}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, String key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_str, page_url, key);}
|
||||
public static byte To_tid_or_invalid(byte[] page_url, byte[] key) {return Wbase_claim_enum_.To_tid_or_invalid(hash_by_bry, page_url, key);}
|
||||
|
||||
public static final Wbase_data_itm
|
||||
Dflt__precision = Wbase_data_itm.New_int(11)
|
||||
, Dflt__before = Wbase_data_itm.New_int(0)
|
||||
, Dflt__after = Wbase_data_itm.New_int(0)
|
||||
, Dflt__timezone = Wbase_data_itm.New_int(0)
|
||||
, Dflt__calendarmodel = Wbase_data_itm.New_str("http://www.wikidata.org/entity/Q1985727")
|
||||
;
|
||||
|
||||
private static final byte[] Bry_year_prefix = Bry_.new_a7("+0000000");
|
||||
public static byte[] To_bry(Bry_bfr bfr, String date) {return To_bry(bfr, DateAdp_.parse_fmt(date, "yyyy-MM-dd HH:mm:ss"));}
|
||||
public static byte[] To_bry(Bry_bfr bfr, DateAdp date) {// +0000000yyyy-MM-ddTHH:mm:ssZ
|
||||
bfr
|
||||
.Add(Bry_year_prefix)
|
||||
.Add_int_fixed(date.Year(), 4)
|
||||
.Add_byte(Byte_ascii.Dash)
|
||||
.Add_int_fixed(date.Month(), 2)
|
||||
.Add_byte(Byte_ascii.Dash)
|
||||
.Add_int_fixed(date.Day(), 2)
|
||||
.Add_byte(Byte_ascii.Ltr_T)
|
||||
.Add_int_fixed(date.Hour(), 2)
|
||||
.Add_byte(Byte_ascii.Colon)
|
||||
.Add_int_fixed(date.Minute(), 2)
|
||||
.Add_byte(Byte_ascii.Colon)
|
||||
.Add_int_fixed(date.Second(), 2)
|
||||
.Add_byte(Byte_ascii.Ltr_Z)
|
||||
;
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_claim_value extends Wbase_claim_base {
|
||||
public Wbase_claim_value(int pid, byte val_tid, byte snak_tid) {super(pid, snak_tid);
|
||||
this.val_tid = val_tid;
|
||||
}
|
||||
@Override public byte Val_tid() {return val_tid;} private final byte val_tid;
|
||||
|
||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_system(this);}
|
||||
@Override public String toString() {// TEST:
|
||||
return String_.Concat_with_str("|", Wbase_claim_value_type_.To_str_or_fail(this.Snak_tid()), Wbase_claim_type_.To_key_or_unknown(this.Val_tid()));
|
||||
}
|
||||
|
||||
public static Wbase_claim_value New_novalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__novalue);}
|
||||
public static Wbase_claim_value New_somevalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__somevalue);}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
public class Wbase_data_itm {
|
||||
public Wbase_data_itm(int val_int, String val_str, byte[] val_bry) {
|
||||
this.val_int = val_int;
|
||||
this.val_str = val_str;
|
||||
this.val_bry = val_bry;
|
||||
}
|
||||
public int Val_int() {return val_int;} private final int val_int;
|
||||
public String Val_str() {return val_str;} private final String val_str;
|
||||
public byte[] Val_bry() {return val_bry;} private final byte[] val_bry;
|
||||
|
||||
public static Wbase_data_itm New_int(int val) {return new Wbase_data_itm(val, Int_.To_str(val), Int_.To_bry(val));}
|
||||
public static Wbase_data_itm New_str(String val) {return new Wbase_data_itm( -1, val, Bry_.new_u8(val));}
|
||||
}
|
||||
@@ -15,25 +15,25 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.xtns.wdatas.hwtrs.*;
|
||||
public class Wdata_date {
|
||||
public Wdata_date(long year, int month, int day, int hour, int minute, int second, int precision, int before, int after, boolean calendar_is_julian) {
|
||||
import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
public class Wbase_date {
|
||||
public Wbase_date(long year, int month, int day, int hour, int minute, int second, int precision, int before, int after, boolean calendar_is_julian) {
|
||||
this.year = year; this.month = month; this.day = day; this.hour = hour; this.minute = minute; this.second = second;
|
||||
this.precision = precision; this.before = before; this.after = after; this.calendar_is_julian = calendar_is_julian;
|
||||
}
|
||||
public long Year() {return year;} private final long year;
|
||||
public int Month() {return month;} private final int month;
|
||||
public int Day() {return day;} private final int day;
|
||||
public int Hour() {return hour;} private final int hour;
|
||||
public int Minute() {return minute;} private final int minute;
|
||||
public int Second() {return second;} private final int second;
|
||||
public int Precision() {return precision;} private final int precision;
|
||||
public int Before() {return before;} private final int before;
|
||||
public int After() {return after;} private final int after;
|
||||
public boolean Calendar_is_julian() {return calendar_is_julian;} private final boolean calendar_is_julian;
|
||||
public static Wdata_date parse(byte[] date, int precision, int before, int after, boolean calendar_is_julian) {// EX:+00000002001-02-03T04:05:06Z
|
||||
public long Year() {return year;} private final long year;
|
||||
public int Month() {return month;} private final int month;
|
||||
public int Day() {return day;} private final int day;
|
||||
public int Hour() {return hour;} private final int hour;
|
||||
public int Minute() {return minute;} private final int minute;
|
||||
public int Second() {return second;} private final int second;
|
||||
public int Precision() {return precision;} private final int precision;
|
||||
public int Before() {return before;} private final int before;
|
||||
public int After() {return after;} private final int after;
|
||||
public boolean Calendar_is_julian() {return calendar_is_julian;} private final boolean calendar_is_julian;
|
||||
public static Wbase_date Parse(byte[] date, int precision, int before, int after, boolean calendar_is_julian) {// EX:+00000002001-02-03T04:05:06Z
|
||||
int year_sign = 1;
|
||||
switch (date[0]) {
|
||||
case Byte_ascii.Plus: break;
|
||||
@@ -47,9 +47,9 @@ public class Wdata_date {
|
||||
int hour = Bry_.To_int_or(date, year_end + 7, year_end + 9, -1);
|
||||
int minute = Bry_.To_int_or(date, year_end + 10, year_end + 12, -1);
|
||||
int second = Bry_.To_int_or(date, year_end + 13, year_end + 15, -1);
|
||||
return new Wdata_date(year * year_sign, month, day, hour, minute, second, precision, before, after, calendar_is_julian);
|
||||
return new Wbase_date(year * year_sign, month, day, hour, minute, second, precision, before, after, calendar_is_julian);
|
||||
}
|
||||
public static Wdata_date Xto_julian(Wdata_date date) {
|
||||
public static Wbase_date Xto_julian(Wbase_date date) {
|
||||
int a = (int)Math_.Floor((14 - date.Month() / 12));
|
||||
int y = (int)date.Year() + 4800 - a;
|
||||
int m = date.Month() + 12 * a - 3;
|
||||
@@ -61,9 +61,9 @@ public class Wdata_date {
|
||||
int new_y = d - 4800 + (int)Math_.Floor(n / 10);
|
||||
int new_m = n + 3 - 12 * (int)Math_.Floor(n / 10);
|
||||
int new_d = e - (int)Math_.Floor((153 * n + 2) / 5) + 1;
|
||||
return new Wdata_date(new_y, new_m, new_d, date.Hour(), date.Minute(), date.Second(), date.precision, date.before, date.after, date.calendar_is_julian);
|
||||
return new Wbase_date(new_y, new_m, new_d, date.Hour(), date.Minute(), date.Second(), date.precision, date.before, date.after, date.calendar_is_julian);
|
||||
}
|
||||
public static void Xto_str(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wdata_date date) {
|
||||
public static void Xto_str(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
|
||||
boolean calendar_is_julian = date.calendar_is_julian;
|
||||
if (calendar_is_julian)
|
||||
date = Xto_julian(date);
|
||||
@@ -73,19 +73,19 @@ public class Wdata_date {
|
||||
int precision = date.precision;
|
||||
byte[] time_spr = msgs.Sym_time_spr();
|
||||
switch (precision) {
|
||||
case Wdata_date.Fmt_ym: // EX: "Feb 2001"
|
||||
case Wbase_date.Fmt_ym: // EX: "Feb 2001"
|
||||
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(year);
|
||||
break;
|
||||
case Wdata_date.Fmt_ymd: // EX: "3 Feb 2001"
|
||||
case Wbase_date.Fmt_ymd: // EX: "3 Feb 2001"
|
||||
bfr.Add_int_variable(date.Day());
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(date.Year());
|
||||
break;
|
||||
case Wdata_date.Fmt_ymdh: // EX: "4:00 3 Feb 2011"
|
||||
case Wbase_date.Fmt_ymdh: // EX: "4:00 3 Feb 2011"
|
||||
bfr.Add_int_variable(date.Hour());
|
||||
bfr.Add(time_spr);
|
||||
bfr.Add_int_fixed(0, 2);
|
||||
@@ -96,7 +96,7 @@ public class Wdata_date {
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_long_variable(date.Year());
|
||||
break;
|
||||
case Wdata_date.Fmt_ymdhn: // EX: "4:05 3 Feb 2011"
|
||||
case Wbase_date.Fmt_ymdhn: // EX: "4:05 3 Feb 2011"
|
||||
bfr.Add_int_variable(date.Hour());
|
||||
bfr.Add(time_spr);
|
||||
bfr.Add_int_fixed(date.Minute(), 2);
|
||||
@@ -129,7 +129,7 @@ public class Wdata_date {
|
||||
bfr.Add(msgs.Time_julian());
|
||||
Xto_str_beforeafter(bfr, tmp_fmtr, tmp_bfr, msgs, date);
|
||||
}
|
||||
private static void Xto_str_beforeafter(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wdata_date date) {
|
||||
private static void Xto_str_beforeafter(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
|
||||
byte[] bry = null;
|
||||
int before = date.before;
|
||||
int after = date.after;
|
||||
@@ -150,7 +150,7 @@ public class Wdata_date {
|
||||
bfr.Add_byte_space().Add(bry);
|
||||
}
|
||||
}
|
||||
private static void Xto_str_fmt_y(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wdata_date date, int precision) {
|
||||
private static void Xto_str_fmt_y(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date, int precision) {
|
||||
int year_pow = 9 - precision;
|
||||
byte[] year_fmt = msgs.Ary()[msgs.Time_year_idx() + year_pow];
|
||||
long year = date.Year();
|
||||
@@ -15,11 +15,11 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
|
||||
import org.junit.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wdatas.core.*; import gplx.xowa.xtns.wdatas.parsers.*; import gplx.xowa.xtns.wdatas.hwtrs.*;
|
||||
public class Wdata_date_tst {
|
||||
@Before public void init() {fxt.Clear();} private Wdata_date_fxt fxt = new Wdata_date_fxt();
|
||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.hwtrs.*;
|
||||
public class Wbase_date_tst {
|
||||
@Before public void init() {fxt.Clear();} private Wbase_date_fxt fxt = new Wbase_date_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse("+00000002001-02-03T04:05:06Z", 2001, 2, 3, 4, 5, 6);
|
||||
fxt.Test_parse("-98765432109-02-03T04:05:06Z", -98765432109L, 2, 3, 4, 5, 6);
|
||||
@@ -29,11 +29,11 @@ public class Wdata_date_tst {
|
||||
}
|
||||
@Test public void Xto_str() {
|
||||
String date = "+00000002001-02-03T04:05:06Z";
|
||||
fxt.Test_xto_str(date, Wdata_date.Fmt_ym , "Feb 2001");
|
||||
fxt.Test_xto_str(date, Wdata_date.Fmt_ymd , "3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wdata_date.Fmt_ymdh , "4:00 3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wdata_date.Fmt_ymdhn , "4:05 3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wdata_date.Fmt_ymdhns , "4:05:06 3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ym , "Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymd , "3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdh , "4:00 3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhn , "4:05 3 Feb 2001");
|
||||
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhns , "4:05:06 3 Feb 2001");
|
||||
}
|
||||
@Test public void Xto_str_year() {
|
||||
fxt.Test_xto_str("+00000001970-01-01T00:00:00Z", 9, "1970");
|
||||
@@ -45,30 +45,30 @@ public class Wdata_date_tst {
|
||||
fxt.Test_xto_str("+00000123456-01-01T00:00:00Z", 4, "in 100,000 years");
|
||||
}
|
||||
@Test public void Xto_str_julian() {
|
||||
fxt.Init_calendar_is_julian_(Bool_.Y).Test_xto_str("+00000001600-01-02T00:00:00Z", Wdata_date.Fmt_ymd, "18 Jan 1600<sup>jul</sup>");
|
||||
fxt.Init_calendar_is_julian_(Bool_.Y).Test_xto_str("+00000001600-01-02T00:00:00Z", Wbase_date.Fmt_ymd, "18 Jan 1600<sup>jul</sup>");
|
||||
}
|
||||
@Test public void Xto_str_before_after() {
|
||||
String date = "+00000002001-02-03T04:05:06Z";
|
||||
fxt.Clear().Init_before_(1).Test_xto_str(date, Wdata_date.Fmt_ymd, "3 Feb 2001 (-1)");
|
||||
fxt.Clear().Init_after_ (1).Test_xto_str(date, Wdata_date.Fmt_ymd, "3 Feb 2001 (+1)");
|
||||
fxt.Clear().Init_before_(1).Init_after_(1).Test_xto_str(date, Wdata_date.Fmt_ymd, "3 Feb 2001 (±1)");
|
||||
fxt.Clear().Init_before_(1).Init_after_(2).Test_xto_str(date, Wdata_date.Fmt_ymd, "3 Feb 2001 (-1, +2)");
|
||||
fxt.Clear().Init_before_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1)");
|
||||
fxt.Clear().Init_after_ (1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (+1)");
|
||||
fxt.Clear().Init_before_(1).Init_after_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (±1)");
|
||||
fxt.Clear().Init_before_(1).Init_after_(2).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1, +2)");
|
||||
}
|
||||
}
|
||||
class Wdata_date_fxt {
|
||||
class Wbase_date_fxt {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(16);
|
||||
private Wdata_hwtr_msgs msgs;
|
||||
private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_(); private final Bry_bfr tmp_time_bfr = Bry_bfr_.New_w_size(32);
|
||||
public Wdata_date_fxt Clear() {
|
||||
public Wbase_date_fxt Clear() {
|
||||
init_before = init_after = 0;
|
||||
init_calendar_is_julian = false;
|
||||
return this;
|
||||
}
|
||||
public boolean Init_calendar_is_julian() {return init_calendar_is_julian;} public Wdata_date_fxt Init_calendar_is_julian_(boolean v) {init_calendar_is_julian = v; return this;} private boolean init_calendar_is_julian;
|
||||
public int Init_before() {return init_before;} public Wdata_date_fxt Init_before_(int v) {init_before = v; return this;} private int init_before;
|
||||
public int Init_after() {return init_after;} public Wdata_date_fxt Init_after_(int v) {init_after = v; return this;} private int init_after;
|
||||
public boolean Init_calendar_is_julian() {return init_calendar_is_julian;} public Wbase_date_fxt Init_calendar_is_julian_(boolean v) {init_calendar_is_julian = v; return this;} private boolean init_calendar_is_julian;
|
||||
public int Init_before() {return init_before;} public Wbase_date_fxt Init_before_(int v) {init_before = v; return this;} private int init_before;
|
||||
public int Init_after() {return init_after;} public Wbase_date_fxt Init_after_(int v) {init_after = v; return this;} private int init_after;
|
||||
public void Test_parse(String raw, long expd_y, int expd_m, int expd_d, int expd_h, int expd_n, int expd_s) {
|
||||
Wdata_date actl_date = Wdata_date.parse(Bry_.new_a7(raw), Wdata_date.Fmt_ymdhns, init_before, init_after, init_calendar_is_julian);
|
||||
Wbase_date actl_date = Wbase_date.Parse(Bry_.new_a7(raw), Wbase_date.Fmt_ymdhns, init_before, init_after, init_calendar_is_julian);
|
||||
Tfds.Eq(expd_y, actl_date.Year());
|
||||
Tfds.Eq(expd_m, actl_date.Month());
|
||||
Tfds.Eq(expd_d, actl_date.Day());
|
||||
@@ -77,16 +77,16 @@ class Wdata_date_fxt {
|
||||
Tfds.Eq(expd_s, actl_date.Second());
|
||||
}
|
||||
public void Test_julian(int[] orig_ary, int[] expd) {
|
||||
Wdata_date orig = new Wdata_date(orig_ary[0], orig_ary[1], orig_ary[2], 0, 0, 0, 0, 0, 0, init_calendar_is_julian);
|
||||
Wdata_date actl = Wdata_date.Xto_julian(orig);
|
||||
Wbase_date orig = new Wbase_date(orig_ary[0], orig_ary[1], orig_ary[2], 0, 0, 0, 0, 0, 0, init_calendar_is_julian);
|
||||
Wbase_date actl = Wbase_date.Xto_julian(orig);
|
||||
Tfds.Eq(expd[0], (int)actl.Year(), "y");
|
||||
Tfds.Eq(expd[1], actl.Month(), "m");
|
||||
Tfds.Eq(expd[2], actl.Day(), "d");
|
||||
}
|
||||
public void Test_xto_str(String raw, int precision, String expd) {
|
||||
if (msgs == null) msgs = Wdata_hwtr_msgs.new_en_();
|
||||
Wdata_date date = Wdata_date.parse(Bry_.new_a7(raw), precision, init_before, init_after, init_calendar_is_julian);
|
||||
Wdata_date.Xto_str(tmp_bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
|
||||
Wbase_date date = Wbase_date.Parse(Bry_.new_a7(raw), precision, init_before, init_after, init_calendar_is_julian);
|
||||
Wbase_date.Xto_str(tmp_bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
|
||||
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Wdata_alias_itm implements Wdata_lang_sortable {
|
||||
public Wdata_alias_itm(byte[] lang, byte[][] vals) {this.lang = lang; this.vals = vals;}
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wdata_dict_claim {
|
||||
public static final byte
|
||||
Tid_mainsnak = 0
|
||||
@@ -44,7 +44,7 @@ public class Wdata_dict_claim {
|
||||
, Bry_qualifiers = Bry_.new_a7(Str_qualifiers)
|
||||
, Bry_qualifiers_order = Bry_.new_a7(Str_qualifiers_order)
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_mainsnak , Tid_mainsnak)
|
||||
.Add_bry_byte(Bry_type , Tid_type)
|
||||
.Add_bry_byte(Bry_id , Tid_id)
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wdata_dict_claim_v1 {
|
||||
public static final String
|
||||
Str_m = "m"
|
||||
@@ -24,7 +24,7 @@ public class Wdata_dict_claim_v1 {
|
||||
, Str_rank = "rank"
|
||||
, Str_refs = "refs"
|
||||
;
|
||||
public static final byte[]
|
||||
public static final byte[]
|
||||
Bry_m = Bry_.new_a7(Str_m)
|
||||
, Bry_q = Bry_.new_a7(Str_q)
|
||||
, Bry_g = Bry_.new_a7(Str_g)
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wdata_dict_datavalue {
|
||||
public static final byte
|
||||
Tid_value = 0
|
||||
@@ -32,7 +32,7 @@ public class Wdata_dict_datavalue {
|
||||
, Bry_type = Bry_.new_a7(Str_type)
|
||||
, Bry_error = Bry_.new_a7(Str_error)
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
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)
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wdata_dict_langtext {
|
||||
public static final byte
|
||||
Tid_language = 0
|
||||
@@ -29,7 +29,7 @@ public class Wdata_dict_langtext {
|
||||
Bry_language = Bry_.new_a7(Str_language)
|
||||
, Bry_value = Bry_.new_a7(Str_value)
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_language , Tid_language)
|
||||
.Add_bry_byte(Bry_value , Tid_value)
|
||||
;
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wdata_dict_mainsnak {
|
||||
public static final byte
|
||||
Tid_snaktype = 0
|
||||
@@ -25,15 +25,17 @@ public class Wdata_dict_mainsnak {
|
||||
, Tid_type = 4
|
||||
, Tid_datatype = 5
|
||||
;
|
||||
public static final String
|
||||
Str_datavalue = "datavalue";
|
||||
public static byte[]
|
||||
Bry_snaktype = Bry_.new_a7("snaktype")
|
||||
, Bry_property = Bry_.new_a7("property")
|
||||
, Bry_hash = Bry_.new_a7("hash")
|
||||
, Bry_datavalue = Bry_.new_a7("datavalue")
|
||||
, Bry_datavalue = Bry_.new_a7(Str_datavalue)
|
||||
, Bry_type = Bry_.new_a7("type")
|
||||
, Bry_datatype = Bry_.new_a7("datatype")
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_snaktype , Tid_snaktype)
|
||||
.Add_bry_byte(Bry_property , Tid_property)
|
||||
.Add_bry_byte(Bry_hash , Tid_hash)
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wdata_dict_reference {
|
||||
public static final byte
|
||||
Tid_hash = 0
|
||||
@@ -27,7 +27,7 @@ public class Wdata_dict_reference {
|
||||
, Str_snaks = "snaks"
|
||||
, Str_snaks_order = "snaks-order"
|
||||
;
|
||||
public static final byte[]
|
||||
public static final byte[]
|
||||
Bry_hash = Bry_.new_a7(Str_hash)
|
||||
, Bry_snaks = Bry_.new_a7(Str_snaks)
|
||||
, Bry_snaks_order = Bry_.new_a7(Str_snaks_order)
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Wdata_dict_sitelink {
|
||||
public static final byte
|
||||
Tid_site = 0
|
||||
@@ -32,7 +32,7 @@ public class Wdata_dict_sitelink {
|
||||
, Bry_title = Bry_.new_a7(Str_title)
|
||||
, Bry_badges = Bry_.new_a7(Str_badges)
|
||||
;
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
public static final Hash_adp_bry Dict = Hash_adp_bry.cs()
|
||||
.Add_bry_byte(Bry_site , Tid_site)
|
||||
.Add_bry_byte(Bry_title , Tid_title)
|
||||
.Add_bry_byte(Bry_badges , Tid_badges)
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Wdata_dict_utl {
|
||||
public static byte Get_tid_or_invalid(byte[] qid, Hash_adp_bry dict, byte[] key) {
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
public interface Wdata_lang_sortable {
|
||||
byte[] Lang_code();
|
||||
int Lang_sort(); void Lang_sort_(int v);
|
||||
@@ -15,7 +15,7 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.xowa.apps.apis.xowa.xtns.*;
|
||||
public class Wdata_lang_sorter implements Gfo_evt_itm, gplx.core.lists.ComparerAble {
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
@@ -15,12 +15,12 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Wdata_langtext_itm implements Wdata_lang_sortable {
|
||||
public Wdata_langtext_itm(byte[] lang, byte[] text) {this.lang = lang; this.text = text;}
|
||||
public byte[] Lang() {return lang;} private final byte[] lang;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public byte[] Lang() {return lang;} private final byte[] lang;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public byte[] Lang_code() {return lang;}
|
||||
public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null;
|
||||
@Override public String toString() {// TEST:
|
||||
@@ -15,14 +15,14 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.xtns.wdatas.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
package gplx.xowa.xtns.wbases.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Wdata_sitelink_itm implements Wdata_lang_sortable {
|
||||
public Wdata_sitelink_itm(byte[] site, byte[] name, byte[][] badges) {this.site = site; this.name = name; this.badges = badges;}
|
||||
public byte[] Site() {return site;} private final byte[] site;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public byte[][] Badges() {return badges;} private final byte[][] badges;
|
||||
public byte[] Site() {return site;} private final byte[] site;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public byte[][] Badges() {return badges;} private final byte[][] badges;
|
||||
public byte[] Lang() {return lang;} public void Lang_(byte[] v) {lang = v;} private byte[] lang = Bry_.Empty;
|
||||
public byte[] Lang_code() {return lang;}
|
||||
public int Lang_sort() {return lang_sort;} public void Lang_sort_(int v) {lang_sort = v;} private int lang_sort = Wdata_lang_sorter.Sort_null;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user