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

App: Release v4.5.15.1709

This commit is contained in:
gnosygnu
2017-09-17 22:39:30 -04:00
parent 4ca98f7333
commit ea3f0ffbcc
896 changed files with 69373 additions and 0 deletions

View File

@@ -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; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.langs.jsons.*; import gplx.xowa.wikis.pages.*;
public class Wbase_doc_mgr__tst {
@Before public void init() {fxt.Init();} private final Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt();
@Test public void Redirect() {
// create 2 pages; Q1 redirects to Q2
Wdata_wiki_mgr wbase_mgr = fxt.App().Wiki_mgr().Wdata_mgr();
fxt.Parser_fxt().Init_page_create(wbase_mgr.Wdata_wiki(), "Q1", Json_doc.Make_str_by_apos("{'entity':'q1','redirect':'Q2'}"));
fxt.Parser_fxt().Init_page_create(wbase_mgr.Wdata_wiki(), "Q2", Json_doc.Make_str_by_apos("{'entity':'q2','links':{'enwiki':'q2_en','dewiki':'q2_de'}}"));
// fetch Q1; assert Q2 comes back
Wdata_doc actl = wbase_mgr.Doc_mgr.Load_wdoc_or_null(Bry_.new_u8("Q1"));
Gftest.Eq__str("Q2", String_.new_u8(actl.Qid()));
}
}

View File

@@ -0,0 +1,178 @@
/*
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; 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.wbases.imports.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.wikis.nss.*;
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) {
this.parser_fxt = parser_fxt;
this.wiki = parser_fxt.Wiki();
app = wiki.Appe();
app.Xwiki_mgr__sitelink_mgr().Init_by_app();
wdoc_bldr = new Wdata_doc_bldr();
wdata_mgr = app.Wiki_mgr().Wdata_mgr();
wdata_mgr.Prop_mgr().Loader_(Wbase_prop_mgr_loader_.New_mock());
wdata_mgr.Clear();
if (reset) {
Io_mgr.Instance.InitEngine_mem();
parser_fxt.Reset();
}
return this;
} private Xoae_app app; private Xowe_wiki wiki; private Wdata_doc_bldr wdoc_bldr;
public Xoae_app App() {return app;}
public Wdata_wiki_mgr Wdata_mgr() {return wdata_mgr;} private Wdata_wiki_mgr wdata_mgr;
public Xop_fxt Parser_fxt() {return parser_fxt;} private Xop_fxt parser_fxt;
public void Init_lang_fallbacks(String... fallbacks) {
wiki.Lang().Fallback_bry_(Bry_.new_a7(String_.Concat_with_str(",", fallbacks)));
}
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 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 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 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, 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++) {
String prefix = prefixes[i];
wiki.Xwiki_mgr().Add_by_atrs(prefix, prefix + ".wikipedia.org");
}
}
public void Init_qids_add(String lang_key, int wiki_tid, String ttl, String qid) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
wdata_mgr.Qid_mgr.Add(tmp_bfr, Bry_.new_a7(lang_key), wiki_tid, Bry_.new_a7("000"), Bry_.new_a7(ttl), Bry_.new_a7(qid));
tmp_bfr.Mkr_rls();
}
public void Init_pids_add(String lang_key, String pid_name, int pid) {wdata_mgr.Pid_mgr.Add(Bry_.new_u8(lang_key + "|" + pid_name), pid);}
public void Init_links_add(String wiki, String ttl, String qid) {Init_links_add(wiki, "000", ttl, qid);}
public void Init_links_add(String wiki, String ns_num, String ttl, String qid) {
byte[] ttl_bry = Bry_.new_u8(ttl);
Xowd_regy_mgr regy_mgr = app.Hive_mgr().Regy_mgr();
Io_url regy_fil = wdata_mgr.Wdata_wiki().Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid").GenSubFil_nest(wiki, ns_num, "reg.csv");
regy_mgr.Init(regy_fil);
regy_mgr.Create(ttl_bry);
regy_mgr.Save();
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);
Io_url file_orig = Xob_wdata_qid_base_tst.ttl_(app.Wiki_mgr().Wdata_mgr().Wdata_wiki(), wiki, ns_num, 0);
xdat_file.Save(file_orig);
}
public void Init_external_links_mgr_clear() {wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links().Reset();}
public void Init_external_links_mgr_add(String... langs) {
Wdata_external_lang_links_data external_lang_links = wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links();
external_lang_links.Enabled_(true);
int len = langs.length;
for (int i = 0; i < len; i++) {
String lang = langs[i];
if (String_.Eq(lang, "*"))
external_lang_links.Sort_(true);
else
external_lang_links.Langs_add(Bry_.new_a7(lang));
}
}
public void Test_link(String ttl_str, String expd) {Test_link(Xoa_ttl.Parse(wiki, Xow_ns_.Tid__main, Bry_.new_u8(ttl_str)), expd);}
public void Test_link(Xoa_ttl ttl, String expd) {
byte[] qid_ttl = wdata_mgr.Qid_mgr.Get_or_null(wiki, 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(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 Test_parse(String raw, String expd) {
parser_fxt.Test_parse_page_tmpl_str(raw, expd);
}
public void Test_parse_langs(String raw, String expd) {
// setup langs
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
app.Xwiki_mgr__sitelink_mgr().Parse(Bry_.new_u8(String_.Concat_lines_nl
( "0|grp1"
, "1|en|English"
, "1|fr|French"
, "1|de|German"
, "1|pl|Polish"
)));
wiki.Xwiki_mgr().Add_by_sitelink_mgr();
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_by_csv(Bry_.new_a7(String_.Concat_lines_nl
( "1|en.wikipedia.org|en.wikipedia.org"
, "1|fr.wikipedia.org|fr.wikipedia.org"
, "1|de.wikipedia.org|de.wikipedia.org"
, "1|pl.wikipedia.org|pl.wikipedia.org"
)));
parser_fxt.Page_ttl_("Q1_en");
parser_fxt.Exec_parse_page_all_as_str(raw);
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
wdata_lang_wtr.Page_(page).Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_rls());
}
public void Test_xwiki_links(String ttl, String... expd) {
tmp_langs.Clear();
Wdata_xwiki_link_wtr.Write_wdata_links(tmp_langs, wiki, Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl)), wiki.Parser_mgr().Ctx().Page().Wdata_external_lang_links());
Tfds.Eq_ary_str(expd, Test_xwiki_links_xto_str_ary(tmp_langs));
} List_adp tmp_langs = List_adp_.New();
String[] Test_xwiki_links_xto_str_ary(List_adp list) {
int len = list.Count();
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
Wdata_sitelink_itm itm = (Wdata_sitelink_itm)list.Get_at(i);
rv[i] = String_.new_a7(itm.Page_ttl().Page_db());
}
tmp_langs.Clear();
return rv;
}
public void Test_write_json_as_html(String raw_str, String expd) {
byte[] raw_bry = Bry_.new_a7(raw_str);
raw_bry = gplx.langs.jsons.Json_parser_tst.Replace_apos(raw_bry);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
Wdata_wiki_mgr.Write_json_as_html(wdata_mgr.Jdoc_parser(), bfr, raw_bry);
Tfds.Eq(expd, bfr.To_str_and_rls());
}
}

View File

@@ -0,0 +1,74 @@
/*
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.xtns.wbases.imports.*;
public class Wdata_wiki_mgr_tst {
private final Wdata_prop_val_visitor__fxt fxt = new Wdata_prop_val_visitor__fxt();
@Test public void Basic() {
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
fxt.Init_links_add("enwiki", "Q1", "Q1_en");
fxt.Test_link("Q1", "Q1_en");
fxt.Test_link("Q2", null);
}
@Test public void Case_sensitive() { // PURPOSE: wikidata lkp should be case_sensitive; a vs A DATE:2013-09-03
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
fxt.Init_links_add("enwiki", "Page", "Page_data");
fxt.Test_link("Page", "Page_data");
fxt.Test_link("PAGE", null);
}
@Test public void Non_canonical_ns() { // PURPOSE: handle wikidata entries in non-canonical ns; EX:ukwikisource and Author; PAGE:uk.s:Автор:Богдан_Гаврилишин DATE:2014-07-23
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
Xowe_wiki wiki = fxt.Wiki();
wiki.Ns_mgr().Add_new(124, "Test_ns");
fxt.Init_links_add("enwiki", "000", "Test_ns:Test_page", "pass"); // NOTE: wdata will save to "000" ns, b/c "124" ns is not canonical
Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), 124, Bry_.new_a7("Test_page"));
fxt.Test_link(ttl, "pass");
}
@Test public void Write_json_as_html() {
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
fxt.Test_write_json_as_html("{'a':'b','c':['d','e'],'f':{'g':'<h>'}}", String_.Concat_lines_nl_skip_last
( "<span id=\"xowa-wikidata-json\">"
, "{ \"a\":\"b\""
, ", \"c\":"
, " [ \"d\""
, " , \"e\""
, " ]"
, ", \"f\":"
, " { \"g\":\"&lt;h&gt;\""
, " }"
, "}"
, "</span>"
));
}
@Test public void Normalize_for_decimal() {
fxt.Test__normalize_for_decimal("1234" , "1234"); // basic
fxt.Test__normalize_for_decimal("+1234" , "1234"); // plus
fxt.Test__normalize_for_decimal("1,234" , "1234"); // comma
fxt.Test__normalize_for_decimal("+1,234" , "1234"); // both
}
@Test public void Write_quantity_null() { // handle missing lbound / ubound; DATE:2016-12-03
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
Bry_bfr bfr = Bry_bfr_.New();
Wdata_prop_val_visitor.Write_quantity(bfr, fxt.Wdata_mgr(), fxt.Wiki().Lang(), Bry_.new_a7("123"), null, null, null);
Gftest.Eq__str("123", bfr.To_bry_and_clear());
}
}
class Wdata_prop_val_visitor__fxt {
public void Test__normalize_for_decimal(String raw, String expd) {
Gftest.Eq__str(expd, Wdata_prop_val_visitor.Normalize_for_decimal(Bry_.new_u8(raw)), raw);
}
}

View File

@@ -0,0 +1,138 @@
/*
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; 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 {
@Before public void init() {fxt.Init();} private final Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt();
@Test public void Skip_xwiki_lang_for_self() { // PURPOSE: list of language links should not include self
fxt.Init_xwikis_add("en", "fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Tid__wikipedia, "Q1_en", "Q1");
fxt.Init__docs__add(fxt.Wdoc_bldr("Q1").Add_sitelink("enwiki", "Q1_en").Add_sitelink("frwiki", "Q1_fr").Add_sitelink("dewiki", "Q1_de").Xto_wdoc());
fxt.Test_xwiki_links("Q1_en", "Q1_fr", "Q1_de");
}
@Test public void No_external_lang_links__de() {
fxt.Init_xwikis_add("fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Tid__wikipedia, "Q1_en", "Q1");
fxt.Init__docs__add(fxt.Wdoc_bldr("Q1").Add_sitelink("enwiki", "Q1_en").Add_sitelink("frwiki", "Q1_fr").Add_sitelink("dewiki", "Q1_de").Xto_wdoc());
fxt.Init_external_links_mgr_add("de");
fxt.Test_xwiki_links("Q1_en", "Q1_de");
fxt.Init_external_links_mgr_clear();
fxt.Test_parse_langs("{{noexternallanglinks:de}}", String_.Concat_lines_nl
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/bin/any/xowa/file/app.general/twisty_right.png' title='' /></a> (links: 1) (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td/>"
, " <td/>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Links_w_name_fmt() { // PURPOSE: wikidata changed links node from "enwiki:A" to "enwiki:{name:A,badges:[]}"; DATE:2013-09-14
fxt.Init_xwikis_add("en", "fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Tid__wikipedia, "Q1_en", "Q1");
Json_doc jdoc = fxt.App().Utl__json_parser().Parse(String_.Concat_lines_nl
( "{ \"entity\":\"q1\""
, ", \"links\":"
, " { \"dewiki\":\"q1_de\""
, " , \"frwiki\":{\"name\":\"q1_fr\",\"badges\":[]}"
, " }"
, "}"
));
Wdata_doc wdata_doc = new Wdata_doc(Bry_.new_a7("Q1"), fxt.App().Wiki_mgr().Wdata_mgr(), jdoc);
fxt.Init__docs__add(wdata_doc);
fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr");
}
@Test public void Same_lang_but_different_domains() { // PURPOSE: if two entries for same lang, but one is in different domain, use the one for the current wiki DATE:2014-06-21
fxt.Init_xwikis_add("en", "fr", "de");
fxt.Init_qids_add("en", Xow_domain_tid_.Tid__wikipedia, "Q1_en", "Q1");
Json_doc jdoc = fxt.App().Utl__json_parser().Parse(String_.Concat_lines_nl
( "{ \"entity\":\"q1\""
, ", \"links\":"
, " { \"dewiki\":\"q1_de\""
, " , \"frwiki\":{\"name\":\"q1_fr\",\"badges\":[]}"
, " , \"dewikisource\":\"q1_dewikisource\"" // this should be ignored
, " }"
, "}"
));
Wdata_doc wdata_doc = new Wdata_doc(Bry_.new_a7("Q1"), fxt.App().Wiki_mgr().Wdata_mgr(), jdoc);
fxt.Init__docs__add(wdata_doc);
fxt.Test_xwiki_links("Q1_en", "q1_de", "q1_fr");
}
@Test public void Badges() {
fxt.Init_xwikis_add("de", "fr", "pl");
fxt.Init_qids_add("en", Xow_domain_tid_.Tid__wikipedia, "Q1_en", "Q1");
fxt.Init__docs__add
( fxt.Wdoc_bldr("Q1")
.Add_sitelink("enwiki", "Q1_en")
.Add_sitelink("dewiki", "Q1_de", "Q17437796")
.Add_sitelink("frwiki", "Q1_fr", "Q17437798")
.Add_sitelink("plwiki", "Q1_pl", "Q17559452")
.Xto_wdoc());
fxt.Test_parse_langs("", String_.Concat_lines_nl
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/bin/any/xowa/file/app.general/twisty_right.png' title='' /></a> (links: 3) (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-goodarticle'><a hreflang=\"fr\" title=\"Q1 fr\" href=\"/site/fr.wikipedia.org/wiki/Q1 fr\">Q1 fr</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-featuredarticle'><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>Polish</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-recommendedarticle'><a hreflang=\"pl\" title=\"Q1 pl\" href=\"/site/pl.wikipedia.org/wiki/Q1 pl\">Q1 pl</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
// @Test public void No_wikidata_link() {
// fxt.Init_xwikis_add("fr", "de");
// fxt.Test_parse_langs("[[fr:A]]", String_.Concat_lines_nl
// ( "<div id=\"xowa-lang\">"
// , " <h5>In other languages</h5>"
// , " <h4>grp1</h4>"
// , " <ul style='-moz-column-count: 3; list-style:none;'>"
// , " <li><span style='display:inline-block; min-width:150px'>French</span><a hreflang=\"fr\" title=\"A\" href=\"/site/fr.wikipedia.org/wiki/A\">A</a></li>"
// , " <li><span style='display:inline-block; min-width:150px'>French</span><a hreflang=\"fr\" title=\"A\" href=\"/site/fr.wikipedia.org/wiki/A\">A</a></li>"
// , " </ul>"
// , "</div>"
// ));
// }
// @Test public void No_external_lang_links__sort() {
// fxt.Init_xwikis_add("de", "fr");
// fxt.Init_qids_add("en", Xow_domain_tid_.Tid__wikipedia, "Q1_en", "Q1");
// fxt.Init__docs__add("Q1", fxt.page_bldr_("Q1").Add_sitelink("enwiki", "Q1_en").Add_sitelink("frwiki", "Q1_fr").Add_sitelink("dewiki", "Q1_de").Xto_page_doc());
// fxt.Init_external_links_mgr_add("*");
// fxt.Test_xwiki_links("Q1_en", "Q1_de", "Q1_fr");
// fxt.Init_external_links_mgr_clear();
// fxt.Test_parse_langs("{{noexternallanglinks:*}}", String_.Concat_lines_nl
// ( "<div id=\"xowa-lang\">"
// , " <h5>In other languages (<a href=\"/site/www.wikidata.org/wiki/Q1\">wikidata</a>)</h5>"
// , " <h4>grp1</h4>"
// , " <ul style='-moz-column-count: 3; list-style:none;'>"
// , " <li><span style='display:inline-block; min-width:150px'>German</span><a hreflang=\"de\" title=\"Q1 de\" href=\"/site/de.wikipedia.org/wiki/Q1 de\">Q1 de</a></li>"
// , " <li><span style='display:inline-block; min-width:150px'>French</span><a hreflang=\"fr\" title=\"Q1 fr\" href=\"/site/fr.wikipedia.org/wiki/Q1 fr\">Q1 fr</a></li>"
// , " </ul>"
// , "</div>"
// ));
// }
}

View File

@@ -0,0 +1,90 @@
/*
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.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.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);
}
@Test public void Julian() {
fxt.Test_julian(Int_.Ary(1600, 1, 2), Int_.Ary(1600, 1, 18));
}
@Test public void Xto_str() {
String date = "+00000002001-02-03T04:05:06Z";
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");
fxt.Test_xto_str("-00000001234-01-01T00:00:00Z", 9, "1234 BC");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 8, "1980s");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 7, "19. century");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 6, "1. millenium");
fxt.Test_xto_str("+00000012345-01-01T00:00:00Z", 5, "10,000 years");
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", Wbase_date.Fmt_ymd, "2 Jan 1600");
}
@Test public void Xto_str_before_after() {
String date = "+00000002001-02-03T04:05:06Z";
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,&#32;+2)");
}
}
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 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 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) {
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());
Tfds.Eq(expd_h, actl_date.Hour());
Tfds.Eq(expd_n, actl_date.Minute());
Tfds.Eq(expd_s, actl_date.Second());
}
public void Test_julian(int[] orig_ary, int[] expd) {
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_.To_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_();
Wbase_date date = Wbase_date_.Parse(Bry_.new_a7(raw), precision, init_before, init_after, init_calendar_is_julian);
Wbase_date_.To_bfr(tmp_bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,326 @@
/*
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.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.langs.htmls.encoders.*;
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.*; import gplx.xowa.apps.apis.xowa.html.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apps.apis.xowa.xtns.*;
public class Wdata_hwtr_mgr_tst {
@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
@Test public void Stub() {}
// @Test public void Write_label() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_label("en", "en_label")
// .Add_label("de", "de_label").Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Labels</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Language</th>"
// , " <th>Label</th>"
// , " </tr>"
// , " <tr>"
// , " <td><code>en</code></td>"
// , " <td>en_label</td>"
// , " </tr>"
// , " <tr>"
// , " <td><code>de</code></td>"
// , " <td>de_label</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_descr() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_description("en", "en_descr")
// .Add_description("de", "de_descr").Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Descriptions</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Language</th>"
// , " <th>Description</th>"
// , " </tr>"
// , " <tr>"
// , " <td><code>en</code></td>"
// , " <td>en_descr</td>"
// , " </tr>"
// , " <tr>"
// , " <td><code>de</code></td>"
// , " <td>de_descr</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_alias() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_alias("en", "en_1", "en_2")
// .Add_alias("de", "de_1").Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Aliases</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Language</th>"
// , " <th>Alias</th>"
// , " </tr>"
// , " <tr>"
// , " <td><code>en</code></td>"
// , " <td>en_1<br/>en_2</td>"
// , " </tr>"
// , " <tr>"
// , " <td><code>de</code></td>"
// , " <td>de_1</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_slink_tbl_one() {
// fxt
// .Init_resolved_qid(1, "featured article").Init_resolved_qid(2, "good article")
// .Test_doc(fxt.Wdoc_bldr()
// .Add_sitelink("enwiki", "Earth", "Q1", "Q2")
// .Add_sitelink("dewiki", "Erde")
// .Add_sitelink("frwiki", "Terre")
// .Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , " <div class='wikibase-sitelinkgrouplistview'>"
// , " <div class='wb-listview'>"
// , " <div class='wikibase-sitelinkgroupview' data-wb-sitelinks-group='wikipedia'>"
// , " <div class='wikibase-sitelinkgroupview-heading-container'>"
// , " <h2 class='wb-section-heading wikibase-sitelinkgroupview-heading' dir='auto' id='sitelinks-wikipedia'>Links (Wikipedia)</h2>"
// , " </div>"
// , " <table class='wikibase-sitelinklistview'>"
// , " <colgroup>"
// , " <col class='wikibase-sitelinklistview-sitename' />"
// , " <col class='wikibase-sitelinklistview-siteid' />"
// , " <col class='wikibase-sitelinklistview-link' />"
// , " </colgroup>"
// , " <thead>"
// , " <tr class='wikibase-sitelinklistview-columnheaders'>"
// , " <th class='wikibase-sitelinkview-sitename'>Language</th>"
// , " <th class='wikibase-sitelinkview-siteid'>Code</th>"
// , " <th class='wikibase-sitelinkview-link'>Linked page</th>"
// , " </tr>"
// , " </thead>"
// , " <tbody>"
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-enwiki' data-wb-siteid='enwiki'>"
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-enwiki' lang='en' dir='auto'>English</td>"
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-enwiki'>enwiki</td>"
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-enwiki' lang='en' dir='auto'>"
// , " <span class='wikibase-sitelinkview-badges'>"
// , " <span class='wb-badge wb-badge-Q1 wb-badge-featuredarticle' title='featured article'></span>"
// , " <span class='wb-badge wb-badge-Q2 wb-badge-goodarticle' title='good article'></span>"
// , " </span>"
// , " <span class='wikibase-sitelinkview-page'>"
// , " <a href='https://en.wikipedia.org/wiki/Earth' hreflang='en' dir='auto'>Earth</a>"
// , " </span>"
// , " </td>"
// , " </tr>"
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-dewiki' data-wb-siteid='dewiki'>"
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-dewiki' lang='de' dir='auto'>Deutsch</td>"
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-dewiki'>dewiki</td>"
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-dewiki' lang='de' dir='auto'>"
// , " <span class='wikibase-sitelinkview-badges'>"
// , " </span>"
// , " <span class='wikibase-sitelinkview-page'>"
// , " <a href='https://de.wikipedia.org/wiki/Erde' hreflang='de' dir='auto'>Erde</a>"
// , " </span>"
// , " </td>"
// , " </tr>"
// , " <tr class='wikibase-sitelinkview wikibase-sitelinkview-frwiki' data-wb-siteid='frwiki'>"
// , " <td class='wikibase-sitelinkview-sitename wikibase-sitelinkview-sitename-frwiki' lang='fr' dir='auto'>Français</td>"
// , " <td class='wikibase-sitelinkview-siteid wikibase-sitelinkview-siteid-frwiki'>frwiki</td>"
// , " <td class='wikibase-sitelinkview-link wikibase-sitelinkview-link-frwiki' lang='fr' dir='auto'>"
// , " <span class='wikibase-sitelinkview-badges'>"
// , " </span>"
// , " <span class='wikibase-sitelinkview-page'>"
// , " <a href='https://fr.wikipedia.org/wiki/Terre' hreflang='fr' dir='auto'>Terre</a>"
// , " </span>"
// , " </td>"
// , " </tr>"
// , " </tbody>"
// , " </table>"
// , " </div>"
// , " </div>"
// , " </div>"
// ));
// }
// @Test public void Write_slink_tbl_many() {
// fxt.Test_doc(fxt.Wdoc_bldr()
// .Add_sitelink("enwiki" , "Earth")
// .Add_sitelink("enwiktionary", "Earth")
// .Add_sitelink("enwikiquote" , "Earth")
// .Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<p>"
// , " <div id='toc' class='toc'>"
// , " <div id='toctitle'><h2>Contents</h2></div>"
// , " <ul>"
// , " <li class='toclevel-1 tocsection-1'><a href='#Links_(Wikipedia)'><span class='tocnumber'>1</span> <span class='toctext'>Links (Wikipedia)</span></a></li>"
// , " <li class='toclevel-1 tocsection-2'><a href='#Links_(Wiktionary)'><span class='tocnumber'>2</span> <span class='toctext'>Links (Wiktionary)</span></a></li>"
// , " <li class='toclevel-1 tocsection-3'><a href='#Links_(Wikiquote)'><span class='tocnumber'>3</span> <span class='toctext'>Links (Wikiquote)</span></a></li>"
// , " <li class='toclevel-1 tocsection-4'><a href='#JSON'><span class='tocnumber'>4</span> <span class='toctext'>JSON</span></a></li>"
// , " </ul>"
// , " </div>"
// , "</p>"
// , ""
// , "<h2>Links (Wikipedia)</h2>"
// , ""
// , "<p>"
// , " <table class='wikitable'>"
// , " <tr>"
// , " <th>Site</th>"
// , " <th>Link</th>"
// , " <th>Badges</th>"
// , " </tr>"
// , " <tr>"
// , " <td><a href='/site/en.wikipedia.org/wiki/'><code>enwiki</code></a></td>"
// , " <td><a href='/site/en.wikipedia.org/wiki/Earth'>Earth</a></td>"
// , " <td></td>"
// , " </tr>"
// , " </table>"
// , "</p>"
// , ""
// , "<h2>Links (Wiktionary)</h2>"
// , ""
// , "<p>"
// , " <table class='wikitable'>"
// , " <tr>"
// , " <th>Site</th>"
// , " <th>Link</th>"
// , " <th>Badges</th>"
// , " </tr>"
// , " <tr>"
// , " <td><a href='/site/en.wiktionary.org/wiki/'><code>enwiktionary</code></a></td>"
// , " <td><a href='/site/en.wiktionary.org/wiki/Earth'>Earth</a></td>"
// , " <td></td>"
// , " </tr>"
// , " </table>"
// , "</p>"
// , ""
// , "<h2>Links (Wikiquote)</h2>"
// , ""
// , "<p>"
// , " <table class='wikitable'>"
// , " <tr>"
// , " <th>Site</th>"
// , " <th>Link</th>"
// , " <th>Badges</th>"
// , " </tr>"
// , " <tr>"
// , " <td><a href='/site/en.wikiquote.org/wiki/'><code>enwikiquote</code></a></td>"
// , " <td><a href='/site/en.wikiquote.org/wiki/Earth'>Earth</a></td>"
// , " <td></td>"
// , " </tr>"
// , " </table>"
// , "</p>"
// ));
// }
// @Test public void Write_claim() {
// Wdata_wiki_mgr_fxt mkr = fxt.Wdata_fxt();
// fxt
// .Init_resolved_pid(1, "prop_1")
// .Test_doc(fxt.Wdoc_bldr()
// .Add_claims
// ( mkr.Make_claim_string(1, "abc").Qualifiers_(mkr.Make_qualifiers(mkr.Make_qualifiers_grp(2, mkr.Make_claim_string(2, "qual_2"))))
// ).Xto_wdoc(), String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>Claims</h2>"
// , ""
// , "<table class='wikitable'>"
// , " <tr>"
// , " <th>Id</th>"
// , " <th>Name</th>"
// , " <th>Value</th>"
// , " <th>References</th>"
// , " <th>Qualifiers</th>"
// , " <th>Rank</th>"
// , " </tr>"
// , " <tr>"
// , " <td>1</td>"
// , " <td>prop_1</td>"
// , " <td>abc</td>"
// , " <td></td>"
// , " <td></td>"
// , " <td>normal</td>"
// , " </tr>"
// , "</table>"
// ));
// }
// @Test public void Write_json() {
// Json_doc jdoc = Json_doc.new_apos_("{ 'node':['val_0', 'val_1'] }");
// Wdata_doc wdoc = new Wdata_doc(Bry_.Empty, null, jdoc);
// fxt.Test_json(wdoc, String_.Concat_lines_nl_skip_last
// ( ""
// , "<h2>JSON</h2>"
// , ""
// , "<pre style=\"overflow:auto\">"
// , "{ \"node\":"
// , " [ \"val_0\""
// , " , \"val_1\""
// , " ]"
// , "}"
// , "</pre>"
// ));
// }
}
class Wdata_hwtr_mgr_fxt {
private Wdata_hwtr_mgr doc_hwtr; private Ordered_hash resolved_ttls = Ordered_hash_.New_bry();
public Wdata_wiki_mgr_fxt Wdata_fxt() {return wdata_fxt;} private Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
public void init() {
if (doc_hwtr == null) {
doc_hwtr = new Wdata_hwtr_mgr();
Wdata_hwtr_msgs msgs = Wdata_hwtr_msgs.new_en_();
Xoapi_toggle_mgr toggle_mgr = new Xoapi_toggle_mgr();
wdata_fxt.Init();
toggle_mgr.Ctor_by_app(wdata_fxt.App()); // must init, else null error
doc_hwtr.Init_by_ctor(new Xoapi_wikibase(), wdata_fxt.Wdata_mgr(), new Wdata_lbl_wkr__test(resolved_ttls), Gfo_url_encoder_.Href, toggle_mgr, new Xow_xwiki_mgr(wdata_fxt.Wiki()));
doc_hwtr.Init_by_lang(wdata_fxt.Wiki().Lang(), msgs);
}
resolved_ttls.Clear();
doc_hwtr.Lbl_mgr().Clear();
}
public Wdata_doc_bldr Wdoc_bldr() {return wdoc_bldr;} private Wdata_doc_bldr wdoc_bldr = new Wdata_doc_bldr();
public Wdata_hwtr_mgr_fxt Init_resolved_pid(int pid, String lbl) {resolved_ttls.Add(Wdata_lbl_itm.Make_ttl(Bool_.Y, pid), new Wdata_langtext_itm(Bry_.new_a7("en"), Bry_.new_a7(lbl))); return this;}
public Wdata_hwtr_mgr_fxt Init_resolved_qid(int qid, String lbl) {resolved_ttls.Add(Wdata_lbl_itm.Make_ttl(Bool_.N, qid), new Wdata_langtext_itm(Bry_.new_a7("en"), Bry_.new_a7(lbl))); return this;}
public void Test_doc(Wdata_doc wdoc, String expd) {
doc_hwtr.Init_by_wdoc(wdoc);
byte[] actl = doc_hwtr.Write(wdoc);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public void Test_claim_val(Wbase_claim_base claim, String expd) {
doc_hwtr.Init_by_wdoc(wdoc_bldr.Add_claims(claim).Xto_wdoc());
Bry_bfr tmp_bfr = Bry_bfr_.New();
Wdata_visitor__html_wtr html_wtr = new Wdata_visitor__html_wtr().Init(tmp_bfr, wdata_fxt.Wdata_mgr(), doc_hwtr.Msgs(), doc_hwtr.Lbl_mgr(), wdata_fxt.Wiki().Lang(), Bry_.Empty);
claim.Welcome(html_wtr);
byte[] actl = tmp_bfr.To_bry_and_clear();
Tfds.Eq(expd, String_.new_u8(actl));
}
public void Test_json(Wdata_doc wdoc, String expd) {
Wdata_fmtr__json fmtr_json = doc_hwtr.Fmtr_json();
fmtr_json.Init_by_wdoc(wdoc.Jdoc());
Bry_bfr tmp_bfr = Bry_bfr_.New();
fmtr_json.Bfr_arg__add(tmp_bfr);
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}
class Wdata_lbl_wkr__test implements Wdata_lbl_wkr {
private Ordered_hash found;
public Wdata_lbl_wkr__test(Ordered_hash found) {this.found = found;}
public void Resolve(Wdata_lbl_mgr lbl_mgr, Wdata_lang_sorter sorter) {lbl_mgr.Resolve(found);}
}

View File

@@ -0,0 +1,101 @@
/*
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.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.apps.apis.xowa.html.*;
public class Wdata_visitor__html_wtr_tst {
@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
@Test public void Monolingualtext() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto")
, "Motto [en]"
);
}
@Test public void Time() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Wbase_date.Fmt_ymdhns)
, "4:05:06 3 Feb 2001"
);
}
@Test public void Time__julian() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Bry_.Empty, Bry_.new_a7("http://www.wikidata.org/entity/Q1985786"))
, "4:05:06 3 Feb 2001"
);
}
@Test public void Quantity_ubound_lbound() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "", "60", "30")
, "30-60"
);
}
@Test public void Quantity_same() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "1", "60", "40")
, "50±10"
);
}
@Test public void Quantity_frac() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_quantity(1, "+0.1234", "1", "+0.1235", "+0.1233")
, "0.1234±0.0001"
);
}
@Test public void Entity_qid() {
fxt
.Init_resolved_qid(1, "item_1")
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_entity_qid(1, 1)
, "<a href='/wiki/Q1'>item_1</a>"
);
}
@Test public void Entity_pid() {
fxt
.Init_resolved_pid(1, "item_1")
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_entity_pid(1, 1)
, "<a href='/wiki/Property:P1'>item_1</a>"
);
}
@Test public void Globecoordinate() {
fxt
.Init_resolved_qid(2, "Earth")
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
, "0°7&#39;39&#34;S, 51°30&#39;26&#34;E (<a href='/wiki/Q2'>Earth</a>)"
);
}
@Test public void Globecoordinate__globe__null() {
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
, "0°7&#39;39&#34;S, 51°30&#39;26&#34;E"
);
}
@Test public void Globecoordinate__precision__0() { // PURPOSE: 0 precision was causing divide by 0 error; PAGE:ru.w:Лысково_(Калужская_область) DATE:2016-11-24
fxt
.Test_claim_val
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", "0", "null", "")
, "0°6&#39;S, 51°30&#39;E"
);
}
}

View File

@@ -0,0 +1,73 @@
/*
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.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
public class Xob_wdata_pid_base_tst {
gplx.xowa.bldrs.Xob_fxt fxt = new gplx.xowa.bldrs.Xob_fxt().Ctor_mem();
Io_url reg_(Xowe_wiki wdata, String wiki) {return Wdata_idx_wtr.dir_pid_(wdata, wiki).GenSubFil(Xotdb_dir_info_.Name_reg_fil);}
Io_url ttl_(Xowe_wiki wdata, String wiki, int fil_id) {
Io_url root = Wdata_idx_wtr.dir_pid_(wdata, wiki);
return Xotdb_fsys_mgr.Url_fil(root, fil_id, Xotdb_dir_info_.Bry_xdat);
}
@Test public void Basic() {
fxt.Wiki().Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, "Property");
fxt.doc_ary_
( fxt.doc_wo_date_(2, "Property:P2", json_("p2", "label", String_.Ary("en", "p2_en", "fr", "p2_fr")))
, fxt.doc_wo_date_(1, "Property:P1", json_("p1", "label", String_.Ary("en", "p1_en", "fr", "p1_fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "en", 0)
, "!!!!*|!!!!*|"
, "p1_en|p1"
, "p2_en|p2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "en")
, "0|p1_en|p2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "fr", 0)
, "!!!!*|!!!!*|"
, "p1_fr|p1"
, "p2_fr|p2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "fr")
, "0|p1_fr|p2_fr|2"
, ""
)
.Run(new Xob_wdata_pid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
public static String json_(String entity_id, String grp_key, String[] grp_vals) {
Bry_bfr bfr = Bry_bfr_.New();
bfr.Add_str_a7("{ 'entity':'").Add_str_u8(entity_id).Add_byte(Byte_ascii.Apos).Add_byte_nl();
bfr.Add_str_a7(", 'datatype':'commonsMedia'\n");
bfr.Add_str_a7(", '").Add_str_u8(grp_key).Add_str_a7("':").Add_byte_nl();
int len = grp_vals.length;
for (int i = 0; i < len; i += 2) {
bfr.Add_byte_repeat(Byte_ascii.Space, 2);
bfr.Add_byte(i == 0 ? Byte_ascii.Curly_bgn : Byte_ascii.Comma).Add_byte(Byte_ascii.Space);
bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(grp_vals[i ]).Add_byte(Byte_ascii.Apos).Add_byte(Byte_ascii.Colon);
bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(grp_vals[i + 1]).Add_byte(Byte_ascii.Apos).Add_byte_nl();
}
bfr.Add_str_a7(" }").Add_byte_nl();
bfr.Add_str_a7("}").Add_byte_nl();
return String_.Replace(bfr.To_str_and_clear(), "'", "\"");
}
}

View File

@@ -0,0 +1,173 @@
/*
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.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*; import gplx.dbs.*;
import gplx.xowa.bldrs.wms.sites.*;
public class Xob_wdata_qid_base_tst {
private gplx.xowa.bldrs.Xob_fxt fxt; // NOTE: reset memory instance (don't just call clear)
@Before public void init() {
this.fxt = new gplx.xowa.bldrs.Xob_fxt().Ctor_mem();
gplx.dbs.Db_conn_bldr.Instance.Reg_default_mem();
}
@Test public void Basic() {
fxt.doc_ary_
( fxt.doc_wo_date_(2, "q2", Xob_wdata_pid_base_tst.json_("q2", "links", String_.Ary("enwiki", "q2_en", "frwiki", "q2_fr")))
, fxt.doc_wo_date_(1, "q1", Xob_wdata_pid_base_tst.json_("q1", "links", String_.Ary("enwiki", "q1_en", "frwiki", "q1_fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_en|q1"
, "Q2_en|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "000")
, "0|Q1_en|Q2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_fr|q1"
, "Q2_fr|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "000")
, "0|Q1_fr|Q2_fr|2"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
@Test public void Ns() {
// setup db
Site_core_db json_db = new Site_core_db(fxt.App().Fsys_mgr().Cfg_site_meta_fil());
Site_namespace_tbl ns_tbl = json_db.Tbl__namespace();
ns_tbl.Insert(Bry_.new_a7("en.w"), Xow_ns_.Tid__help, Xow_ns_case_.Bry__1st, Bry_.Empty, Bry_.new_a7("Help"), Bool_.N, Bool_.N, Bry_.Empty);
ns_tbl.Insert(Bry_.new_a7("fr.w"), Xow_ns_.Tid__help, Xow_ns_case_.Bry__1st, Bry_.Empty, Bry_.new_a7("Aide"), Bool_.N, Bool_.N, Bry_.Empty);
// run test
fxt.doc_ary_
( fxt.doc_wo_date_(1, "11", Xob_wdata_pid_base_tst.json_("q1", "links", String_.Ary("enwiki", "Help:Q1_en", "frwiki", "Aide:Q1_fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "012", 0)
, "!!!!*|"
, "Q1_en|q1"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "012")
, "0|Q1_en|Q1_en|1"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "012", 0)
, "!!!!*|"
, "Q1_fr|q1"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "012")
, "0|Q1_fr|Q1_fr|1"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
@Test public void Links_w_name() { // PURPOSE: wikidata changed links node from "enwiki:A" to "enwiki:{name:A,badges:[]}"; DATE:2013-09-14
String q1_str = String_.Concat_lines_nl
( "{ \"entity\":\"q1\""
, ", \"links\":"
, " { \"enwiki\":\"q1_en\""
, " , \"frwiki\":\"q1_fr\""
, " }"
, "}"
);
String q2_str = String_.Concat_lines_nl
( "{ \"entity\":[\"item\",2]"
, ", \"links\":"
, " { \"enwiki\":{\"name\":\"q2_en\",\"badges\":[]}"
, " , \"frwiki\":{\"name\":\"q2_fr\",\"badges\":[]}"
, " }"
, "}"
);
fxt.doc_ary_
( fxt.doc_wo_date_(1, "q1", q1_str)
, fxt.doc_wo_date_(2, "q2", q2_str)
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_en|q1"
, "Q2_en|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "000")
, "0|Q1_en|Q2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_fr|q1"
, "Q2_fr|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "000")
, "0|Q1_fr|Q2_fr|2"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
@Test public void Spaces() { // PURPOSE: assert that ttls with spaces are converted to unders DATE:2015-04-21
fxt.doc_ary_
( fxt.doc_wo_date_(2, "q2", Xob_wdata_pid_base_tst.json_("q2", "links", String_.Ary("enwiki", "q2 en", "frwiki", "q2 fr"))) // note "q2 en" not "q2_en"
, fxt.doc_wo_date_(1, "q1", Xob_wdata_pid_base_tst.json_("q1", "links", String_.Ary("enwiki", "q1 en", "frwiki", "q1 fr")))
)
.Fil_expd(ttl_(fxt.Wiki(), "enwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_en|q1"
, "Q2_en|q2" // NOTE: q2_en
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "enwiki", "000")
, "0|Q1_en|Q2_en|2"
, ""
)
.Fil_expd(ttl_(fxt.Wiki(), "frwiki", "000", 0)
, "!!!!*|!!!!*|"
, "Q1_fr|q1"
, "Q2_fr|q2"
, ""
)
.Fil_expd
( reg_(fxt.Wiki(), "frwiki", "000")
, "0|Q1_fr|Q2_fr|2"
, ""
)
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
;
}
public static Io_url reg_(Xowe_wiki wdata, String wiki, String ns_id) {
return Wdata_idx_wtr.dir_qid_(wdata, wiki, ns_id).GenSubFil(Xotdb_dir_info_.Name_reg_fil);
}
public static Io_url ttl_(Xowe_wiki wdata, String wiki, String ns_id, int fil_id) {
Io_url root = Wdata_idx_wtr.dir_qid_(wdata, wiki, ns_id);
return Xotdb_fsys_mgr.Url_fil(root, fil_id, Xotdb_dir_info_.Bry_xdat);
}
}

View File

@@ -0,0 +1,185 @@
/*
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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*;
public class Wdata_doc_parser_v1_tst {
@Before public void init() {fxt.Init();} private Wdata_doc_parser_v1_fxt fxt = new Wdata_doc_parser_v1_fxt();
@Test public void Entity_v1_1() {
fxt.Test_entity("{ 'entity':'q1' }", "q1");
}
@Test public void Entity_v1_2() {
fxt.Test_entity("{ 'entity':['item',1] }", "q1");
}
@Test public void Sitelink_v1_1() {
fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last
( "{ 'links':"
, " { 'enwiki':'en_val'"
, " , 'dewiki':'de_val'"
, " , 'frwiki':'fr_val'"
, " }"
, "}"
)
, fxt.Make_sitelink("enwiki", "en_val")
, fxt.Make_sitelink("dewiki", "de_val")
, fxt.Make_sitelink("frwiki", "fr_val")
);
}
@Test public void Sitelink_v1_2() {
fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last
( "{ 'links':"
, " { 'enwiki':"
, " { 'name':'en_val'"
, " , 'badges':"
, " [ 'Q10'"
, " , 'Q11'"
, " , 'Q12'"
, " ]"
, " }"
, " , 'dewiki':"
, " { 'name':'de_val'"
, " , 'badges':"
, " [ 'Q2'"
, " ]"
, " }"
, " , 'frwiki':"
, " { 'name':'fr_val'"
, " , 'badges':[]"
, " }"
, " }"
, "}"
)
, fxt.Make_sitelink("enwiki", "en_val", "Q10", "Q11", "Q12")
, fxt.Make_sitelink("dewiki", "de_val", "Q2")
, fxt.Make_sitelink("frwiki", "fr_val")
);
}
@Test public void Labels() {
fxt.Test_labels(String_.Concat_lines_nl_skip_last
( "{ 'label':"
, " { 'en':'en_val'"
, " , 'de':'de_val'"
, " , 'fr':'fr_val'"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Descriptions() {
fxt.Test_descriptions(String_.Concat_lines_nl_skip_last
( "{ 'description':"
, " { 'en':'en_val'"
, " , 'de':'de_val'"
, " , 'fr':'fr_val'"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Aliases() {
fxt.Test_aliases(String_.Concat_lines_nl_skip_last
( "{ 'aliases':"
, " { 'en':"
, " [ 'en_val_1'"
, " , 'en_val_2'"
, " , 'en_val_3'"
, " ]"
, " ,"
, " 'de':"
, " [ 'de_val_1'"
, " , 'de_val_2'"
, " ]"
, " ,"
, " 'fr':"
, " [ 'fr_val_1'"
, " ]"
, " }"
, "}"
)
, fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3")
, fxt.Make_alias("de", "de_val_1", "de_val_2")
, fxt.Make_alias("fr", "fr_val_1")
);
}
@Test public void Aliases_alt() {
fxt.Test_aliases(String_.Concat_lines_nl_skip_last
( "{ 'aliases':"
, " { 'en':"
, " { '0':'en_val_1'"
, " , '1':'en_val_2'"
, " , '2':'en_val_3'"
, " }"
, " }"
, "}"
)
, fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3")
);
}
@Test public void Claims() {
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'claims':"
, " ["
, " { 'm':"
, " [ 'value'"
, " , 1"
, " , 'string'"
, " , 'abc'"
, " ]"
, " , 'q':[]"
, " , 'g':'Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e'"
, " , 'rank':1"
, " , 'refs':[]"
, " }"
, " ]"
, "}"
)
, fxt.Make_claim_string(1, "abc")
);
}
@Test public void Claim_bad() { // wikidata flags several entries as "bad"; https://www.wikidata.org/wiki/Wikidata:Project_chat/Archive/2013/10
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'entity':['item',2]"
, ", 'claims':"
, " ["
, " { 'm':"
, " [ 'value'"
, " , 373"
, " , 'bad'"
, " ,"
, " { 'latitude':1"
, " , 'longitude':2"
, " , 'altitude':null"
, " , 'precision':1"
, " , 'globe':'http:\\/\\/www.wikidata.org\\/entity\\/Q2'"
, " }"
, " ]"
, " }"
, " ]"
, "}"
)
, fxt.Make_claim_globecoordinate(1, "1", "2", "1") // assume "bad" is same as globecoordinate; DATE:2014-09-20
);
}
}
class Wdata_doc_parser_v1_fxt extends Wdata_doc_parser_fxt_base {
@Override public Wdata_doc_parser Make_parser() {return new Wdata_doc_parser_v1();}
}

View File

@@ -0,0 +1,258 @@
/*
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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*;
public class Wdata_doc_parser_v2__basic__tst {
@Before public void init() {fxt.Init();} private Wdata_doc_parser_v2_fxt fxt = new Wdata_doc_parser_v2_fxt();
@Test public void Entity() {
fxt.Test_entity("{ 'id':'Q2' }", "q2");
}
@Test public void Sitelink() {
fxt.Test_sitelinks(String_.Concat_lines_nl_skip_last
( "{ 'sitelinks':"
, " { 'enwiki':"
, " { 'site':'enwiki'"
, " , 'title':'en_val'"
, " , 'badges':"
, " [ 'Q10'"
, " , 'Q11'"
, " , 'Q12'"
, " ]"
, " }"
, " , 'dewiki':"
, " { 'site':'dewiki'"
, " , 'title':'de_val'"
, " , 'badges':"
, " [ 'Q2'"
, " ]"
, " }"
, " , 'frwiki':"
, " { 'site':'frwiki'"
, " , 'title':'fr_val'"
, " , 'badges':[]"
, " }"
, " }"
, "}"
)
, fxt.Make_sitelink("enwiki", "en_val", "Q10", "Q11", "Q12")
, fxt.Make_sitelink("dewiki", "de_val", "Q2")
, fxt.Make_sitelink("frwiki", "fr_val")
);
}
@Test public void Labels() {
fxt.Test_labels(String_.Concat_lines_nl_skip_last
( "{ 'labels':"
, " { 'en':"
, " { 'language':'enwiki'"
, " , 'value':'en_val'"
, " }"
, " , 'de':"
, " { 'language':'dewiki'"
, " , 'value':'de_val'"
, " }"
, " , 'fr':"
, " { 'language':'frwiki'"
, " , 'value':'fr_val'"
, " }"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Descriptions() {
fxt.Test_descriptions(String_.Concat_lines_nl_skip_last
( "{ 'descriptions':"
, " { 'en':"
, " { 'language':'enwiki'"
, " , 'value':'en_val'"
, " }"
, " , 'de':"
, " { 'language':'dewiki'"
, " , 'value':'de_val'"
, " }"
, " , 'fr':"
, " { 'language':'frwiki'"
, " , 'value':'fr_val'"
, " }"
, " }"
, "}"
)
, fxt.Make_langval("en", "en_val")
, fxt.Make_langval("de", "de_val")
, fxt.Make_langval("fr", "fr_val")
);
}
@Test public void Aliases() {
fxt.Test_aliases(String_.Concat_lines_nl_skip_last
( "{ 'aliases':"
, " { 'en':"
, " ["
, " { 'language':'en'"
, " , 'value':'en_val_1'"
, " }"
, " ,"
, " { 'language':'en'"
, " , 'value':'en_val_2'"
, " }"
, " ,"
, " { 'language':'en'"
, " , 'value':'en_val_3'"
, " }"
, " ]"
, " ,"
, " 'de':"
, " ["
, " { 'language':'de'"
, " , 'value':'de_val_1'"
, " }"
, " ,"
, " { 'language':'de'"
, " , 'value':'de_val_2'"
, " }"
, " ]"
, " ,"
, " 'fr':"
, " ["
, " { 'language':'fr'"
, " , 'value':'fr_val_1'"
, " }"
, " ]"
, " }"
, "}"
)
, fxt.Make_alias("en", "en_val_1", "en_val_2", "en_val_3")
, fxt.Make_alias("de", "de_val_1", "de_val_2")
, fxt.Make_alias("fr", "fr_val_1")
);
}
@Test public void Qualifiers() {
fxt.Test_qualifiers(String_.Concat_lines_nl_skip_last
( "{ 'qualifiers':"
, " { 'P1':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P1'"
, " , 'hash':''"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':11"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ,"
, " { 'snaktype':'value'"
, " , 'property':'P1'"
, " , 'hash':''"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':12"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " ,"
, " 'P2':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P2'"
, " , 'hash':''"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':21"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " }"
, "}"
), fxt.Make_claim_entity_qid(1, 11), fxt.Make_claim_entity_qid(1, 12), fxt.Make_claim_entity_qid(2, 21)
);
}
@Test public void Pid_order() {
fxt.Test_pid_order
( "{ 'qualifiers-order':['P1', 'P2', 'P3'] }"
, 1, 2, 3
);
}
@Test public void References() {
fxt.Test_references(String_.Concat_lines_nl_skip_last
( "{ 'references':"
, " [ "
, " { 'hash':'8e7d51e38606193465d2a1e9d41ba490e06682a6'"
, " , 'snaks':"
, " { 'P2':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P2'"
, " , 'hash':'358e3c0ffa2bfecfe962b39141d99dc2d482110f'"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':21"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " , 'P3':"
, " [ "
, " { 'snaktype':'value'"
, " , 'property':'P3'"
, " , 'hash':'358e3c0ffa2bfecfe962b39141d99dc2d482110f'"
, " , 'datavalue':"
, " { 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':31"
, " }"
, " , 'type':'wikibase-entityid'"
, " }"
, " }"
, " ]"
, " }"
, " , 'snaks-order':"
, " [ 'P2'"
, " , 'P3'"
, " ]"
, " }"
, " ]"
, "}"
), Int_.Ary(2, 3), fxt.Make_claim_entity_qid(2, 21), fxt.Make_claim_entity_qid(3, 31))
;
}
@Test public void References_empty() { // PURPOSE:sometimes references can have 0 snaks; return back an empty Wbase_claim_grp_list, not null; PAGE:Птичкин,_Евгений_Николаевич; DATE:2015-02-16
fxt.Test_references(String_.Concat_lines_nl_skip_last
( "{ 'references':"
, " [ "
, " { 'hash':'8e7d51e38606193465d2a1e9d41ba490e06682a6'"
, " , 'snaks':[]"
, " , 'snaks-order':[]"
, " }"
, " ]"
, "}"
), Int_.Ary_empty)
;
}
}

View File

@@ -0,0 +1,191 @@
/*
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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*;
public class Wdata_doc_parser_v2__claims__tst {
@Before public void init() {fxt.Init();} private Wdata_doc_parser_v2_fxt fxt = new Wdata_doc_parser_v2_fxt();
@Test public void Full__string() {
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'claims':"
, " { 'P1':"
, " ["
, " { 'mainsnak':"
, " { 'snaktype':'value'"
, " , 'property':'P1'"
, " , 'hash':'84487fc3f93b4f74ab1cc5a47d78f596f0b49390'"
, " , 'datavalue':"
, " { 'value':'abc'"
, " , 'type':'string'"
, " }"
, " }"
, " , 'type':'statement'"
, " , 'id':'Q2$e8ba1188-4aec-9e37-a75e-f79466c1913e'"
, " , 'rank':'normal'"
, " }"
, " ]"
, " }"
, "}"
)
, fxt.Make_claim_string(1, "abc")
);
}
@Test public void Full__novalue() {
fxt.Test_claims(String_.Concat_lines_nl_skip_last
( "{ 'claims':"
, " { 'P1':"
, " ["
, " { 'mainsnak':"
, " { 'snaktype':'novalue'"
, " , 'property':'P1'"
, " , 'hash':'84487fc3f93b4f74ab1cc5a47d78f596f0b49390'"
, " }"
, " }"
, " ]"
, " }"
, "}"
)
, fxt.Make_claim_novalue(1)
);
}
@Test public void Data__string() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'abc'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "abc")
);
}
@Test public void Data__item() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'entity-type':'item'"
, " , 'numeric-id':'123'"
, " }"
, ", 'type':'wikibase-entityid'"
, "}"
)
, fxt.Make_claim_entity_qid(1, 123)
);
}
@Test public void Data__property() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'entity-type':'property'"
, " , 'numeric-id':'398'"
, " }"
, ", 'type':'wikibase-entityid'"
, "}"
)
, fxt.Make_claim_entity_pid(1, 398)
);
}
@Test public void Data__monolingualtext() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'text':'en_text'"
, " , 'language':'en'"
, " }"
, ", 'type':'monolingualtext'"
, "}"
)
, fxt.Make_claim_monolingualtext(1, "en", "en_text")
);
}
@Test public void Data__globecoordinate() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'latitude':1.2"
, " , 'longitude':3.4"
, " , 'altitude':null"
, " , 'precision':0.0002"
, " , 'globe':'http:\\/\\/www.wikidata.org\\/entity\\/Q2'"
, " }"
, ", 'type':'globecoordinate'"
, "}"
)
, fxt.Make_claim_globecoordinate(1, "1.2", "3.4", "0.0002")
);
}
@Test public void Data__quantity() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'amount':'123'"
, " , 'unit':'2'"
, " , 'upperBound':'125'"
, " , 'lowerBound':'121'"
, " }"
, ", 'type':'quantity'"
, "}"
)
, fxt.Make_claim_quantity(1, 123, 2, 125, 121)
);
}
@Test public void Data__time() {
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':"
, " { 'time':'+00000002001-02-03T04:05:06Z'"
, " , 'timezone':0"
, " , 'before':0"
, " , 'after':0"
, " , 'precision':11"
, " , 'calendarmodel':'http:\\/\\/www.wikidata.org\\/entity\\/Q1985727'"
, " }"
, ", 'type':'time'"
, "}"
)
, fxt.Make_claim_time(1, "2001-02-03 04:05:06")
);
}
@Test public void Data__url() { // NOTE:has "String" property-type; EX:wd:Q23548; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'http:\\/\\/www.nasa.gov\\/rss\\/dyn\\/breaking_news.rss'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "http://www.nasa.gov/rss/dyn/breaking_news.rss")
);
}
@Test public void Data__commonsMedia() { // NOTE:has "String" property-type; EX:wd:Q327162; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'Tabliczka E40.svg'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "Tabliczka E40.svg")
);
}
@Test public void Data__externalid() { // NOTE:has "String" property-type; EX:wd:Q77177; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'000331371'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "000331371")
);
}
@Test public void Data__math() { // NOTE:has "String" property-type; EX:wd:Q11518; DATE:2016-07-28
fxt.Test_claims_data(String_.Concat_lines_nl_skip_last
( "{ 'value':'a^2+b^2=c^2'"
, ", 'type':'string'"
, "}"
)
, fxt.Make_claim_string(1, "a^2+b^2=c^2")
);
}
// www.wikidata.org/wiki/Q11518
}

View File

@@ -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;
}
}

View File

@@ -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&#39;4.2&#34;N, 6°47&#39;20.4&#34;E");
}
@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,52 @@
/*
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();
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);
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,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]]");
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,74 @@
/*
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.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import org.junit.*; import gplx.xowa.wikis.domains.*;
public class Wdata_itemByTitle_page_tst {
@Before public void init() {fxt.Clear();} private Wdata_itemByTitle_page_fxt fxt = new Wdata_itemByTitle_page_fxt();
@Test public void Url() {
fxt.Init_wdata_page("Q2", "q2_earth");
fxt.Init_wdata_label("enwiki", "Earth", "Q2");
fxt.Test_open("Special:ItemByTitle/enwiki/Earth", "q2_earth");
}
@Test public void Missing() {
fxt.Test_open("Special:ItemByTitle/enwiki/unknown_page", fxt.Expd_html("enwiki", "unknown page"));
}
@Test public void Html() {
fxt.Test_open("Special:ItemByTitle", fxt.Expd_html("enwiki", ""));
}
@Test public void Args() {
fxt.Init_wdata_page("Q2", "q2_earth");
fxt.Init_wdata_label("enwiki", "Earth", "Q2");
fxt.Test_open("Special:ItemByTitle?site=enwiki&page=Earth", "q2_earth");
}
@Test public void Url_decode() { // PURPOSE: spaces not handled; EX: Albert Einstein -> Albert+Einstein; DATE:2013-07-24
fxt.Init_wdata_page("Q2", "q2_page");
fxt.Init_wdata_label("enwiki", "A_B", "Q2");
fxt.Test_open("Special:ItemByTitle?site=enwiki&page=A+B", "q2_page");
}
}
class Wdata_itemByTitle_page_fxt {
public void Clear() {
parser_fxt = new Xop_fxt();
parser_fxt.Reset();
app = parser_fxt.App();
wiki = parser_fxt.Wiki();
special_page = wiki.Special_mgr().Page_itemByTitle();
wdata_fxt = new Wdata_wiki_mgr_fxt().Init(parser_fxt, true);
} private Xop_fxt parser_fxt; private Xoae_app app; private Wdata_itemByTitle_page special_page; private Xowe_wiki wiki;
Wdata_wiki_mgr_fxt wdata_fxt;
public void Init_wdata_page(String qid_ttl, String text) {
Wdata_doc doc = wdata_fxt.Wdoc_bldr(qid_ttl).Xto_wdoc();
app.Wiki_mgr().Wdata_mgr().Doc_mgr.Add(Bry_.new_a7(qid_ttl), doc);
parser_fxt.Init_page_create(app.Wiki_mgr().Wdata_mgr().Wdata_wiki(), qid_ttl, text);
}
public void Init_wdata_label(String wmf_key_str, String wdata_label, String qid) {
wdata_fxt.Init_qids_add("en", Xow_domain_tid_.Tid__wikipedia, wdata_label, qid);
}
public void Test_open(String link, String expd) {
Xoae_page page = wiki.Parser_mgr().Ctx().Page();
Xoa_url url = app.User().Wikii().Utl__url_parser().Parse(Bry_.new_u8(link));
page.Url_(url);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7(link));
page.Ttl_(ttl);
special_page.Special__gen(wiki, page, url, ttl);
Tfds.Eq_str_lines(expd, String_.new_a7(page.Db().Text().Text_bry()));
}
public String Expd_html(String wmf_key, String ttl_str) {
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_k004();
special_page.Html_fmtr().Bld_bfr_many(tmp_bfr, "Search for items by site and title", "Site", wmf_key, "Page", ttl_str, "Search");
return tmp_bfr.To_str_and_rls();
}
}