1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/*
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.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Wdata_external_lang_links_data {
private List_adp langs_list = List_adp_.New(); private Hash_adp_bry langs_hash = Hash_adp_bry.ci_a7(); // ASCII:lang_code
public boolean Enabled() {return enabled;} private boolean enabled; public Wdata_external_lang_links_data Enabled_(boolean v) {enabled = v; return this;}
public boolean Sort() {return sort;} public Wdata_external_lang_links_data Sort_(boolean v) {sort = v; return this;} private boolean sort;
public int Langs_len() {return langs_list.Count();}
public Wdata_external_lang_links_data Langs_add(byte[] v) {langs_hash.Add(v, v); langs_list.Add(v); return this;}
public byte[] Langs_get_at(int i) {return (byte[])langs_list.Get_at(i);}
public boolean Langs_hide(byte[] src, int bgn, int end) {
if (sort) return false;
return langs_hash.Get_by_mid(src, bgn, end) == null;
}
public void Reset() {
enabled = false;
sort = false;
langs_list.Clear();
langs_hash.Clear();
}
public void Parse(Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Pf_func_base pfunc) {
enabled = true;
byte[] argx = pfunc.Eval_argx(ctx, src, caller, self);
if (Bry_.Eq(argx, Key_sort)) {sort = true; return;} // {{noexternallanglinks:*}}; assume it cannot be combined with other langs_hash: EX: {{noexternallanglinks:*|en|fr}}
int args_len = self.Args_len();
Langs_add(argx);
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b128();
for (int i = 0; i < args_len; i++) {
Arg_nde_tkn nde = self.Args_get_by_idx(i);
nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, tmp_bfr); // NOTE: changed from self to caller; DATE:2016-03-16
byte[] lang = tmp_bfr.To_bry_and_clear();
Langs_add(lang);
}
tmp_bfr.Mkr_rls();
}
public static final byte[] Key_sort = new byte[] {Byte_ascii.Star};
}

View File

@@ -0,0 +1,34 @@
/*
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.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Wdata_pf_noExternalLangLinks extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_noexternallanglinks;}
@Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_noExternalLangLinks().Name_(name);}
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
ctx.Page().Wdata_external_lang_links().Parse(ctx, src, caller, self, this);
}
public static void Print_self(Gfo_usr_dlg usr_dlg, Bry_bfr bfr, byte[] src, Xot_invk self, String warn_cls, String warn_fmt, Object... args) {
bfr.Add_mid(src, self.Src_bgn(), self.Src_end());
usr_dlg.Warn_many(GRP_KEY, warn_cls, warn_fmt, args);
}
static final String GRP_KEY = "xowa.xtns.wdata.noexternallanglinks";
}

View File

@@ -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.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
public class Wdata_pf_noExternalLangLinks_tst {
@Before public void init() {fxt.Clear();} Wdata_pf_noExternalLangLinks_fxt fxt = new Wdata_pf_noExternalLangLinks_fxt();
@Test public void Basic() {
fxt.Clear().Expd_enabled_(true).Test_parse("{{noexternallanglinks}}");
fxt.Clear().Expd_enabled_(false).Expd_sort_(false).Expd_langs_().Test_parse("");
}
@Test public void Selected() {
fxt.Clear().Expd_enabled_(true).Expd_langs_("en", "fr").Test_parse("{{noexternallanglinks:en|fr}}");
}
@Test public void Sort() {
fxt.Clear().Expd_enabled_(true).Expd_sort_(true).Expd_langs_().Test_parse("{{noexternallanglinks:*}}");
}
}
class Wdata_pf_noExternalLangLinks_fxt {
public Wdata_pf_noExternalLangLinks_fxt Clear() {
if (parser_fxt == null) {
parser_fxt = new Xop_fxt();
app = parser_fxt.App();
wiki = parser_fxt.Wiki();
data = wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links();
}
expd_sort = expd_enabled = Bool_.__byte;
expd_langs = null;
data.Reset();
return this;
} private Xop_fxt parser_fxt; Xoae_app app; Xowe_wiki wiki; Wdata_external_lang_links_data data;
public Wdata_pf_noExternalLangLinks_fxt Expd_enabled_(boolean v) {expd_enabled = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_enabled;
public Wdata_pf_noExternalLangLinks_fxt Expd_sort_(boolean v) {expd_sort = v ? Bool_.Y_byte : Bool_.N_byte; return this;} private byte expd_sort;
public Wdata_pf_noExternalLangLinks_fxt Expd_langs_(String... v) {expd_langs = v; return this;} private String[] expd_langs;
public void Test_parse(String raw) {
byte[] expd = parser_fxt.Test_parse_tmpl_str_rv(raw);
Tfds.Eq(Bry_.Empty, expd);
if (expd_enabled != Bool_.__byte) Tfds.Eq(expd_enabled == Bool_.Y_byte, data.Enabled());
if (expd_sort != Bool_.__byte) Tfds.Eq(expd_sort == Bool_.Y_byte, data.Sort());
if (expd_langs != null) Tfds.Eq_ary_str(expd_langs, Data_langs_xto_str_ary());
}
String[] Data_langs_xto_str_ary() {
int len = data.Langs_len();
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
rv[i] = String_.new_u8((byte[])data.Langs_get_at(i));
}
return rv;
}
}

View File

@@ -0,0 +1,92 @@
/*
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.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 Wdata_pf_property extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_property;}
@Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_property().Name_(name);}
@Override public void Func_evaluate(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; DATE:2016-07-06
// init
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);
}
}

View File

@@ -0,0 +1,143 @@
/*
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.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_property__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("{{#property:p1}}", "a");
fxt.Test_parse("{{#property:p2}}", "");
}
@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("{{#property:p1}}", "b");
}
@Test public void Entity_fr() { // PURPOSE: non-English wiki should default to English label if non-English label not available; DATE:2013-12-19
fxt.Wiki().Wdata_wiki_lang_(Bry_.new_a7("fr")); // set wiki to French
fxt.Init_links_add("frwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_entity_qid(1, 2))); // create wdata page Q1 with prop entity reference to Q2
fxt.Init__docs__add(fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc()); // create wdata page Q2 with label in en (not fr)
fxt.Test_parse("{{#property:p1}}", "b"); // parse; should get en label
}
@Test public void Entity_missing() { // PURPOSE: wiki may refer to entity that no longer exists; EX: {{#property:p1}} which links to Q1, but p1 links to Q2 and Q2 was deleted; DATE:2014-02-01
fxt.Init_links_add("enwiki", "Test_page", "q1"); // create link for en:Test_page in wikidata
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_entity_qid(1, 2))); // create wdata page Q1 with prop entity reference to Q2; note that Q2 is not created
fxt.Test_parse("{{#property:p1}}", ""); // parse; get ""
}
@Test public void Time() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_time(1, "2012-01-02 03:04:05")));
fxt.Test_parse("{{#property:p1}}", "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 Geodata() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_geo(1, "6.789", "1.2345")));
fxt.Test_parse("{{#property:p1}}", "1° 14' 4.2&quot; E, 6° 47' 20.4&quot; N");
}
@Test public void Quantity__plus_minus__y() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "1", "+1236", "+1232")));
fxt.Test_parse("{{#property:p1}}", "1,234±2");
}
@Test public void Quantity__plus_minus__n() { // PURPOSE:do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "1", "+1234", "+1234")));
fxt.Test_parse("{{#property:p1}}", "1,234");
}
@Test public void Quantity__range() { // PURPOSE:do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "1", "+1236", "+1233")));
fxt.Test_parse("{{#property:p1}}", "1,233-1,236");
}
@Test public void Quantity__long() { // PURPOSE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+4321000000", "1", "4321000000", "4321000000")));
fxt.Test_parse("{{#property:p1}}", "4,321,000,000");
}
@Test public void Quantity__unit__entity() {// PURPOSE: get entity name; EX:{{#invoke:Wikidata|getUnits|P2386|FETCH_WIKIDATA}} PAGE:en.w:Arecibo_Observatory; DATE:2016-10-11
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "http://www.wikidata.org/entity/q2", "+1236", "+1232")));
Wdata_doc wdoc = fxt.doc_("q2", fxt.Make_claim_string(2, "a"));
wdoc.Label_list().Add(Bry_.new_a7("en"), new gplx.xowa.xtns.wbases.core.Wdata_langtext_itm(Bry_.new_a7("en"), Bry_.new_a7("meter")));
fxt.Init__docs__add(wdoc);
fxt.Test_parse("{{#property:p1}}", "1,234±2 meter");
}
@Test public void Quantity__decimal() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234.50", "1", "+1236.75", "+1232.25")));
fxt.Test_parse("{{#property:p1}}", "1,234.5±2.25");
}
@Test public void Monolingualtext() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_monolingual(1, "la", "Lorem ipsum dolor sit amet")));
fxt.Test_parse("{{#property:p1}}", "Lorem ipsum dolor sit amet");
}
@Test public void Novalue() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_novalue(1)));
fxt.Test_parse("{{#property:p1}}", "novalue");
}
@Test public void Somevalue() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_somevalue(1)));
fxt.Test_parse("{{#property:p1}}", "somevalue");
}
@Test public void Multiple() {
fxt.Init_links_add("enwiki", "Test_page", "q1");
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_string(1, "a"), fxt.Make_claim_string(1, "b")));
fxt.Test_parse("{{#property:p1}}", "a"); // only take first; DATE:2015-08-02
}
@Test public void Q() {
fxt.Init_links_add("enwiki", "Test_page", "q2");
fxt.Init__docs__add(fxt.doc_("q2", fxt.Make_claim_string(1, "a")));
fxt.Test_parse("{{#property:p1|q=q2}}", "a");
}
@Test public void Of() {
fxt.Init_links_add("enwiki", "Of_page", "q2");
fxt.Init__docs__add(fxt.doc_("q2", fxt.Make_claim_string(1, "a")));
fxt.Test_parse("{{#property:p1|of=Of_page}}", "a");
}
@Test public void From() {
fxt.Init__docs__add(fxt.doc_("Property:p2", fxt.Make_claim_string(1, "a")));
fxt.Test_parse("{{#property:p1|from=p2}}", "a");
fxt.Test_parse("{{#property:p1|from=}}", "");
}
@Test public void Pid_as_name() {
fxt.Init_links_add("enwiki", "Test_page", "q2");
fxt.Init_pids_add("en", "astronomic symbol", 1);
fxt.Init__docs__add(fxt.doc_("q2", fxt.Make_claim_string(1, "a")));
fxt.Test_parse("{{#property:astronomic symbol}}", "a");
}
@Test public void Empty_arg() { // PURPOSE: {{#property:p1|}} should not fail / warn; DATE:2013-11-15
fxt.Init_links_add("enwiki", "Test_page", "q2");
fxt.Init_pids_add("en", "astronomic symbol", 1);
fxt.Init__docs__add(fxt.doc_("q2", fxt.Make_claim_string(1, "a")));
fxt.Test_parse("{{#property:p1|}}", "a");
}
@Test public void Parse_pid() {
fxt.Test_parse_pid ("p123" , 123); // basic
fxt.Test_parse_pid ("P123" , 123); // uppercase
fxt.Test_parse_pid_null ("population"); // name test
fxt.Test_parse_pid_null ("123"); // missing p
fxt.Test_parse_pid_null (""); // empty String test
}
}

View File

@@ -0,0 +1,55 @@
/*
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.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_property__parse__tst {
@Before public void init() {fxt.Init();} private final Wdata_pf_property_data_fxt fxt = new Wdata_pf_property_data_fxt();
@Test public void Q() {fxt.Init().Run__parse("{{#property:p1|q=q2}}").Chk_q("q2");}
@Test public void Of() {fxt.Init().Run__parse("{{#property:p1|of=Earth}}").Chk_of("Earth");}
@Test public void From() {fxt.Init().Run__parse("{{#property:p1|from=p2}}").Chk_from("p2");}
}
class Wdata_pf_property_data_fxt {
private Xoae_app app; private Wdata_wiki_mgr wdata_mgr; private Xop_fxt parser_fxt;
public Wdata_pf_property_data_fxt Init() {
if (app == null) {
parser_fxt = new Xop_fxt();
app = parser_fxt.App();
wdata_mgr = app.Wiki_mgr().Wdata_mgr();
}
Io_mgr.Instance.InitEngine_mem();
wdata_mgr.Clear();
parser_fxt.Reset();
actl = null;
return this;
}
private Wdata_pf_property_data actl;
public Wdata_pf_property_data_fxt Run__parse(String raw) {
byte[] raw_bry = Bry_.new_u8(raw);
Xowe_wiki wiki = parser_fxt.Wiki(); Xop_ctx ctx = wiki.Parser_mgr().Ctx();
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);
wiki.Parser_mgr().Main().Expand_tmpl(root, ctx, tkn_mkr, raw_bry);
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);
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_of(String v) {Tfds.Eq_bry(v, actl.Of); return this;}
public Wdata_pf_property_data_fxt Chk_from(String v) {Tfds.Eq_bry(v, actl.From); return this;}
}

View File

@@ -0,0 +1,69 @@
/*
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.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.primitives.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Wdata_pf_property_data {
public Wdata_pf_property_data(byte[] of, byte[] q, byte[] from) {
this.Of = of; this.Q = q; this.From = from;
}
public final byte[] Of; // EX: "earth"
public final byte[] Q; // EX: "Q123"
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) {
Bry_bfr tmp_bfr = ctx.Wiki().Utl__bfr_mkr().Get_b512();
byte[] of = null, q = null, from = null;
int args_len = self.Args_len();
for (int i = 0; i < args_len; ++i) {
Arg_nde_tkn nde = self.Args_get_by_idx(i);
// get key; EX: "of=", "q=", "from="
Arg_itm_tkn nde_key = nde.Key_tkn();
int key_bgn = nde_key.Src_bgn(), key_end = nde_key.Src_end();
if (key_bgn == key_end && key_bgn == -1) continue; // null arg; ignore, else will throw warning below; EX: {{#property:p1|}}; DATE:2013-11-15
byte key_tid = atrs_hash.Get_as_byte_or(src, key_bgn, key_end, Byte_.Max_value_127);
switch (key_tid) {
case Byte_.Max_value_127:
ctx.App().Usr_dlg().Warn_many("", "", "unknown key for property: ~{0} ~{1}", String_.new_u8(ctx.Page().Ttl().Full_txt_w_ttl_case()), String_.new_u8(src, self.Src_bgn(), self.Src_end()));
continue;
case Tid__id: // same as "not-found", but don't warn;
continue;
}
// get val
nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, tmp_bfr); // NOTE: changed from self to caller; DATE:2016-03-16
byte[] val = tmp_bfr.To_bry_and_clear();
switch (key_tid) {
case Tid__of: of = val; break;
case Tid__q: q = val; break;
case Tid__from: from = val; break;
default: throw Err_.new_unhandled(key_tid);
}
}
tmp_bfr.Mkr_rls();
return new Wdata_pf_property_data(of, q, from);
}
private static final byte Tid__of = 0, Tid__q = 1, Tid__from = 2, Tid__id = 3;
private static final Hash_adp_bry atrs_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("of" , Tid__of)
.Add_str_byte("q" , Tid__q)
.Add_str_byte("from" , Tid__from) // "from" is alias as "q" except it seems to handle properties; EX: {{#property:p1|from=Q2}} == {{#property:p1|q=Q2}}; EX: {{#property:p1|from=p2}}
.Add_str_byte("id" , Tid__id) // "id" has no effect, but appears in articles; ignore and don't warn; EX:{{#property:P277|id=Q1322933}} PAGE:en.w:Symfony; DATE:2016-08-13
;
}

View File

@@ -0,0 +1,51 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.wbases.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wdata_pf_property_fmt {
public byte[] Separator() {return separator;} private byte[] separator;
public byte[] Value_template() {return value_template;} private byte[] value_template;
public byte[] Qualifier_template() {return qualifier_template;} private byte[] qualifier_template;
public byte[] Qualifier_separator() {return qualifier_separator;} private byte[] qualifier_separator;
public byte[] Qualifiers_wrapper() {return qualifiers_wrapper;} private byte[] qualifiers_wrapper;
public byte[] Qualifiers_template() {return qualifiers_template;} private byte[] qualifiers_template;
public byte[] Qualifiers_value_separator() {return qualifiers_value_separator;} private byte[] qualifiers_value_separator;
public byte[] Reference_keyvalue_template() {return reference_keyvalue_template;} private byte[] reference_keyvalue_template;
public byte[] Reference_wrapper() {return reference_wrapper;} private byte[] reference_wrapper;
public byte[] References_wrapper() {return references_wrapper;} private byte[] references_wrapper;
public byte[] Reference_keyvalue_separator() {return reference_keyvalue_separator;} private byte[] reference_keyvalue_separator;
public byte[] Reference_template() {return reference_template;} private byte[] reference_template;
public byte[] Reference_value_separator() {return reference_value_separator;} private byte[] reference_value_separator;
public byte[] Reference_separator() {return reference_separator;} private byte[] reference_separator;
public void Init() {
byte[] comma = new byte[] {Byte_ascii.Comma};
separator = comma;
value_template = Bry_.new_a7("{{{value}}} {{{qualifiers}}}{{{references}}}");
qualifier_template = Bry_.new_a7("{{{1}}} {{{2}}}");
qualifier_separator = comma;
qualifiers_wrapper = Bry_.new_a7("{{{1}}}");
qualifiers_template = Bry_.Empty;
qualifiers_value_separator = comma;
reference_keyvalue_template = Bry_.new_a7("{{{1}}} {{{2}}}");
reference_wrapper = Bry_.new_a7("<ref>{{{1}}}</ref>");
references_wrapper = Bry_.new_a7("{{{1}}}");
reference_keyvalue_separator = comma;
reference_template = Bry_.Empty;
reference_value_separator = comma;
reference_separator = Bry_.Empty; // "a separator to use between each reference"
}
}

View File

@@ -0,0 +1,29 @@
/*
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.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.langs.jsons.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*;
public class Wdata_pf_wbreponame extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_wbreponame;}
@Override public Pf_func New(int id, byte[] name) {return new Wdata_pf_wbreponame().Name_(name);}
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) {
bfr.Add(Reponame); // NOTE: MW has logic to look for message named "wbreponame", and returning it if it exists; only applies to non-WMF Wikidatas; DATE:2014-09-07
} private static final byte[] Reponame = Bry_.new_a7("Wikidata");
}

View File

@@ -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.pfuncs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
public class Wdata_pf_wbreponame_tst {
@Before public void init() {fxt.Clear();} private Wdata_pf_wbreponame_fxt fxt = new Wdata_pf_wbreponame_fxt();
@Test public void Basic() {
fxt.Test_parse("{{wbreponame}}", "Wikidata");
}
}
class Wdata_pf_wbreponame_fxt {
public Wdata_pf_wbreponame_fxt Clear() {
if (parser_fxt == null) {
parser_fxt = new Xop_fxt();
}
return this;
} private Xop_fxt parser_fxt;
public void Test_parse(String raw, String expd) {
parser_fxt.Test_html_full_str(raw, expd);
}
}