mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-09-29 23:10:52 +00:00
Wikibase.Scribunto: Support #statements keyword
This commit is contained in:
parent
26a56950cd
commit
1ba6f094e3
@ -273,5 +273,6 @@ kwd_mgr.New(Bool_.Y, Xol_kwd_grp_.Id_rev_protectionexpiry, "PROTECTIONEXPIRY");
|
|||||||
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_new_window_link, "#NewWindowLink");
|
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_new_window_link, "#NewWindowLink");
|
||||||
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_categorytree, "#categorytree");
|
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_categorytree, "#categorytree");
|
||||||
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_assessment, "#assessment");
|
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_assessment, "#assessment");
|
||||||
|
kwd_mgr.New(Bool_.N, Xol_kwd_grp_.Id_statements, "#statements");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,8 +235,9 @@ public static final int
|
|||||||
, Id_assessment = 215
|
, Id_assessment = 215
|
||||||
, Id_ttl_root_txt = 216
|
, Id_ttl_root_txt = 216
|
||||||
, Id_ttl_root_url = 217
|
, Id_ttl_root_url = 217
|
||||||
|
, Id_statements = 218
|
||||||
;
|
;
|
||||||
public static final int Id__max = 218;
|
public static final int Id__max = 219;
|
||||||
|
|
||||||
private static byte[] ary_itm_(int id) {
|
private static byte[] ary_itm_(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
@ -458,6 +459,7 @@ case Xol_kwd_grp_.Id_rev_protectionexpiry: return Bry_.new_u8("protectionexpiry"
|
|||||||
case Xol_kwd_grp_.Id_new_window_link: return Bry_.new_u8("newwindowlink");
|
case Xol_kwd_grp_.Id_new_window_link: return Bry_.new_u8("newwindowlink");
|
||||||
case Xol_kwd_grp_.Id_categorytree: return Bry_.new_u8("categorytree");
|
case Xol_kwd_grp_.Id_categorytree: return Bry_.new_u8("categorytree");
|
||||||
case Xol_kwd_grp_.Id_assessment: return Bry_.new_u8("assessment");
|
case Xol_kwd_grp_.Id_assessment: return Bry_.new_u8("assessment");
|
||||||
|
case Xol_kwd_grp_.Id_statements: return Bry_.new_u8("statements");
|
||||||
default: throw Err_.new_unhandled(id);
|
default: throw Err_.new_unhandled(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,6 +245,7 @@ public class Pf_func_ {
|
|||||||
, Xol_kwd_grp_.Id_rev_protectionexpiry
|
, Xol_kwd_grp_.Id_rev_protectionexpiry
|
||||||
, Xol_kwd_grp_.Id_categorytree
|
, Xol_kwd_grp_.Id_categorytree
|
||||||
, Xol_kwd_grp_.Id_assessment
|
, Xol_kwd_grp_.Id_assessment
|
||||||
|
, Xol_kwd_grp_.Id_statements
|
||||||
};
|
};
|
||||||
public static Xot_defn Get_prototype(int id) {
|
public static Xot_defn Get_prototype(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
@ -404,6 +405,7 @@ public class Pf_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_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.wbases.pfuncs.Wdata_pf_property();
|
case Xol_kwd_grp_.Id_property: return new gplx.xowa.xtns.wbases.pfuncs.Wdata_pf_property();
|
||||||
|
case Xol_kwd_grp_.Id_statements: return new gplx.xowa.xtns.wbases.pfuncs.Wdata_pf_statements();
|
||||||
case Xol_kwd_grp_.Id_noexternallanglinks: return new gplx.xowa.xtns.wbases.pfuncs.Wdata_pf_noExternalLangLinks();
|
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_wbreponame: return new gplx.xowa.xtns.wbases.pfuncs.Wdata_pf_wbreponame();
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public class Scrib_lib_wikibase_entity implements Scrib_lib {
|
|||||||
|
|
||||||
// print it
|
// print it
|
||||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||||
wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang);
|
wdata_mgr.Resolve_to_bfr(bfr, prop_grp, lang, Bool_.N);
|
||||||
return rslt.Init_obj(bfr.To_bry_and_rls());
|
return rslt.Init_obj(bfr.To_bry_and_rls());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,16 +17,21 @@ package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xo
|
|||||||
import gplx.core.brys.fmtrs.*;
|
import gplx.core.brys.fmtrs.*;
|
||||||
import gplx.xowa.langs.*;
|
import gplx.xowa.langs.*;
|
||||||
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.*; import gplx.xowa.xtns.wbases.claims.itms.times.*;
|
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.*; import gplx.xowa.xtns.wbases.claims.itms.times.*;
|
||||||
public class Wdata_prop_val_visitor implements Wbase_claim_visitor {
|
public class Wdata_prop_val_visitor implements Wbase_claim_visitor { // THREAD.UNSAFE; callers must do synchronized
|
||||||
private Wdata_wiki_mgr wdata_mgr; private Xoae_app app; private Bry_bfr bfr;
|
private Wdata_wiki_mgr wdata_mgr; private Xoae_app app; private Bry_bfr bfr;
|
||||||
private Xol_lang_itm lang;
|
private Xol_lang_itm lang;
|
||||||
private final Bry_bfr tmp_time_bfr = Bry_bfr_.Reset(255); private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_();
|
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;
|
private Wdata_hwtr_msgs msgs;
|
||||||
public Wdata_prop_val_visitor(Xoae_app app, Wdata_wiki_mgr wdata_mgr) {this.app = app; this.wdata_mgr = wdata_mgr;}
|
private boolean mode_is_statements;
|
||||||
public void Init(Bry_bfr bfr, Wdata_hwtr_msgs msgs, byte[] lang_key) {
|
public Wdata_prop_val_visitor(Xoae_app app, Wdata_wiki_mgr wdata_mgr) {
|
||||||
|
this.app = app; this.wdata_mgr = wdata_mgr;
|
||||||
|
}
|
||||||
|
public void Init(Bry_bfr bfr, Wdata_hwtr_msgs msgs, byte[] lang_key, boolean mode_is_statements) {
|
||||||
|
// init some member variables;
|
||||||
this.bfr = bfr; this.msgs = msgs;
|
this.bfr = bfr; this.msgs = msgs;
|
||||||
this.lang = app.Lang_mgr().Get_by(lang_key);
|
this.lang = app.Lang_mgr().Get_by(lang_key);
|
||||||
if (lang == null) lang = app.Lang_mgr().Lang_en(); // TEST: needed for one test; DATE:2016-10-20
|
if (lang == null) lang = app.Lang_mgr().Lang_en(); // TEST: needed for one test; DATE:2016-10-20
|
||||||
|
this.mode_is_statements = mode_is_statements;
|
||||||
}
|
}
|
||||||
public void Visit_str(Wbase_claim_string itm) {Write_str(bfr, itm.Val_bry());}
|
public void Visit_str(Wbase_claim_string itm) {Write_str(bfr, itm.Val_bry());}
|
||||||
public static void Write_str(Bry_bfr bfr, byte[] bry) {bfr.Add(bry);}
|
public static void Write_str(Bry_bfr bfr, byte[] bry) {bfr.Add(bry);}
|
||||||
@ -43,15 +48,34 @@ public class Wdata_prop_val_visitor implements Wbase_claim_visitor {
|
|||||||
}
|
}
|
||||||
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {Write_langtext(bfr, itm.Text());}
|
public void Visit_monolingualtext(Wbase_claim_monolingualtext itm) {Write_langtext(bfr, itm.Text());}
|
||||||
public static void Write_langtext(Bry_bfr bfr, byte[] text) {bfr.Add(text);} // phrase only; PAGE:en.w:Alberta; EX: {{#property:motto}} -> "Fortis et libre"; DATE:2014-08-28
|
public static void Write_langtext(Bry_bfr bfr, byte[] text) {bfr.Add(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) {Write_entity(bfr, wdata_mgr, lang.Key_bry(), itm.Page_ttl_db());}
|
public void Visit_entity(Wbase_claim_entity itm) {Write_entity(bfr, wdata_mgr, lang.Key_bry(), itm.Page_ttl_db(), mode_is_statements);}
|
||||||
public static void Write_entity(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, byte[] lang_key, byte[] entity_ttl_db) {
|
public static void Write_entity(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, byte[] lang_key, byte[] entity_ttl_db, boolean mode_is_statements) {
|
||||||
|
// get entity
|
||||||
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(entity_ttl_db);
|
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(entity_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
|
|
||||||
|
// 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
|
||||||
|
if (entity_doc == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// get label
|
||||||
byte[] label = entity_doc.Label_list__get(lang_key);
|
byte[] label = entity_doc.Label_list__get(lang_key);
|
||||||
if (label == null && !Bry_.Eq(lang_key, Xol_lang_itm_.Key_en)) // NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19
|
|
||||||
|
// NOTE: some properties may not exist in language of wiki; default to english; DATE:2013-12-19
|
||||||
|
if (label == null && !Bry_.Eq(lang_key, Xol_lang_itm_.Key_en))
|
||||||
label = entity_doc.Label_list__get(Xol_lang_itm_.Key_en);
|
label = entity_doc.Label_list__get(Xol_lang_itm_.Key_en);
|
||||||
if (label != null) // if label is still not found, don't add null reference
|
|
||||||
bfr.Add(label);
|
// if label is still not found, don't add null reference
|
||||||
|
if (label != null) {
|
||||||
|
// if statements, add "[[entity_val]]"
|
||||||
|
if (mode_is_statements) {
|
||||||
|
bfr.Add(gplx.xowa.parsers.tmpls.Xop_tkn_.Lnki_bgn);
|
||||||
|
bfr.Add(label);
|
||||||
|
bfr.Add(gplx.xowa.parsers.tmpls.Xop_tkn_.Lnki_end);
|
||||||
|
}
|
||||||
|
// else, just add "entity_val"
|
||||||
|
else
|
||||||
|
bfr.Add(label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void Visit_quantity(Wbase_claim_quantity itm) {Write_quantity(bfr, wdata_mgr, lang, itm.Amount(), itm.Lbound(), itm.Ubound(), itm.Unit());}
|
public void Visit_quantity(Wbase_claim_quantity itm) {Write_quantity(bfr, wdata_mgr, lang, itm.Amount(), itm.Lbound(), itm.Ubound(), itm.Unit());}
|
||||||
public static void Write_quantity(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, Xol_lang_itm lang, byte[] val_bry, byte[] lo_bry, byte[] hi_bry, byte[] unit) {
|
public static void Write_quantity(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, Xol_lang_itm lang, byte[] val_bry, byte[] lo_bry, byte[] hi_bry, byte[] unit) {
|
||||||
|
@ -102,7 +102,7 @@ public class Wdata_prop_val_visitor_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
entity_id = Wbase_claim_entity.To_xid__db(entity_tid, entity_id); // get p/q and number; PAGE:en.v:Mongolia; EX: [numeric-id=6498663, entity-type=item]; DATE:2016-10-18
|
entity_id = Wbase_claim_entity.To_xid__db(entity_tid, entity_id); // get p/q and number; PAGE:en.v:Mongolia; EX: [numeric-id=6498663, entity-type=item]; DATE:2016-10-18
|
||||||
Wdata_prop_val_visitor.Write_entity(bfr, wdata_mgr, lang.Key_bry(), entity_id);
|
Wdata_prop_val_visitor.Write_entity(bfr, wdata_mgr, lang.Key_bry(), entity_id, Bool_.N);
|
||||||
}
|
}
|
||||||
private static void Write_time(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, Xowe_wiki wiki, byte[] page_url, int pid, byte snak_tid, Keyval[] kvs) {
|
private static void Write_time(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, Xowe_wiki wiki, byte[] page_url, int pid, byte snak_tid, Keyval[] kvs) {
|
||||||
byte[] time = null, calendar = null;
|
byte[] time = null, calendar = null;
|
||||||
|
@ -92,11 +92,11 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
|||||||
public void Resolve_claim(Bry_bfr rv, Xow_domain_itm domain, Wbase_claim_base claim_itm) {
|
public void Resolve_claim(Bry_bfr rv, Xow_domain_itm domain, Wbase_claim_base claim_itm) {
|
||||||
synchronized (thread_lock) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
|
synchronized (thread_lock) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
|
||||||
if (hwtr_mgr == null) Hwtr_mgr_assert();
|
if (hwtr_mgr == null) Hwtr_mgr_assert();
|
||||||
prop_val_visitor.Init(rv, hwtr_mgr.Msgs(), domain.Lang_orig_key());
|
prop_val_visitor.Init(rv, hwtr_mgr.Msgs(), domain.Lang_orig_key(), Bool_.N);
|
||||||
claim_itm.Welcome(prop_val_visitor);
|
claim_itm.Welcome(prop_val_visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Resolve_to_bfr(Bry_bfr bfr, Wbase_claim_grp prop_grp, byte[] lang_key) {
|
public void Resolve_to_bfr(Bry_bfr bfr, Wbase_claim_grp prop_grp, byte[] lang_key, boolean mode_is_statements) {
|
||||||
synchronized (thread_lock) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
|
synchronized (thread_lock) { // LOCK:must synchronized b/c prop_val_visitor has member bfr which can get overwritten; DATE:2016-07-06
|
||||||
if (hwtr_mgr == null) Hwtr_mgr_assert();
|
if (hwtr_mgr == null) Hwtr_mgr_assert();
|
||||||
int len = prop_grp.Len();
|
int len = prop_grp.Len();
|
||||||
@ -113,7 +113,7 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
|||||||
case Wbase_claim_value_type_.Tid__novalue : bfr.Add(Wbase_claim_value_type_.Itm__novalue.Key_bry()); 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;
|
case Wbase_claim_value_type_.Tid__somevalue : bfr.Add(Wbase_claim_value_type_.Itm__somevalue.Key_bry()); break;
|
||||||
default: {
|
default: {
|
||||||
prop_val_visitor.Init(bfr, hwtr_mgr.Msgs(), lang_key);
|
prop_val_visitor.Init(bfr, hwtr_mgr.Msgs(), lang_key, mode_is_statements);
|
||||||
selected.Welcome(prop_val_visitor);
|
selected.Welcome(prop_val_visitor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class Wdata_wiki_mgr_fxt {
|
|||||||
Tfds.Eq(expd, String_.new_u8(qid_ttl));
|
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_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 Gfo_number_parser num_parser = new Gfo_number_parser();
|
public void Test_parse_pid(String val, int expd) {Tfds.Eq(expd, Wbase_statement_mgr_.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 Init__docs__add(Wdata_doc page) {wdata_mgr.Doc_mgr.Add(page.Qid(), page);}
|
||||||
public void Test_parse(String raw, String expd) {
|
public void Test_parse(String raw, String expd) {
|
||||||
parser_fxt.Test_parse_page_tmpl_str(raw, expd);
|
parser_fxt.Test_parse_page_tmpl_str(raw, expd);
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
|
|
||||||
|
You may use XOWA according to either of these licenses as is most appropriate
|
||||||
|
for your project on a case-by-case basis.
|
||||||
|
|
||||||
|
The terms of each license can be found in the source code repository:
|
||||||
|
|
||||||
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
|
*/
|
||||||
|
package gplx.xowa.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||||
|
import gplx.core.envs.*;
|
||||||
|
import gplx.core.primitives.*;
|
||||||
|
import gplx.xowa.parsers.logs.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*;
|
||||||
|
import gplx.xowa.langs.kwds.*;
|
||||||
|
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||||
|
public class Wbase_statement_mgr_ {
|
||||||
|
public static void Get_wbase_data(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src, Pf_func_base pfunc, boolean mode_is_statements) {
|
||||||
|
// init
|
||||||
|
byte[] pid_ttl = pfunc.Eval_argx(ctx, src, caller, self);
|
||||||
|
Xop_log_property_wkr property_wkr = ctx.Xtn__wikidata__property_wkr();
|
||||||
|
long log_time_bgn = 0;
|
||||||
|
if (property_wkr != null) {
|
||||||
|
log_time_bgn = System_.Ticks();
|
||||||
|
if (!property_wkr.Eval_bgn(ctx.Page(), pid_ttl)) return;
|
||||||
|
}
|
||||||
|
Xoae_app app = ctx.App();
|
||||||
|
Xowe_wiki wiki = ctx.Wiki();
|
||||||
|
Xoa_ttl ttl = ctx.Page().Ttl();
|
||||||
|
Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr(); if (!wdata_mgr.Enabled()) return;
|
||||||
|
|
||||||
|
// get pid_int; EX: {{#property:p123}} -> 123
|
||||||
|
int pid_int = Wbase_statement_mgr_.Parse_pid(app.Utl_num_parser(), pid_ttl); // parse "p123" to "123"
|
||||||
|
if (pid_int == Wdata_wiki_mgr.Pid_null) { // pid_ttl is name; EX: {{#property:road_map}}
|
||||||
|
pid_int = wdata_mgr.Pid_mgr.Get_or_null(wiki.Wdata_wiki_lang(), pid_ttl);
|
||||||
|
if (pid_int == Wdata_wiki_mgr.Pid_null) {
|
||||||
|
Print_self(app.Usr_dlg(), bfr, src, self, "prop_not_found", "prop id not found: ~{0} ~{1} ~{2}", wiki.Domain_str(), ttl.Page_db_as_str(), pid_ttl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get doc from args; EX:{{#property:p123}} -> "current_page"; EX:{{#property:p123|of=Earth}} -> "Q2"; {{#property:p123|q=q2}} -> "Q2"; {{#property:p123|from=p321}} -> "Property:P321"
|
||||||
|
Wdata_pf_property_data doc_data = Wdata_pf_property_data.Parse(ctx, src, caller, self);
|
||||||
|
Wdata_doc doc = Wbase_statement_mgr_.Get_doc(wdata_mgr, wiki, ttl, doc_data);
|
||||||
|
if (doc == null) return; // NOTE: some pages will not have a qid; EX: "Some_unknown_page" will not have a qid in wikidata; if no qid, then all {{#property:p###}} will have no prop_val
|
||||||
|
|
||||||
|
// get val based on pid and doc; EX: {{#property:p123|of=Earth}} -> doc=Q2; pid=123 -> "value of p123 in Q2"
|
||||||
|
Wbase_claim_grp claim_grp = doc.Claim_list_get(pid_int);
|
||||||
|
if (claim_grp == null) return;// NOTE: some props may not exist; EX: "Some_known_page" has a qid of 123 but does not have pid 345 required by {{#property:P345|q=123}}
|
||||||
|
wdata_mgr.Resolve_to_bfr(bfr, claim_grp, wiki.Wdata_wiki_lang(), mode_is_statements); // NOTE: was ctx.Page().Lang().Key_bry(), but fails in simplewiki; DATE:2013-12-02
|
||||||
|
if (property_wkr != null) property_wkr.Eval_end(ctx.Page(), pid_ttl, log_time_bgn);
|
||||||
|
}
|
||||||
|
public static int Parse_pid(Gfo_number_parser num_parser, byte[] bry) {
|
||||||
|
int bry_len = bry.length;
|
||||||
|
if (bry_len < 2) return Wdata_wiki_mgr.Pid_null; // must have at least 2 chars; p#
|
||||||
|
byte b_0 = bry[0];
|
||||||
|
if (b_0 != Byte_ascii.Ltr_p && b_0 != Byte_ascii.Ltr_P) return Wdata_wiki_mgr.Pid_null;
|
||||||
|
num_parser.Parse(bry, 1, bry_len);
|
||||||
|
return num_parser.Has_err() ? Wdata_wiki_mgr.Pid_null : num_parser.Rv_as_int();
|
||||||
|
}
|
||||||
|
private static void Print_self(Gfo_usr_dlg usr_dlg, Bry_bfr bfr, byte[] src, Xot_invk self, String warn_cls, String warn_fmt, Object... args) {
|
||||||
|
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
|
||||||
|
usr_dlg.Log_many("", warn_cls, warn_fmt, args);
|
||||||
|
}
|
||||||
|
public static Wdata_doc Get_doc(Wdata_wiki_mgr wdata_mgr, Xowe_wiki wiki, Xoa_ttl ttl, Wdata_pf_property_data data) {
|
||||||
|
if (Bry_.Len_gt_0(data.Q)) return wdata_mgr.Doc_mgr.Get_by_bry_or_null(data.Q);
|
||||||
|
else if (Bry_.Len_gt_0(data.From)) return wdata_mgr.Doc_mgr.Get_by_xid_or_null(data.From); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
||||||
|
else if (Bry_.Len_gt_0(data.Of)) {
|
||||||
|
Xoa_ttl of_ttl = Xoa_ttl.Parse(wiki, data.Of); if (of_ttl == null) return null;
|
||||||
|
byte[] qid = wdata_mgr.Qid_mgr.Get_or_null(wiki, of_ttl); if (qid == null) return null; // NOTE: for now, use wiki.Lang_key(), not page.Lang()
|
||||||
|
return wdata_mgr.Doc_mgr.Get_by_bry_or_null(qid);
|
||||||
|
}
|
||||||
|
else return wdata_mgr.Doc_mgr.Get_by_ttl_or_null(wiki, ttl);
|
||||||
|
}
|
||||||
|
}
|
@ -14,77 +14,14 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
package gplx.xowa.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||||
import gplx.core.envs.*;
|
|
||||||
import gplx.core.primitives.*;
|
|
||||||
import gplx.xowa.parsers.logs.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*;
|
|
||||||
import gplx.xowa.langs.kwds.*;
|
|
||||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||||
|
import gplx.xowa.langs.kwds.*; import gplx.xowa.xtns.pfuncs.*;
|
||||||
public class Wdata_pf_property extends Pf_func_base {
|
public class Wdata_pf_property extends Pf_func_base {
|
||||||
@Override public int Id() {return Xol_kwd_grp_.Id_property;}
|
@Override public int Id() {return Xol_kwd_grp_.Id_property;}
|
||||||
@Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_property().Name_(name);}
|
@Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_property().Name_(name);}
|
||||||
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {// EX: {{#property:p123|}}
|
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {// EX: {{#property:p123|}}
|
||||||
synchronized (this) { // LOCK: must synchronized b/c bfr will later be set as member variable in .Resolve_to_bfr; DATE:2016-07-06
|
synchronized (this) { // LOCK: must synchronized b/c bfr will later be set as member variable in .Resolve_to_bfr; DATE:2016-07-06
|
||||||
// init
|
Wbase_statement_mgr_.Get_wbase_data(bfr, ctx, caller, self, src, this, Bool_.N);
|
||||||
byte[] pid_ttl = Eval_argx(ctx, src, caller, self);
|
|
||||||
Xop_log_property_wkr property_wkr = ctx.Xtn__wikidata__property_wkr();
|
|
||||||
long log_time_bgn = 0;
|
|
||||||
if (property_wkr != null) {
|
|
||||||
log_time_bgn = System_.Ticks();
|
|
||||||
if (!property_wkr.Eval_bgn(ctx.Page(), pid_ttl)) return;
|
|
||||||
}
|
|
||||||
Xoae_app app = ctx.App();
|
|
||||||
Xowe_wiki wiki = ctx.Wiki();
|
|
||||||
Xoa_ttl ttl = ctx.Page().Ttl();
|
|
||||||
Wdata_wiki_mgr wdata_mgr = app.Wiki_mgr().Wdata_mgr(); if (!wdata_mgr.Enabled()) return;
|
|
||||||
|
|
||||||
// get pid_int; EX: {{#property:p123}} -> 123
|
|
||||||
int pid_int = Wdata_pf_property.Parse_pid(app.Utl_num_parser(), pid_ttl); // parse "p123" to "123"
|
|
||||||
if (pid_int == Wdata_wiki_mgr.Pid_null) { // pid_ttl is name; EX: {{#property:road_map}}
|
|
||||||
pid_int = wdata_mgr.Pid_mgr.Get_or_null(wiki.Wdata_wiki_lang(), pid_ttl);
|
|
||||||
if (pid_int == Wdata_wiki_mgr.Pid_null) {
|
|
||||||
Print_self(app.Usr_dlg(), bfr, src, self, "prop_not_found", "prop id not found: ~{0} ~{1} ~{2}", wiki.Domain_str(), ttl.Page_db_as_str(), pid_ttl);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get doc from args; EX:{{#property:p123}} -> "current_page"; EX:{{#property:p123|of=Earth}} -> "Q2"; {{#property:p123|q=q2}} -> "Q2"; {{#property:p123|from=p321}} -> "Property:P321"
|
|
||||||
Wdata_pf_property_data doc_data = Wdata_pf_property_data.Parse(ctx, src, caller, self, this);
|
|
||||||
Wdata_doc doc = Wdata_pf_property_.Get_doc(wdata_mgr, wiki, ttl, doc_data);
|
|
||||||
if (doc == null) return; // NOTE: some pages will not have a qid; EX: "Some_unknown_page" will not have a qid in wikidata; if no qid, then all {{#property:p###}} will have no prop_val
|
|
||||||
|
|
||||||
// get val based on pid and doc; EX: {{#property:p123|of=Earth}} -> doc=Q2; pid=123 -> "value of p123 in Q2"
|
|
||||||
Wbase_claim_grp claim_grp = doc.Claim_list_get(pid_int);
|
|
||||||
if (claim_grp == null) return;// NOTE: some props may not exist; EX: "Some_known_page" has a qid of 123 but does not have pid 345 required by {{#property:P345|q=123}}
|
|
||||||
wdata_mgr.Resolve_to_bfr(bfr, claim_grp, wiki.Wdata_wiki_lang()); // NOTE: was ctx.Page().Lang().Key_bry(), but fails in simplewiki; DATE:2013-12-02
|
|
||||||
if (property_wkr != null) property_wkr.Eval_end(ctx.Page(), pid_ttl, log_time_bgn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static int Parse_pid(Gfo_number_parser num_parser, byte[] bry) {
|
|
||||||
int bry_len = bry.length;
|
|
||||||
if (bry_len < 2) return Wdata_wiki_mgr.Pid_null; // must have at least 2 chars; p#
|
|
||||||
byte b_0 = bry[0];
|
|
||||||
if (b_0 != Byte_ascii.Ltr_p && b_0 != Byte_ascii.Ltr_P) return Wdata_wiki_mgr.Pid_null;
|
|
||||||
num_parser.Parse(bry, 1, bry_len);
|
|
||||||
return num_parser.Has_err() ? Wdata_wiki_mgr.Pid_null : num_parser.Rv_as_int();
|
|
||||||
}
|
|
||||||
private static void Print_self(Gfo_usr_dlg usr_dlg, Bry_bfr bfr, byte[] src, Xot_invk self, String warn_cls, String warn_fmt, Object... args) {
|
|
||||||
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
|
|
||||||
usr_dlg.Log_many(GRP_KEY, warn_cls, warn_fmt, args);
|
|
||||||
}
|
|
||||||
public static void Print_empty(Gfo_usr_dlg usr_dlg, String warn_cls, String warn_fmt, Object... args) {
|
|
||||||
usr_dlg.Warn_many(GRP_KEY, warn_cls, warn_fmt, args);
|
|
||||||
}
|
|
||||||
private static final String GRP_KEY = "xowa.xtns.wdata.property";
|
|
||||||
}
|
|
||||||
class Wdata_pf_property_ {
|
|
||||||
public static Wdata_doc Get_doc(Wdata_wiki_mgr wdata_mgr, Xowe_wiki wiki, Xoa_ttl ttl, Wdata_pf_property_data data) {
|
|
||||||
if (Bry_.Len_gt_0(data.Q)) return wdata_mgr.Doc_mgr.Get_by_bry_or_null(data.Q);
|
|
||||||
else if (Bry_.Len_gt_0(data.From)) return wdata_mgr.Doc_mgr.Get_by_xid_or_null(data.From); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"
|
|
||||||
else if (Bry_.Len_gt_0(data.Of)) {
|
|
||||||
Xoa_ttl of_ttl = Xoa_ttl.Parse(wiki, data.Of); if (of_ttl == null) return null;
|
|
||||||
byte[] qid = wdata_mgr.Qid_mgr.Get_or_null(wiki, of_ttl); if (qid == null) return null; // NOTE: for now, use wiki.Lang_key(), not page.Lang()
|
|
||||||
return wdata_mgr.Doc_mgr.Get_by_bry_or_null(qid);
|
|
||||||
}
|
|
||||||
else return wdata_mgr.Doc_mgr.Get_by_ttl_or_null(wiki, ttl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,10 @@ class Wdata_pf_property_data_fxt {
|
|||||||
byte[] raw_bry = Bry_.new_u8(raw);
|
byte[] raw_bry = Bry_.new_u8(raw);
|
||||||
Xowe_wiki wiki = parser_fxt.Wiki(); Xop_ctx ctx = wiki.Parser_mgr().Ctx();
|
Xowe_wiki wiki = parser_fxt.Wiki(); Xop_ctx ctx = wiki.Parser_mgr().Ctx();
|
||||||
Xop_tkn_mkr tkn_mkr = app.Parser_mgr().Tkn_mkr();
|
Xop_tkn_mkr tkn_mkr = app.Parser_mgr().Tkn_mkr();
|
||||||
Wdata_pf_property pfunc = new Wdata_pf_property();
|
|
||||||
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
Xop_root_tkn root = tkn_mkr.Root(raw_bry);
|
||||||
wiki.Parser_mgr().Main().Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
wiki.Parser_mgr().Main().Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
|
||||||
Xot_invk tkn = (Xot_invk)root.Subs_get(0);
|
Xot_invk tkn = (Xot_invk)root.Subs_get(0);
|
||||||
this.actl = Wdata_pf_property_data.Parse(ctx, raw_bry, Xot_invk_mock.Null, tkn, pfunc);
|
this.actl = Wdata_pf_property_data.Parse(ctx, raw_bry, Xot_invk_mock.Null, tkn);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public Wdata_pf_property_data_fxt Chk_q(String v) {Tfds.Eq_bry(v, actl.Q); return this;}
|
public Wdata_pf_property_data_fxt Chk_q(String v) {Tfds.Eq_bry(v, actl.Q); return this;}
|
||||||
|
@ -24,7 +24,7 @@ public class Wdata_pf_property_data {
|
|||||||
public final byte[] Q; // EX: "Q123"
|
public final byte[] Q; // EX: "Q123"
|
||||||
public final byte[] From; // EX: "p2"
|
public final byte[] From; // EX: "p2"
|
||||||
|
|
||||||
public static Wdata_pf_property_data Parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Wdata_pf_property pfunc) {
|
public static Wdata_pf_property_data Parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self) {
|
||||||
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
|
||||||
byte[] of = null, q = null, from = null;
|
byte[] of = null, q = null, from = null;
|
||||||
int args_len = self.Args_len();
|
int args_len = self.Args_len();
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
|
|
||||||
|
You may use XOWA according to either of these licenses as is most appropriate
|
||||||
|
for your project on a case-by-case basis.
|
||||||
|
|
||||||
|
The terms of each license can be found in the source code repository:
|
||||||
|
|
||||||
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
|
*/
|
||||||
|
package gplx.xowa.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||||
|
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||||
|
import gplx.xowa.langs.kwds.*; import gplx.xowa.xtns.pfuncs.*;
|
||||||
|
public class Wdata_pf_statements extends Pf_func_base {
|
||||||
|
@Override public int Id() {return Xol_kwd_grp_.Id_statements;}
|
||||||
|
@Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_statements().Name_(name);}
|
||||||
|
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {// EX: {{#statements:p123|}}
|
||||||
|
synchronized (this) { // LOCK: must synchronized b/c bfr will later be set as member variable in .Resolve_to_bfr; DATE:2016-07-06
|
||||||
|
Wbase_statement_mgr_.Get_wbase_data(bfr, ctx, caller, self, src, this, Bool_.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||||
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
|
|
||||||
|
You may use XOWA according to either of these licenses as is most appropriate
|
||||||
|
for your project on a case-by-case basis.
|
||||||
|
|
||||||
|
The terms of each license can be found in the source code repository:
|
||||||
|
|
||||||
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
|
*/
|
||||||
|
package gplx.xowa.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
||||||
|
import org.junit.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
|
||||||
|
public class Wdata_pf_statements__basic__tst {
|
||||||
|
@Before public void init() {fxt.Init();} private final Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt();
|
||||||
|
@Test public void String() {
|
||||||
|
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||||
|
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_string(1, "a")));
|
||||||
|
fxt.Test_parse("{{#statements:p1}}", "a");
|
||||||
|
}
|
||||||
|
@Test public void Entity() {
|
||||||
|
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||||
|
fxt.Init__docs__add(fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
|
||||||
|
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_entity_qid(1, 2)));
|
||||||
|
fxt.Test_parse("{{#statements:p1}}", "[[b]]");
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
v4.5.0.1703: app_update
|
blog_new_job[D[D[D[D[D[D[D_
|
||||||
|
Loading…
Reference in New Issue
Block a user