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

Wikibase: Infer datatype from cached table not from JSON doc

This commit is contained in:
gnosygnu
2016-12-01 11:07:33 -05:00
parent b3566def7e
commit da18f05d9f
10 changed files with 172 additions and 23 deletions

View File

@@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.data.*;
public class Wbase_prop_mgr { // lang-agnostic registry of props; EX: "p15" -> commonsmedia
private boolean init_needed = true;
private Ordered_hash hash;
public Wbase_prop_mgr(Wbase_prop_mgr_loader loader) {
this.loader = loader;
}
public Wbase_prop_mgr_loader Loader() {return loader;} private Wbase_prop_mgr_loader loader;
public void Loader_(Wbase_prop_mgr_loader v) {
loader = v;
init_needed = true;
}
private void Init() {
init_needed = false;
hash = loader.Load();
}
public String Get_or_null(String pid) {
if (init_needed) Init();
if (hash == null) return null;
String rv = (String)hash.Get_by(pid);
if (rv == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "wbase:could not find datatype for pid; pid=~{0}", pid);
}
return rv;
}
}

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.wikis.data.*;
public interface Wbase_prop_mgr_loader {
Ordered_hash Load();
}

View File

@@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.wbases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Wbase_prop_mgr_loader_ {
public static Wbase_prop_mgr_loader New_mock(Keyval... pairs) {
return new Wbase_prop_mgr_loader__mock(pairs);
}
public static Wbase_prop_mgr_loader New_db(Wdata_wiki_mgr wbase_mgr) {
return new Wbase_prop_mgr_loader__db(wbase_mgr);
}
}
class Wbase_prop_mgr_loader__mock implements Wbase_prop_mgr_loader {
private final Keyval[] pairs;
public Wbase_prop_mgr_loader__mock(Keyval[] pairs) {
this.pairs = pairs;
}
public Ordered_hash Load() {
Ordered_hash rv = Ordered_hash_.New();
for (Keyval kv : pairs)
rv.Add(kv.Key(), kv.Val_to_str_or_empty());
return rv;
}
}
class Wbase_prop_mgr_loader__db implements Wbase_prop_mgr_loader {
private final Wdata_wiki_mgr wbase_mgr;
public Wbase_prop_mgr_loader__db(Wdata_wiki_mgr wbase_mgr) {
this.wbase_mgr = wbase_mgr;
}
public Ordered_hash Load() {
gplx.xowa.wikis.data.Xow_db_file wbase_db = wbase_mgr.Wdata_wiki().Data__core_mgr().Db__wbase();
if (!wbase_db.Conn().Meta_tbl_exists(wbase_db.Tbl__wbase_prop().Tbl_name())) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "wbase:prop tbl missing");
return null;
}
return wbase_db.Tbl__wbase_prop().Select_all();
}
}

View File

@@ -28,13 +28,14 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
private final Wdata_prop_val_visitor prop_val_visitor;
private final Wdata_doc_parser wdoc_parser_v1 = new Wdata_doc_parser_v1(), wdoc_parser_v2 = new Wdata_doc_parser_v2();
private final Object thread_lock = new Object();
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32);
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32);
public Wdata_wiki_mgr(Xoae_app app) {
this.app = app;
this.evt_mgr = new Gfo_evt_mgr(this);
this.Qid_mgr = new Wbase_qid_mgr(this);
this.Pid_mgr = new Wbase_pid_mgr(this);
this.Doc_mgr = new Wbase_doc_mgr(app, this, this.Qid_mgr);
this.prop_mgr = new Wbase_prop_mgr(Wbase_prop_mgr_loader_.New_db(this));
this.prop_val_visitor = new Wdata_prop_val_visitor(app, this);
this.Enabled_(true);
}
@@ -42,6 +43,7 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
public final Wbase_qid_mgr Qid_mgr;
public final Wbase_pid_mgr Pid_mgr;
public final Wbase_doc_mgr Doc_mgr;
public Wbase_prop_mgr Prop_mgr() {return prop_mgr;} private final Wbase_prop_mgr prop_mgr;
public boolean Enabled() {return enabled;} private boolean enabled;
public void Enabled_(boolean v) {
this.enabled = v;

View File

@@ -34,6 +34,7 @@ public class Wdata_wiki_mgr_fxt {
app.Xwiki_mgr__sitelink_mgr().Init_by_app();
wdoc_bldr = new Wdata_doc_bldr();
wdata_mgr = app.Wiki_mgr().Wdata_mgr();
wdata_mgr.Prop_mgr().Loader_(Wbase_prop_mgr_loader_.New_mock());
wdata_mgr.Clear();
if (reset) {
Io_mgr.Instance.InitEngine_mem();

View File

@@ -49,14 +49,14 @@ public class Xowb_prop_tbl implements Db_tbl {
return rv;
}
private void Select_all__add(Ordered_hash hash, Db_rdr rdr) {
byte[] pid = rdr.Read_bry_by_str(fld__wbp_pid);
String pid = rdr.Read_str(fld__wbp_pid);
byte datatype_id = (byte)rdr.Read_int(fld__wbp_datatype);
Wbase_enum_itm datatype_itm = Wbase_claim_type_.Reg.Get_itm_or((byte)datatype_id, null);
if (datatype_itm == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "wbase:invalid prop datatype_id; pid=~{0} datatype=~{1}", pid, datatype_id);
datatype_itm = Wbase_claim_type_.Itm__string;
}
hash.Add(pid, datatype_itm);
hash.Add_if_dupe_use_1st(pid, datatype_itm.Key_str());
}
public void Rls() {}
}