mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Html: Move get_elem_val to xo.elem
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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.*;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
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_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" E, 6° 47' 20.4" 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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_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;}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.*;
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user