mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
General: Remove text database support
This commit is contained in:
@@ -47,7 +47,6 @@ public class Pfunc_filepath_tst {
|
||||
}
|
||||
@Test public void Wiki_is_commons() {
|
||||
fxt.Init_page_create(commons_wiki, "File:A.png", "");
|
||||
commons_wiki.Tdb_fsys_mgr().Tdb_dir_regy()[Xotdb_dir_info_.Tid_page].Ext_tid_(gplx.core.ios.streams.Io_stream_tid_.Tid__raw);
|
||||
mock_wkr.Redirect_("A.png", "A.png").Repo_idx_(1);
|
||||
fxt.Test_parse_tmpl_str_test("{{filepath:A.png}}", "{{test}}", "file:///mem/xowa/file/commons/trg/orig/7/0/1/c/A.png");
|
||||
}
|
||||
|
||||
@@ -50,8 +50,11 @@ public class Scrib_lib_wikibase_tst {
|
||||
fxt.Test_scrib_proc_bool(lib, Scrib_lib_wikibase.Invk_entityExists, Object_.Ary("Q1" ), false);
|
||||
}
|
||||
@Test public void GetEntityId() {
|
||||
wdata_fxt.Init_links_add("enwiki", "Earth", "q2");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("Earth" ), "q2");
|
||||
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc("Q2")
|
||||
.Add_sitelink("enwiki", "Earth")
|
||||
);
|
||||
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("Earth" ), "Q2");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("missing_page" ), "");
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityId, Object_.Ary("" ), ""); // PAGE:en.w:Water_treader DATE:2018-07-01
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ public class Wdata_doc_bldr {
|
||||
public Wdata_doc_bldr Add_description(String lang, String text) {byte[] key = Bry_.new_u8(lang); descr_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_u8(text))); return this;}
|
||||
public Wdata_doc_bldr Add_label(String lang, String text) {byte[] key = Bry_.new_u8(lang); label_list.Add(key, new Wdata_langtext_itm(key, Bry_.new_u8(text))); return this;}
|
||||
public Wdata_doc_bldr Add_sitelink(String site, String link, String... bdgs) {
|
||||
byte[] key = Bry_.new_u8(site); slink_list.Add(key, new Wdata_sitelink_itm(key, Bry_.new_u8(link), Bry_.Ary(bdgs)));
|
||||
byte[] key = Bry_.new_u8(site);
|
||||
slink_list.Add(key, new Wdata_sitelink_itm(key, Bry_.new_u8(link), Bry_.Ary(bdgs)));
|
||||
return this;
|
||||
}
|
||||
public Wdata_doc_bldr Add_alias(String lang, String... ary){byte[] key = Bry_.new_u8(lang); alias_list.Add(key, new Wdata_alias_itm (key, Bry_.Ary(ary))); return this;}
|
||||
|
||||
@@ -15,12 +15,10 @@ 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.wikis.nss.*; import gplx.xowa.wikis.domains.*;
|
||||
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.xtns.wbases.stores.*;
|
||||
import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
public class Wdata_wiki_mgr_fxt {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Wdata_doc_bldr wdoc_bldr;
|
||||
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();}
|
||||
@@ -39,15 +37,13 @@ public class Wdata_wiki_mgr_fxt {
|
||||
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));}
|
||||
@@ -74,7 +70,16 @@ public class Wdata_wiki_mgr_fxt {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public Wdata_doc_bldr Wdoc(String qid) {return wdoc_bldr.Qid_(qid);}
|
||||
public Wdata_doc doc_(String qid, Wbase_claim_base... props) {return wdoc_bldr.Qid_(qid).Add_claims(props).Xto_wdoc();}
|
||||
|
||||
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_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_lang_fallbacks(String... fallbacks) {wiki.Lang().Fallback_bry_(Bry_.new_a7(String_.Concat_with_str(",", fallbacks)));}
|
||||
public void Init_xwikis_add(String... prefixes) {
|
||||
int len = prefixes.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -82,28 +87,6 @@ public class Wdata_wiki_mgr_fxt {
|
||||
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();
|
||||
@@ -117,6 +100,23 @@ public class Wdata_wiki_mgr_fxt {
|
||||
external_lang_links.Langs_add(Bry_.new_a7(lang));
|
||||
}
|
||||
}
|
||||
|
||||
public void Init__docs__add(Wdata_doc_bldr bldr) {Init__docs__add(bldr.Xto_wdoc());}
|
||||
public void Init__docs__add(Wdata_doc wdoc) {
|
||||
wdata_mgr.Doc_mgr.Add(wdoc.Qid(), wdoc);
|
||||
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
Wbase_qid_mgr qid_mgr = wdata_mgr.Qid_mgr;
|
||||
Ordered_hash slinks = wdoc.Slink_list();
|
||||
int slinks_len = slinks.Len();
|
||||
for (int i = 0; i < slinks_len; i++) {
|
||||
Wdata_sitelink_itm slink = (Wdata_sitelink_itm)slinks.Get_at(i);
|
||||
Xow_domain_itm domain = Xow_abrv_wm_.Parse_to_domain_itm(slink.Site());
|
||||
Xoa_ttl page_ttl = wiki.Ttl_parse(slink.Name());
|
||||
qid_mgr.Add(tmp_bfr, domain.Lang_actl_key(), domain.Domain_type_id(), page_ttl.Ns().Num_bry(), page_ttl.Page_db(), wdoc.Qid());
|
||||
}
|
||||
}
|
||||
|
||||
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_qid_or_null(wiki, ttl);
|
||||
@@ -124,7 +124,6 @@ public class Wdata_wiki_mgr_fxt {
|
||||
}
|
||||
public void Test_parse_pid_null(String val) {Test_parse_pid(val, Wbase_pid.Id_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);
|
||||
}
|
||||
@@ -157,7 +156,7 @@ public class Wdata_wiki_mgr_fxt {
|
||||
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();
|
||||
} private 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];
|
||||
@@ -175,4 +174,20 @@ public class Wdata_wiki_mgr_fxt {
|
||||
Wdata_wiki_mgr.Write_json_as_html(wdata_mgr.Jdoc_parser(), bfr, raw_bry);
|
||||
Tfds.Eq(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
public static String New_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(), "'", "\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,23 +19,31 @@ 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);
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_sitelink("enwiki", "Q1_en")
|
||||
);
|
||||
|
||||
fxt.Test_link("Q1_en" , "Q1");
|
||||
fxt.Test_link("Q1_nil", 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);
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_sitelink("enwiki", "Q1_EN")
|
||||
);
|
||||
|
||||
fxt.Test_link("Q1_EN", "Q1");
|
||||
fxt.Test_link("q1_en", 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");
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_sitelink("enwiki", "Test_ns:Test_page")
|
||||
);
|
||||
|
||||
fxt.Test_link(Xoa_ttl.Parse(fxt.Wiki(), 124, Bry_.new_a7("Test_page")), "Q1"); // NOTE: wdata will save to "000" ns, b/c "124" ns is not canonical
|
||||
}
|
||||
@Test public void Write_json_as_html() {
|
||||
Wdata_wiki_mgr_fxt fxt = new Wdata_wiki_mgr_fxt().Init();
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Wbase_claim_type_ {
|
||||
, Tid__tabular_data = 14
|
||||
, Tid__lexeme = 15
|
||||
;
|
||||
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.data_type", 15);
|
||||
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.data_type", 16);
|
||||
public static final Wbase_enum_itm
|
||||
Itm__unknown = New(Tid__unknown , "unknown")
|
||||
, Itm__bad = New(Tid__bad , "bad") // NOTE: wikidata identifies several entries as "bad"; Q1615351|'s-Graveland, Q107538|Baco; DATE:2013-10-20
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
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 gplx.langs.jsons.*; import gplx.core.ios.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.parsers.*;
|
||||
import gplx.xowa.xtns.wbases.imports.*;
|
||||
abstract class Wdata_idx_mgr_base {
|
||||
public void Ctor(Xob_itm_dump_base wkr, Xob_bldr bldr, Xowe_wiki wiki, int dump_fil_len) {
|
||||
this.wkr = wkr; this.wiki = wiki; this.bldr = bldr; this.dump_fil_len = dump_fil_len;
|
||||
} Xob_itm_dump_base wkr; protected Xowe_wiki wiki; Xob_bldr bldr; Xol_csv_parser csv_parser = Xol_csv_parser.Instance; protected Ordered_hash hash = Ordered_hash_.New(); protected int dump_fil_len;
|
||||
public void Flush() {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wdata_idx_wtr wtr = (Wdata_idx_wtr)hash.Get_at(i);
|
||||
wtr.Flush();
|
||||
}
|
||||
}
|
||||
public void Make() {
|
||||
int len = hash.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Wdata_idx_wtr wtr = (Wdata_idx_wtr)hash.Get_at(i);
|
||||
wtr.Make(bldr.Usr_dlg(), wkr.Make_fil_len());
|
||||
}
|
||||
if (wkr.Delete_temp()) Io_mgr.Instance.DeleteDirDeep(wkr.Temp_dir());
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
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 gplx.core.ios.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.texts.tdbs.*;
|
||||
class Wdata_idx_wtr {
|
||||
public Wdata_idx_wtr(Io_url dump_dir, int dump_fil_max, Io_url make_dir) {
|
||||
this.dump_dir = dump_dir;
|
||||
this.dump_fil_max = dump_fil_max;
|
||||
dump_url_gen = Io_url_gen_.dir_(dump_dir);
|
||||
this.make_dir = make_dir;
|
||||
} private Bry_bfr dump_bfr = Bry_bfr_.Reset(2 * Io_mgr.Len_kb); int dump_fil_max; Io_url dump_dir, make_dir; Io_url_gen dump_url_gen;
|
||||
public void Write(byte[] ttl, byte[] qid) {
|
||||
if (dump_bfr.Len() + ttl.length + qid.length + 2 > dump_fil_max) Flush(); // 2 = "|" + "\n"; NOTE: all items have format of "data|qid\n"
|
||||
dump_bfr.Add(ttl).Add_byte_pipe().Add(qid).Add_byte_nl();
|
||||
}
|
||||
public void Flush() {
|
||||
Io_mgr.Instance.AppendFilBfr(dump_url_gen.Nxt_url(), dump_bfr);
|
||||
}
|
||||
public void Make(Gfo_usr_dlg usr_dlg, int make_fil_len) {
|
||||
Xobdc_merger.Basic(usr_dlg, dump_url_gen, dump_dir.OwnerDir().GenSubDir("sort"), dump_fil_max, Io_line_rdr_key_gen_.first_pipe, new Xob_make_cmd_site(usr_dlg, make_dir, make_fil_len));
|
||||
}
|
||||
public static Wdata_idx_wtr new_qid_(Xowe_wiki wdata_wiki, String wiki_str, String ns_num, int dump_fil_max) {
|
||||
Io_url dump_dir = wdata_wiki.Fsys_mgr().Tmp_dir().GenSubDir_nest("wdata.qid", "qid", wiki_str, ns_num, "dump"); // /xowa/wiki/www.wikidata.org/tmp/wdata_qid/ + enwiki/000/dump/
|
||||
Io_url make_dir = dir_qid_(wdata_wiki, wiki_str, ns_num); // /xowa/wiki/www.wikidata.org/site/data/qid/ + enwiki/000/
|
||||
return new Wdata_idx_wtr(dump_dir, dump_fil_max, make_dir);
|
||||
}
|
||||
public static Wdata_idx_wtr new_pid_(Xowe_wiki wdata_wiki, String lang_key, int dump_fil_max) {
|
||||
Io_url dump_dir = wdata_wiki.Fsys_mgr().Tmp_dir().GenSubDir_nest("wdata.pid", "pid", lang_key, "dump"); // /xowa/wiki/www.wikidata.org/tmp/wdata_pid/ + en/
|
||||
Io_url make_dir = dir_pid_(wdata_wiki, lang_key); // /xowa/wiki/www.wikidata.org/site/data/pid/ + en/
|
||||
return new Wdata_idx_wtr(dump_dir, dump_fil_max, make_dir);
|
||||
}
|
||||
public static Io_url dir_qid_(Xowe_wiki wiki, String wiki_str, String ns_num) {
|
||||
return wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid", wiki_str, ns_num); // /xowa/wiki/www.wikidata.org/site/data/ + qid/enwiki/000/
|
||||
}
|
||||
public static Io_url dir_pid_(Xowe_wiki wiki, String lang_key) {
|
||||
return wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid", lang_key); // /xowa/wiki/www.wikidata.org/site/data/ + pid/en/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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 gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.dbs.*;
|
||||
import gplx.langs.jsons.*;
|
||||
public class Xob_wdata_pid extends Xob_itm_dump_base implements Xob_page_wkr, Gfo_invk {
|
||||
private Db_conn conn;
|
||||
private Wbase_pid_tbl tbl__pid;
|
||||
private Xowb_prop_tbl tbl__prop;
|
||||
private Json_parser jdoc_parser;
|
||||
private final Ordered_hash datatype_hash = Ordered_hash_.New_bry();
|
||||
public Xob_wdata_pid(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
public Xob_wdata_pid Ctor(Xob_bldr bldr, Xowe_wiki wiki) {
|
||||
this.Cmd_ctor(bldr, wiki);
|
||||
this.jdoc_parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
|
||||
return this;
|
||||
}
|
||||
public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;}
|
||||
public void Page_wkr__bgn() {this.Pid__bgn();}
|
||||
public void Page_wkr__run(Xowd_page_itm page) {
|
||||
if (page.Ns_id() != Wdata_wiki_mgr.Ns_property) return;
|
||||
|
||||
Json_doc jdoc = jdoc_parser.Parse(page.Text());
|
||||
if (jdoc == null) {
|
||||
bldr.Usr_dlg().Warn_many(GRP_KEY, "json.invalid", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db()));
|
||||
return;
|
||||
}
|
||||
Pid__run(jdoc);
|
||||
}
|
||||
public void Page_wkr__run_cleanup() {}
|
||||
public void Page_wkr__end() {this.Pid__end();}
|
||||
public void Pid__bgn() {
|
||||
if (conn == null) // conn will be null unless test
|
||||
conn = wiki.Data__core_mgr().Db__wbase().Conn();
|
||||
|
||||
// init datatype_hash
|
||||
Wbase_enum_hash enum_hash = Wbase_claim_type_.Reg;
|
||||
byte len = (byte)enum_hash.Len();
|
||||
for (byte i = 0; i < len; i++) {
|
||||
Wbase_claim_type claim_type = (Wbase_claim_type)enum_hash.Get_itm_or(i, null);
|
||||
datatype_hash.Add(Bry_.new_u8(claim_type.Key_for_scrib()), claim_type);
|
||||
}
|
||||
|
||||
// init wbase_pid
|
||||
tbl__pid = Wbase_pid_tbl.New_make(conn);
|
||||
tbl__pid.Create_tbl();
|
||||
tbl__pid.Insert_bgn();
|
||||
|
||||
// init wbase_prop
|
||||
tbl__prop = new Xowb_prop_tbl(conn);
|
||||
tbl__prop.Create_tbl();
|
||||
tbl__prop.Insert_bgn();
|
||||
}
|
||||
public void Pid__run(Json_doc jdoc) {
|
||||
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
|
||||
byte[] pid = wdoc_parser.Parse_qid(jdoc);
|
||||
|
||||
// add datatype
|
||||
byte[] datatype = jdoc.Root_nde().Get_as_bry(Wdata_dict_mainsnak.Itm__datatype.Key_str());
|
||||
Wbase_claim_type claim_type = (Wbase_claim_type)datatype_hash.Get_by_or_fail(datatype);
|
||||
tbl__prop.Insert_cmd_by_batch(pid, claim_type.Tid());
|
||||
|
||||
// add langs
|
||||
Ordered_hash list = wdoc_parser.Parse_langvals(pid, jdoc, Bool_.Y);
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Wdata_langtext_itm label = (Wdata_langtext_itm)list.Get_at(i);
|
||||
tbl__pid.Insert_cmd_by_batch(label.Lang(), label.Text(), pid);
|
||||
}
|
||||
}
|
||||
public void Pid__end() {
|
||||
tbl__pid.Insert_end();
|
||||
tbl__pid.Create_idx();
|
||||
tbl__prop.Insert_end();
|
||||
}
|
||||
private static final String GRP_KEY = "xowa.wdata.pid_wkr";
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
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 gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xob_page_wkr, Gfo_invk {
|
||||
private Json_parser parser;
|
||||
public Xob_wdata_pid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
|
||||
public abstract void Pid_bgn();
|
||||
public abstract void Pid_add(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl);
|
||||
public abstract void Pid_datatype(byte[] pid, byte[] datatype_bry);
|
||||
public abstract void Pid_end();
|
||||
|
||||
public abstract String Page_wkr__key();
|
||||
public void Page_wkr__bgn() {
|
||||
this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
|
||||
this.parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
|
||||
this.Pid_bgn();
|
||||
}
|
||||
public void Page_wkr__run(Xowd_page_itm page) {
|
||||
if (page.Ns_id() != Wdata_wiki_mgr.Ns_property) return;
|
||||
|
||||
Json_doc jdoc = parser.Parse(page.Text());
|
||||
if (jdoc == null) {
|
||||
bldr.Usr_dlg().Warn_many(GRP_KEY, "json.invalid", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db()));
|
||||
return;
|
||||
}
|
||||
Parse_jdoc(jdoc);
|
||||
}
|
||||
public void Page_wkr__run_cleanup() {}
|
||||
public void Parse_jdoc(Json_doc jdoc) {
|
||||
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
|
||||
byte[] qid = wdoc_parser.Parse_qid(jdoc);
|
||||
|
||||
// add datatype
|
||||
byte[] datatype = jdoc.Root_nde().Get_as_bry(Wdata_dict_mainsnak.Itm__datatype.Key_str());
|
||||
this.Pid_datatype(qid, datatype);
|
||||
|
||||
// add langs
|
||||
Ordered_hash list = wdoc_parser.Parse_langvals(qid, jdoc, Bool_.Y);
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Wdata_langtext_itm label = (Wdata_langtext_itm)list.Get_at(i);
|
||||
this.Pid_add(label.Lang(), label.Text(), qid);
|
||||
}
|
||||
}
|
||||
public void Page_wkr__end() {this.Pid_end();}
|
||||
private static final String GRP_KEY = "xowa.wdata.pid_wkr";
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
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.*;
|
||||
import gplx.xowa.bldrs.*;
|
||||
public class Xob_wdata_pid_base_tst {
|
||||
private final Xob_fxt fxt = new 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_page_wkrs(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(), "'", "\"");
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
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 gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.xtns.wbases.dbs.*; import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Xob_wdata_pid_sql extends Xob_wdata_pid_base {
|
||||
private Db_conn conn;
|
||||
private Wbase_pid_tbl tbl__pid;
|
||||
private Xowb_prop_tbl tbl__prop;
|
||||
private final Ordered_hash datatype_hash = Ordered_hash_.New_bry();
|
||||
public Xob_wdata_pid_sql(Db_conn conn, Xowe_wiki wiki) {
|
||||
this.conn = conn;
|
||||
this.wiki = wiki;
|
||||
}
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;}
|
||||
@Override public void Pid_bgn() {
|
||||
if (conn == null)
|
||||
conn = wiki.Data__core_mgr().Db__wbase().Conn();
|
||||
// init datatype_hash
|
||||
Wbase_enum_hash enum_hash = Wbase_claim_type_.Reg;
|
||||
byte len = (byte)enum_hash.Len();
|
||||
for (byte i = 0; i < len; i++) {
|
||||
Wbase_claim_type claim_type = (Wbase_claim_type)enum_hash.Get_itm_or(i, null);
|
||||
datatype_hash.Add(Bry_.new_u8(claim_type.Key_for_scrib()), claim_type);
|
||||
}
|
||||
|
||||
// init wbase_pid
|
||||
tbl__pid = Wbase_pid_tbl.New_make(conn);
|
||||
tbl__pid.Create_tbl();
|
||||
tbl__pid.Insert_bgn();
|
||||
|
||||
// init wbase_prop
|
||||
tbl__prop = new Xowb_prop_tbl(conn);
|
||||
tbl__prop.Create_tbl();
|
||||
tbl__prop.Insert_bgn();
|
||||
}
|
||||
@Override public void Pid_add(byte[] lang_key, byte[] ttl, byte[] pid) {
|
||||
tbl__pid.Insert_cmd_by_batch(lang_key, ttl, pid);
|
||||
}
|
||||
@Override public void Pid_datatype(byte[] pid, byte[] datatype_bry) {
|
||||
Wbase_claim_type claim_type = (Wbase_claim_type)datatype_hash.Get_by_or_fail(datatype_bry);
|
||||
tbl__prop.Insert_cmd_by_batch(pid, claim_type.Tid());
|
||||
}
|
||||
@Override public void Pid_end() {
|
||||
tbl__pid.Insert_end();
|
||||
tbl__pid.Create_idx();
|
||||
tbl__prop.Insert_end();
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
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.core.tests.*;
|
||||
import gplx.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xob_wdata_pid_sql_tst {
|
||||
private Db_conn conn;
|
||||
private final Xob_fxt fxt = new Xob_fxt().Ctor_mem();
|
||||
private final Gfo_db_tester db_tester = new Gfo_db_tester();
|
||||
@Before public void init() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
this.conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/wbase.xowa"));
|
||||
}
|
||||
|
||||
@Test public void Basic() {
|
||||
fxt.Wiki().Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, "Property");
|
||||
Xob_wdata_pid_sql wkr = new Xob_wdata_pid_sql(conn, null);
|
||||
wkr.Ctor(fxt.Bldr(), fxt.Wiki());
|
||||
|
||||
fxt.Run_page_wkr(wkr
|
||||
, fxt.doc_wo_date_(2, "Property:P2", Xob_wdata_tst_utl.Json("p2", "label", String_.Ary("en", "p2_en", "fr", "p2_fr")))
|
||||
, fxt.doc_wo_date_(1, "Property:P1", Xob_wdata_tst_utl.Json("p1", "label", String_.Ary("en", "p1_en", "fr", "p1_fr")))
|
||||
);
|
||||
|
||||
db_tester.Test__select_tbl(conn
|
||||
, "wbase_pid", new Dbmeta_fld_list().Bld_str("src_lang").Bld_str("src_ttl").Bld_str("trg_ttl")
|
||||
, String_.Ary("en", "p2_en", "p2")
|
||||
, String_.Ary("fr", "p2_fr", "p2")
|
||||
, String_.Ary("en", "p1_en", "p1")
|
||||
, String_.Ary("fr", "p1_fr", "p1")
|
||||
);
|
||||
}
|
||||
}
|
||||
class Gfo_db_tester {
|
||||
public void Test__select_tbl(Db_conn conn, String tbl, Dbmeta_fld_list flds, String[]... expd_rows) {
|
||||
Db_rdr rdr = Db_rdr_.Empty;
|
||||
try {
|
||||
rdr = conn.Stmt_select_all(tbl, flds).Exec_select__rls_auto();
|
||||
int row_idx = 0;
|
||||
while (rdr.Move_next()) {
|
||||
String[] actl_row = new String[flds.Len()];
|
||||
for (int i = 0; i < flds.Len(); i++)
|
||||
actl_row[i] = Object_.Xto_str_strict_or_null(rdr.Read_at(i));
|
||||
String[] expd_row = expd_rows[row_idx++];
|
||||
Gftest.Eq__ary(expd_row, actl_row, "row compare failed", "row", row_idx);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
}
|
||||
}
|
||||
public void Test__objary(Object[][] expd, Object[][] actl) {
|
||||
// gplx.core.strings.String_bldr_.new_()
|
||||
}
|
||||
}
|
||||
|
||||
class Xob_wdata_tst_utl {
|
||||
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(), "'", "\"");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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.core.tests.*;
|
||||
import gplx.*; import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xob_wdata_pid_tst {
|
||||
private Db_conn conn;
|
||||
private final Xobldr_fxt fxt = new Xobldr_fxt().Ctor_mem();
|
||||
private final Gfo_db_tester db_tester = new Gfo_db_tester();
|
||||
@Before public void init() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
this.conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/wbase.xowa"));
|
||||
}
|
||||
|
||||
@Test public void Basic() {
|
||||
fxt.Wiki().Ns_mgr().Add_new(Wdata_wiki_mgr.Ns_property, "Property");
|
||||
Xob_wdata_pid wkr = new Xob_wdata_pid(conn);
|
||||
wkr.Ctor(fxt.Bldr(), fxt.Wiki());
|
||||
|
||||
fxt.Run_page_wkr(wkr
|
||||
, fxt.New_page_wo_date(2, "Property:P2", Xob_wdata_tst_utl.Json("p2", "label", String_.Ary("en", "p2_en", "fr", "p2_fr")))
|
||||
, fxt.New_page_wo_date(1, "Property:P1", Xob_wdata_tst_utl.Json("p1", "label", String_.Ary("en", "p1_en", "fr", "p1_fr")))
|
||||
);
|
||||
|
||||
db_tester.Test__select_tbl(conn, "wbase_pid", new Dbmeta_fld_list().Bld_str("src_lang").Bld_str("src_ttl").Bld_str("trg_ttl")
|
||||
, Object_.Ary("en", "p2_en", "p2")
|
||||
, Object_.Ary("fr", "p2_fr", "p2")
|
||||
, Object_.Ary("en", "p1_en", "p1")
|
||||
, Object_.Ary("fr", "p1_fr", "p1")
|
||||
);
|
||||
|
||||
db_tester.Test__select_tbl(conn, "wbase_prop", new Dbmeta_fld_list().Bld_str("wbp_pid").Bld_int("wbp_datatype")
|
||||
, Object_.Ary("p2", 12)
|
||||
, Object_.Ary("p1", 12)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Gfo_db_tester {
|
||||
public void Test__select_tbl(Db_conn conn, String tbl, Dbmeta_fld_list flds, Object[]... expd_rows) {
|
||||
// get actl
|
||||
List_adp actl_list = List_adp_.New();
|
||||
Db_rdr rdr = Db_rdr_.Empty;
|
||||
try {
|
||||
rdr = conn.Stmt_select_all(tbl, flds).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Object[] actl_row = new Object[flds.Len()];
|
||||
actl_list.Add(actl_row);
|
||||
for (int i = 0; i < flds.Len(); i++) {
|
||||
Object val = rdr.Read_at(i);
|
||||
int val_tid = Dbmeta_fld_tid.Get_by_obj(val);
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
if (val_tid != fld.Type().Tid_ansi())
|
||||
actl_row[i] = Object_.Xto_str_strict_or_null_mark(val) + "|shouldBe=" + String_.new_u8(fld.Type().Name()) + "|was=" + Type_.Name_by_obj(val);
|
||||
else
|
||||
actl_row[i] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
}
|
||||
Object[][] actl_rows = (Object[][])actl_list.To_ary_and_clear(Object[].class);
|
||||
|
||||
// validate expd datatypes
|
||||
for (Object[] expd_row : expd_rows) {
|
||||
int len = expd_row.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Object val = expd_row[i];
|
||||
int val_tid = Dbmeta_fld_tid.Get_by_obj(val);
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
if (val_tid != fld.Type().Tid_ansi())
|
||||
expd_row[i] = Object_.Xto_str_strict_or_null_mark(val) + "|shouldBe=" + String_.new_u8(fld.Type().Name()) + "|was=" + Type_.Name_by_obj(val);
|
||||
}
|
||||
}
|
||||
Gftest.Eq__ary(To_str_ary(expd_rows), To_str_ary(actl_rows), "rows mismatch");
|
||||
}
|
||||
public byte[][] To_str_ary(Object[][] rows) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
byte[][] rv = new byte[rows.length][];
|
||||
int rows_len = rows.length;
|
||||
for (int i = 0; i < rows_len; i++) {
|
||||
Object[] row = rows[i];
|
||||
for (int j = 0; j < row.length; j++) {
|
||||
if (j != 0) bfr.Add_byte_pipe();
|
||||
bfr.Add_obj(row[j]);
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
rv[i] = bfr.To_bry_and_clear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
class Xob_wdata_tst_utl {
|
||||
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(), "'", "\"");
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
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 gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
public class Xob_wdata_pid_txt extends Xob_wdata_pid_base {
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_pid;}
|
||||
@Override public void Pid_bgn() {
|
||||
pid_bldr = new Wdata_idx_bldr_pid(this, bldr, wiki, dump_fil_len);
|
||||
} Wdata_idx_bldr_pid pid_bldr;
|
||||
@Override public void Pid_add(byte[] lang_key, byte[] prop_key, byte[] qid) {
|
||||
pid_bldr.Add(lang_key, prop_key, qid);
|
||||
}
|
||||
@Override public void Pid_datatype(byte[] pid, byte[] datatype_bry) {}
|
||||
@Override public void Pid_end() {
|
||||
pid_bldr.Flush();
|
||||
pid_bldr.Make();
|
||||
}
|
||||
}
|
||||
class Wdata_idx_bldr_pid extends Wdata_idx_mgr_base {
|
||||
public Wdata_idx_bldr_pid(Xob_itm_dump_base wkr, Xob_bldr bldr, Xowe_wiki wiki, int dump_fil_len) {this.Ctor(wkr, bldr, wiki, dump_fil_len);}
|
||||
public void Add(byte[] lang, byte[] prop_key, byte[] pid) {
|
||||
Wdata_idx_wtr wtr = Get_or_new(lang);
|
||||
wtr.Write(prop_key, pid);
|
||||
}
|
||||
public Wdata_idx_wtr Get_or_new(byte[] lang_bry) {
|
||||
String lang = String_.Lower(String_.new_u8(lang_bry)); // NOTE: for some reason, both "en" and "En" can be added; normalize case
|
||||
Object rv = hash.Get_by(lang);
|
||||
if (rv == null) {
|
||||
Wdata_idx_wtr wtr = Wdata_idx_wtr.new_pid_(wiki, lang, dump_fil_len);
|
||||
hash.Add(lang, wtr);
|
||||
return wtr;
|
||||
}
|
||||
return (Wdata_idx_wtr)rv;
|
||||
}
|
||||
}
|
||||
@@ -14,32 +14,44 @@ 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 gplx.langs.jsons.*; import gplx.core.ios.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.langs.jsons.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.bldrs.wms.sites.*;
|
||||
public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xob_page_wkr, Gfo_invk {
|
||||
import gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.dbs.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
public class Xob_wdata_qid extends Xob_itm_dump_base implements Xob_page_wkr, Gfo_invk {
|
||||
private Db_conn conn;
|
||||
private Wbase_qid_tbl tbl;
|
||||
private final Object thread_lock = new Object();
|
||||
private Json_parser parser; private Xob_wbase_ns_parser ns_parser; private final Xob_wbase_ns_parser_rslt ns_parser_rslt = new Xob_wbase_ns_parser_rslt();
|
||||
public Xob_wdata_qid_base Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
|
||||
public abstract String Page_wkr__key();
|
||||
public abstract void Qid_bgn();
|
||||
public abstract void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid);
|
||||
public abstract void Qid_end();
|
||||
public Xob_wdata_qid(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_qid;}
|
||||
public Xob_wdata_qid Ctor(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki); return this;}
|
||||
public void Page_wkr__bgn() {
|
||||
this.Init_dump(this.Page_wkr__key(), wiki.Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid")); // NOTE: must pass in correct make_dir in order to delete earlier version (else make_dirs will append)
|
||||
this.parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
|
||||
this.ns_parser = new Xob_wbase_ns_parser(bldr.App().Fsys_mgr().Cfg_site_meta_fil());
|
||||
this.Qid_bgn();
|
||||
this.Qid__bgn();
|
||||
}
|
||||
public void Page_wkr__run(Xowd_page_itm page) {
|
||||
if (page.Ns_id() != Xow_ns_.Tid__main) return; // qid pages are only in the Main Srch_rslt_cbk
|
||||
Json_doc jdoc = parser.Parse(page.Text());
|
||||
if (jdoc == null) {bldr.Usr_dlg().Warn_many("", "", "json is invalid: ns=~{0} id=~{1}", page.Ns_id(), String_.new_u8(page.Ttl_page_db())); return;}
|
||||
this.Parse_jdoc(jdoc);
|
||||
this.Qid__run(jdoc);
|
||||
}
|
||||
public void Page_wkr__run_cleanup() {}
|
||||
public void Parse_jdoc(Json_doc jdoc) {
|
||||
public void Page_wkr__end() {this.Qid__end();}
|
||||
public void Qid__bgn() {
|
||||
if (conn == null) {
|
||||
Xow_db_file wbase_db = Make_wbase_db(wiki.Db_mgr_as_sql().Core_data_mgr());
|
||||
conn = wbase_db.Conn();
|
||||
}
|
||||
tbl = Wbase_qid_tbl.New_make(conn, false);
|
||||
tbl.Create_tbl();
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
public void Qid__run(Json_doc jdoc) {
|
||||
synchronized (thread_lock) {
|
||||
Wdata_doc_parser wdoc_parser = app.Wiki_mgr().Wdata_mgr().Wdoc_parser(jdoc);
|
||||
byte[] qid = wdoc_parser.Parse_qid(jdoc);
|
||||
@@ -54,12 +66,21 @@ public abstract class Xob_wdata_qid_base extends Xob_itm_dump_base implements Xo
|
||||
if (sitelink_ns != Xow_ns_.Tid__main) // ttl not in main; chop off ns portion; EX:Aide:French_title -> French_title
|
||||
sitelink_ttl = Bry_.Mid(sitelink_ttl, ns_parser_rslt.Ttl_bgn(), sitelink_ttl.length);
|
||||
sitelink_ttl = wiki.Lang().Case_mgr().Case_build_1st_upper(tmp_bfr, sitelink_ttl, 0, sitelink_ttl.length);
|
||||
this.Qid_add(sitelink.Site(), sitelink_ns, Xoa_ttl.Replace_spaces(sitelink_ttl), qid); // NOTE: always convert spaces to underscores; EX: "A B" -> "A_B" DATE:2015-04-21
|
||||
tbl.Insert_cmd_by_batch(sitelink.Site(), sitelink_ns, Xoa_ttl.Replace_spaces(sitelink_ttl), qid); // NOTE: always convert spaces to underscores; EX: "A B" -> "A_B" DATE:2015-04-21
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Page_wkr__end() {
|
||||
this.Qid_end();
|
||||
// wiki.Data__core_mgr().Db__wbase().Tbl__cfg().Insert_int("", "", 1);
|
||||
public void Qid__end() {
|
||||
tbl.Insert_end();
|
||||
tbl.Create_idx();
|
||||
}
|
||||
public static Xow_db_file Make_wbase_db(Xow_db_mgr db_mgr) {
|
||||
boolean db_is_all_or_few = db_mgr.Props().Layout_text().Tid_is_all_or_few();
|
||||
Xow_db_file wbase_db = db_is_all_or_few
|
||||
? db_mgr.Db__core()
|
||||
: db_mgr.Dbs__make_by_tid(Xow_db_file_.Tid__wbase);
|
||||
if (db_is_all_or_few)
|
||||
db_mgr.Db__wbase_(wbase_db);
|
||||
return wbase_db;
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
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_page_wkrs(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_page_wkrs(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_page_wkrs(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_page_wkrs(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);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
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 gplx.xowa.wikis.data.*; import gplx.dbs.*; import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.xtns.wbases.dbs.*;
|
||||
public class Xob_wdata_qid_sql extends Xob_wdata_qid_base {
|
||||
private Wbase_qid_tbl tbl;
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_qid;}
|
||||
@Override public void Qid_bgn() {
|
||||
Xow_db_file wbase_db = Make_wbase_db(wiki.Db_mgr_as_sql().Core_data_mgr());
|
||||
tbl = Wbase_qid_tbl.New_make(wbase_db.Conn(), false);
|
||||
tbl.Create_tbl();
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
@Override public void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid) {
|
||||
tbl.Insert_cmd_by_batch(wiki_key, ns_id, ttl, qid);
|
||||
}
|
||||
@Override public void Qid_end() {
|
||||
tbl.Insert_end();
|
||||
tbl.Create_idx();
|
||||
}
|
||||
public static Xow_db_file Make_wbase_db(Xow_db_mgr db_mgr) {
|
||||
boolean db_is_all_or_few = db_mgr.Props().Layout_text().Tid_is_all_or_few();
|
||||
Xow_db_file wbase_db = db_is_all_or_few
|
||||
? db_mgr.Db__core()
|
||||
: db_mgr.Dbs__make_by_tid(Xow_db_file_.Tid__wbase);
|
||||
if (db_is_all_or_few)
|
||||
db_mgr.Db__wbase_(wbase_db);
|
||||
return wbase_db;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
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.core.tests.*;
|
||||
import gplx.*; import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.bldrs.wms.sites.*;
|
||||
public class Xob_wdata_qid_tst {
|
||||
private Db_conn conn;
|
||||
private final Xobldr_fxt fxt = new Xobldr_fxt().Ctor_mem();
|
||||
private Xob_wdata_qid wkr;
|
||||
private final Gfo_db_tester db_tester = new Gfo_db_tester();
|
||||
private final Dbmeta_fld_list flds__wbase_qid = new Dbmeta_fld_list().Bld_str("src_wiki").Bld_int("src_ns").Bld_str("src_ttl").Bld_str("trg_ttl");
|
||||
@Before public void init() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
this.conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/wbase.xowa"));
|
||||
this.wkr = new Xob_wdata_qid(conn);
|
||||
wkr.Ctor(fxt.Bldr(), fxt.Wiki());
|
||||
}
|
||||
|
||||
@Test public void Basic() {
|
||||
fxt.Run_page_wkr(wkr
|
||||
, fxt.New_page_wo_date(2, "q2", Wdata_wiki_mgr_fxt.New_json("q2", "links", String_.Ary("enwiki", "q2_en", "frwiki", "q2_fr")))
|
||||
, fxt.New_page_wo_date(1, "q1", Wdata_wiki_mgr_fxt.New_json("q1", "links", String_.Ary("enwiki", "q1_en", "frwiki", "q1_fr")))
|
||||
);
|
||||
|
||||
db_tester.Test__select_tbl(conn, "wbase_qid", flds__wbase_qid
|
||||
, Object_.Ary("enwiki", 0, "Q2_en", "q2")
|
||||
, Object_.Ary("frwiki", 0, "Q2_fr", "q2")
|
||||
, Object_.Ary("enwiki", 0, "Q1_en", "q1")
|
||||
, Object_.Ary("frwiki", 0, "Q1_fr", "q1")
|
||||
);
|
||||
}
|
||||
@Test public void Ns() {
|
||||
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);
|
||||
|
||||
fxt.Run_page_wkr(wkr
|
||||
, fxt.New_page_wo_date(1, "11", Wdata_wiki_mgr_fxt.New_json("q1", "links", String_.Ary("enwiki", "Help:Q1_en", "frwiki", "Aide:Q1_fr")))
|
||||
);
|
||||
|
||||
db_tester.Test__select_tbl(conn, "wbase_qid", flds__wbase_qid
|
||||
, Object_.Ary("enwiki", 12, "Q1_en", "q1")
|
||||
, Object_.Ary("frwiki", 12, "Q1_fr", "q1")
|
||||
);
|
||||
}
|
||||
@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.Run_page_wkr(wkr
|
||||
, fxt.New_page_wo_date(1, "q1", q1_str)
|
||||
, fxt.New_page_wo_date(2, "q2", q2_str)
|
||||
);
|
||||
|
||||
db_tester.Test__select_tbl(conn, "wbase_qid", flds__wbase_qid
|
||||
, Object_.Ary("enwiki", 0, "Q1_en", "q1")
|
||||
, Object_.Ary("frwiki", 0, "Q1_fr", "q1")
|
||||
, Object_.Ary("enwiki", 0, "Q2_en", "q2")
|
||||
, Object_.Ary("frwiki", 0, "Q2_fr", "q2")
|
||||
);
|
||||
}
|
||||
@Test public void Spaces() { // PURPOSE: assert that ttls with spaces are converted to unders DATE:2015-04-21
|
||||
fxt.Run_page_wkr(wkr
|
||||
, fxt.New_page_wo_date(2, "q2", Wdata_wiki_mgr_fxt.New_json("q2", "links", String_.Ary("enwiki", "q2 en", "frwiki", "q2 fr"))) // note "q2 en" not "q2_en"
|
||||
, fxt.New_page_wo_date(1, "q1", Wdata_wiki_mgr_fxt.New_json("q1", "links", String_.Ary("enwiki", "q1 en", "frwiki", "q1 fr")))
|
||||
);
|
||||
|
||||
db_tester.Test__select_tbl(conn, "wbase_qid", flds__wbase_qid
|
||||
, Object_.Ary("enwiki", 0, "Q2_en", "q2") // NOTE: q2_en
|
||||
, Object_.Ary("frwiki", 0, "Q2_fr", "q2")
|
||||
, Object_.Ary("enwiki", 0, "Q1_en", "q1")
|
||||
, Object_.Ary("frwiki", 0, "Q1_fr", "q1")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
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 gplx.xowa.bldrs.*;
|
||||
public class Xob_wdata_qid_txt extends Xob_wdata_qid_base {
|
||||
private Wdata_idx_bldr_qid qid_bldr;
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_tdb_text_wdata_qid;}
|
||||
@Override public void Qid_bgn() {qid_bldr = new Wdata_idx_bldr_qid().Ctor(this, bldr, wiki, dump_fil_len);}
|
||||
@Override public void Qid_add(byte[] wiki_key, int ns_id, byte[] ttl, byte[] qid) {
|
||||
qid_bldr.Add(String_.new_u8(wiki_key), Int_.To_str_pad_bgn_zero(ns_id, 3), ttl, qid);
|
||||
}
|
||||
@Override public void Qid_end() {
|
||||
qid_bldr.Flush();
|
||||
qid_bldr.Make();
|
||||
}
|
||||
}
|
||||
class Wdata_idx_bldr_qid extends Wdata_idx_mgr_base {
|
||||
public Wdata_idx_bldr_qid Ctor(Xob_wdata_qid_base wkr, Xob_bldr bldr, Xowe_wiki wiki, int dump_fil_len) {super.Ctor(wkr, bldr, wiki, dump_fil_len); return this;}
|
||||
public void Add(String wiki_key, String ns_num_str, byte[] ttl, byte[] qid) {
|
||||
Wdata_idx_wtr wtr = Get_or_new(wiki_key, ns_num_str);
|
||||
wtr.Write(ttl, qid);
|
||||
}
|
||||
private Wdata_idx_wtr Get_or_new(String wiki_key, String ns_num_str) {
|
||||
String wtr_key = wiki_key + "|" + ns_num_str;
|
||||
Object rv = hash.Get_by(wtr_key);
|
||||
if (rv == null) {
|
||||
Wdata_idx_wtr wtr = Wdata_idx_wtr.new_qid_(wiki, wiki_key, ns_num_str, dump_fil_len);
|
||||
hash.Add(wtr_key, wtr);
|
||||
return wtr;
|
||||
}
|
||||
return (Wdata_idx_wtr)rv;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*;
|
||||
class Xowb_json_dump_db {
|
||||
private final Xoae_app app; private final Gfo_usr_dlg usr_dlg; private final Xowe_wiki wiki; private final Xob_bldr bldr;
|
||||
private final Json_parser json_parser;
|
||||
private final Xob_wdata_pid_sql pid_cmd; private final Xob_wdata_qid_sql qid_cmd = new Xob_wdata_qid_sql();
|
||||
private final Xob_wdata_pid pid_cmd; private final Xob_wdata_qid qid_cmd;
|
||||
private Xow_ns_mgr ns_mgr; private Xow_db_mgr db_mgr;
|
||||
private Xowd_page_tbl page_tbl; private Xob_ns_to_db_mgr ns_to_db_mgr;
|
||||
private Io_stream_zip_mgr text_zip_mgr; private byte text_zip_tid;
|
||||
@@ -32,7 +32,8 @@ class Xowb_json_dump_db {
|
||||
this.app = bldr.App(); this.usr_dlg = app.Usr_dlg(); this.wiki = wiki; this.bldr = bldr;
|
||||
this.json_parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
|
||||
this.ns_mgr = wiki.Ns_mgr();
|
||||
this.pid_cmd = new Xob_wdata_pid_sql(wiki.Data__core_mgr().Db__wbase().Conn(), null);
|
||||
this.pid_cmd = new Xob_wdata_pid(wiki.Data__core_mgr().Db__wbase().Conn());
|
||||
this.qid_cmd = new Xob_wdata_qid(wiki.Data__core_mgr().Db__wbase().Conn());
|
||||
}
|
||||
public void Parse_all_bgn(long src_fil_len, String src_fil_name) {
|
||||
// load wiki
|
||||
@@ -57,7 +58,7 @@ class Xowb_json_dump_db {
|
||||
this.page_modified_on = Datetime_now.Get();
|
||||
page_tbl.Insert_bgn();
|
||||
qid_cmd.Page_wkr__bgn();
|
||||
pid_cmd.Pid_bgn();
|
||||
pid_cmd.Pid__bgn();
|
||||
}
|
||||
public void Parse_doc(byte[] json_bry) {
|
||||
// parse to jdoc
|
||||
@@ -78,17 +79,17 @@ class Xowb_json_dump_db {
|
||||
|
||||
// insert text
|
||||
if (jdoc_is_qid) {
|
||||
qid_cmd.Parse_jdoc(jdoc);
|
||||
qid_cmd.Qid__run(jdoc);
|
||||
++page_count_main;
|
||||
}
|
||||
else
|
||||
pid_cmd.Parse_jdoc(jdoc);
|
||||
pid_cmd.Pid__run(jdoc);
|
||||
}
|
||||
public void Parse_all_end() {
|
||||
page_tbl.Insert_end();
|
||||
page_tbl.Create_idx();
|
||||
qid_cmd.Qid_end();
|
||||
pid_cmd.Pid_end();
|
||||
qid_cmd.Qid__end();
|
||||
pid_cmd.Pid__end();
|
||||
ns_to_db_mgr.Rls_all();
|
||||
|
||||
// cleanup core
|
||||
|
||||
@@ -18,117 +18,189 @@ 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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_string(1, "a"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
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.Init__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_label("en", "b")
|
||||
);
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_entity_qid(1, 2))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
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
|
||||
// set wiki to French
|
||||
fxt.Wiki().Wdata_wiki_lang_(Bry_.new_a7("fr"));
|
||||
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_entity_qid(1, 2))
|
||||
.Add_sitelink("frwiki", "Test_page")
|
||||
);
|
||||
|
||||
// create wdata page Q2 with label in en (not fr)
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_label("en", "b")
|
||||
);
|
||||
|
||||
// parse; should get en label
|
||||
fxt.Test_parse("{{#property:p1}}", "b");
|
||||
}
|
||||
@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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_entity_qid(1, 2)) // create wdata page Q1 with prop entity reference to Q2; note that Q2 is not created
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_time(1, "2012-01-02 03:04:05"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_geo(1, "6.789", "1.2345"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
fxt.Test_parse("{{#property:p1}}", "1°14'4.2"N, 6°47'20.4"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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_quantity(1, "+1234", "1", "+1236", "+1232"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_quantity(1, "+1234", "1", "+1234", "+1234"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_quantity(1, "+1234", "1", "+1236", "+1233"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_quantity(1, "+4321000000", "1", "4321000000", "4321000000"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_quantity(1, "+1234", "http://www.wikidata.org/entity/Q2", "+1236", "+1232"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_claims(fxt.Make_claim_string(2, "a"))
|
||||
.Add_label("en", "meter")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_quantity(1, "+1234.50", "1", "+1236.75", "+1232.25"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_monolingual(1, "la", "Lorem ipsum dolor sit amet"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_novalue(1))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_somevalue(1))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_string(1, "a"), fxt.Make_claim_string(1, "b"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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");
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_claims(fxt.Make_claim_string(1, "a"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_claims(fxt.Make_claim_string(1, "a"))
|
||||
.Add_sitelink("enwiki", "Of_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Property:P2")
|
||||
.Add_claims(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__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_claims(fxt.Make_claim_string(1, "a"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
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__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_claims(fxt.Make_claim_string(1, "a"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
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() {
|
||||
|
||||
@@ -18,14 +18,23 @@ 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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_string(1, "a"))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
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.Init__docs__add(fxt.Wdoc("Q1")
|
||||
.Add_claims(fxt.Make_claim_entity_qid(1, 2))
|
||||
.Add_sitelink("enwiki", "Test_page")
|
||||
);
|
||||
|
||||
fxt.Init__docs__add(fxt.Wdoc("Q2")
|
||||
.Add_label("en", "b")
|
||||
);
|
||||
|
||||
fxt.Test_parse("{{#statements:p1}}", "[[b]]");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user