mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Wikibase: Add isValidEntityId
This commit is contained in:
@@ -57,6 +57,7 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
case Proc_incrementExpensiveFunctionCount: return IncrementExpensiveFunctionCount(args, rslt);
|
||||
case Proc_getPropertyOrder: return GetPropertyOrder(args, rslt);
|
||||
case Proc_orderProperties: return OrderProperties(args, rslt);
|
||||
case Proc_isValidEntityId: return IsValidEntityId(args, rslt);
|
||||
default: throw Err_.new_unhandled(key);
|
||||
}
|
||||
}
|
||||
@@ -64,17 +65,18 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
Proc_getLabel = 0 //, Proc_getLabelByLanguage = 1
|
||||
, Proc_getEntity = 2, Proc_getEntityStatements = 3, Proc_getSetting = 4, Proc_getEntityUrl = 5, Proc_renderSnak = 6//, Proc_formatValue = 7
|
||||
, Proc_renderSnaks = 8, Proc_getEntityId = 9, Proc_getUserLang = 10, Proc_getDescription = 11, Proc_resolvePropertyId = 12
|
||||
, Proc_getSiteLinkPageName = 13, Proc_incrementExpensiveFunctionCount = 14, Proc_getPropertyOrder = 15, Proc_orderProperties = 16;
|
||||
, Proc_getSiteLinkPageName = 13, Proc_incrementExpensiveFunctionCount = 14, Proc_getPropertyOrder = 15, Proc_orderProperties = 16, Proc_isValidEntityId = 17;
|
||||
public static final String
|
||||
Invk_getLabel = "getLabel", Invk_getLabelByLanguage = "getLabelByLanguage", Invk_getEntity = "getEntity", Invk_getEntityStatements = "getEntityStatements"
|
||||
, Invk_getSetting = "getSetting", Invk_getEntityUrl = "getEntityUrl", Invk_renderSnak = "renderSnak", Invk_formatValue = "formatValue", Invk_renderSnaks = "renderSnaks"
|
||||
, Invk_getEntityId = "getEntityId", Invk_getUserLang = "getUserLang", Invk_getDescription = "getDescription", Invk_resolvePropertyId = "resolvePropertyId"
|
||||
, Invk_getSiteLinkPageName = "getSiteLinkPageName", Invk_incrementExpensiveFunctionCount = "incrementExpensiveFunctionCount", Invk_getPropertyOrder = "getPropertyOrder", Invk_orderProperties = "orderProperties"
|
||||
, Invk_isValidEntityId = "isValidEntityId"
|
||||
;
|
||||
private static final String[] Proc_names = String_.Ary
|
||||
( Invk_getLabel, Invk_getLabelByLanguage, Invk_getEntity, Invk_getEntityStatements, Invk_getSetting, Invk_getEntityUrl, Invk_renderSnak, Invk_formatValue, Invk_renderSnaks
|
||||
, Invk_getEntityId, Invk_getUserLang, Invk_getDescription, Invk_resolvePropertyId, Invk_getSiteLinkPageName, Invk_incrementExpensiveFunctionCount
|
||||
, Invk_getPropertyOrder, Invk_orderProperties
|
||||
, Invk_getPropertyOrder, Invk_orderProperties, Invk_isValidEntityId
|
||||
);
|
||||
public void Notify_page_changed() {if (notify_page_changed_fnc != null) core.Interpreter().CallFunction(notify_page_changed_fnc.Id(), Keyval_.Ary_empty);}
|
||||
public boolean GetLabel(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
@@ -144,7 +146,9 @@ public class Scrib_lib_wikibase implements Scrib_lib {
|
||||
return rslt.Init_null();
|
||||
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl_claims_prop_ary(prop_mgr, String_.new_u8(propertyId), statements, 1));
|
||||
}
|
||||
/*
|
||||
public boolean IsValidEntityId(Scrib_proc_args args, Scrib_proc_rslt rslt) {
|
||||
return rslt.Init_obj(true);
|
||||
} /*
|
||||
public function formatValues( $snaksSerialization ) {
|
||||
$this->checkType( 'formatValues', 1, $snaksSerialization, 'table' );
|
||||
try {
|
||||
|
||||
@@ -19,18 +19,20 @@ 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 String Page_wkr__key();
|
||||
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)
|
||||
parser = bldr.App().Wiki_mgr().Wdata_mgr().Jdoc_parser();
|
||||
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()));
|
||||
@@ -56,5 +58,5 @@ public abstract class Xob_wdata_pid_base extends Xob_itm_dump_base implements Xo
|
||||
}
|
||||
}
|
||||
public void Page_wkr__end() {this.Pid_end();}
|
||||
static final String GRP_KEY = "xowa.wdata.pid_wkr";
|
||||
private static final String GRP_KEY = "xowa.wdata.pid_wkr";
|
||||
}
|
||||
|
||||
@@ -16,8 +16,9 @@ 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 {
|
||||
gplx.xowa.bldrs.Xob_fxt fxt = new gplx.xowa.bldrs.Xob_fxt().Ctor_mem();
|
||||
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);
|
||||
@@ -51,7 +52,7 @@ public class Xob_wdata_pid_base_tst {
|
||||
, "0|p1_fr|p2_fr|2"
|
||||
, ""
|
||||
)
|
||||
.Run(new Xob_wdata_pid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
|
||||
.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) {
|
||||
|
||||
@@ -17,13 +17,15 @@ package gplx.xowa.xtns.wbases.imports; import gplx.*; import gplx.xowa.*; import
|
||||
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 final Db_conn conn;
|
||||
private Xowd_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) {
|
||||
this.conn = conn;
|
||||
}
|
||||
@Override public String Page_wkr__key() {return gplx.xowa.bldrs.Xob_cmd_keys.Key_wbase_pid;}
|
||||
@Override public void Pid_bgn() {
|
||||
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
|
||||
// init datatype_hash
|
||||
Wbase_enum_hash enum_hash = Wbase_claim_type_.Reg;
|
||||
byte len = (byte)enum_hash.Len();
|
||||
@@ -33,12 +35,12 @@ public class Xob_wdata_pid_sql extends Xob_wdata_pid_base {
|
||||
}
|
||||
|
||||
// init wbase_pid
|
||||
tbl__pid = db_mgr.Db__wbase().Tbl__wbase_pid();
|
||||
tbl__pid = new Xowd_wbase_pid_tbl(conn, false); // schema_is_1 == false b/c new wbase_db will always be latest version
|
||||
tbl__pid.Create_tbl();
|
||||
tbl__pid.Insert_bgn();
|
||||
|
||||
// init wbase_prop
|
||||
tbl__prop = db_mgr.Db__wbase().Tbl__wbase_prop();
|
||||
tbl__prop = new Xowb_prop_tbl(conn);
|
||||
tbl__prop.Create_tbl();
|
||||
tbl__prop.Insert_bgn();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
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);
|
||||
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(), "'", "\"");
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class Xob_wdata_qid_base_tst {
|
||||
, "0|Q1_fr|Q2_fr|2"
|
||||
, ""
|
||||
)
|
||||
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
|
||||
.Run_page_wkrs(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
|
||||
;
|
||||
}
|
||||
@Test public void Ns() {
|
||||
@@ -84,7 +84,7 @@ public class Xob_wdata_qid_base_tst {
|
||||
, "0|Q1_fr|Q1_fr|1"
|
||||
, ""
|
||||
)
|
||||
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
|
||||
.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
|
||||
@@ -130,7 +130,7 @@ public class Xob_wdata_qid_base_tst {
|
||||
, "0|Q1_fr|Q2_fr|2"
|
||||
, ""
|
||||
)
|
||||
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
|
||||
.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
|
||||
@@ -160,7 +160,7 @@ public class Xob_wdata_qid_base_tst {
|
||||
, "0|Q1_fr|Q2_fr|2"
|
||||
, ""
|
||||
)
|
||||
.Run(new Xob_wdata_qid_txt().Ctor(fxt.Bldr(), this.fxt.Wiki()))
|
||||
.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) {
|
||||
|
||||
@@ -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 = new Xob_wdata_pid_sql(); private final Xob_wdata_qid_sql qid_cmd = new Xob_wdata_qid_sql();
|
||||
private final Xob_wdata_pid_sql pid_cmd; private final Xob_wdata_qid_sql qid_cmd = new Xob_wdata_qid_sql();
|
||||
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,6 +32,7 @@ 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());
|
||||
}
|
||||
public void Parse_all_bgn(long src_fil_len, String src_fil_name) {
|
||||
// load wiki
|
||||
|
||||
Reference in New Issue
Block a user