1
0
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:
gnosygnu
2018-07-11 07:53:27 -04:00
parent fe0d1abde5
commit be3979c5af
44 changed files with 663 additions and 1954 deletions

View File

@@ -1,162 +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.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.xowa.wikis.tdbs.*;
import gplx.xowa.wikis.nss.*;
public class Xow_data_mgr_tst {
Xow_data_mgr_fxt fxt = new Xow_data_mgr_fxt();
@Before public void init() {fxt.Clear(); Datetime_now.Manual_y_();}
@After public void term() {Datetime_now.Manual_n_();}
@Test public void Create() {
fxt .Create("A1", "A1 data")
.Create("B12", "B12 data")
.Create("C123", "C123 data")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!9|!!!!;|!!!!=|"
, "!!!!!\t##PX+\tA1\tA1 data\t"
, "!!!!\"\t##PX/\tB12\tB12 data\t"
, "!!!!#\t##PX0\tC123\tC123 data\t"
))
;
}
@Test public void Update() {
fxt .Create("A1", "A1 data")
.Create("B12", "B12 data")
.Create("C123", "C123 data")
.Update("B12", "B12 changed")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!9|!!!!>|!!!!=|"
, "!!!!!\t##PX+\tA1\tA1 data\t"
, "!!!!\"\t##PX/\tB12\tB12 changed\t"
, "!!!!#\t##PX0\tC123\tC123 data\t"
))
;
}
@Test public void Update_zip() {
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Tid__main].Ext_tid_(gplx.core.ios.streams.Io_stream_tid_.Tid__zip);
// fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok());
// fxt .Create("A1", "A1 data")
// .Create("B12", "B12 data")
// .Create("C123", "C123 data")
// .Update("B12", "B12 changed")
// .Tst_regy_title("0|A1|C123|3\n")
// .Tst_data_title(String_.Concat_lines_nl
// ( "!!!!>|!!!!?|!!!!@|"
// , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
// , "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
// , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
// ))
// .Tst_data_page(String_.Concat_lines_nl
// ( "zipped:!!!!9|!!!!>|!!!!=|"
// , "!!!!!\t##PX+\tA1\tA1 data\t"
// , "!!!!\"\t##PX/\tB12\tB12 changed\t"
// , "!!!!#\t##PX0\tC123\tC123 data\t"
// ))
// ;
}
@Test public void Create_out_of_order() {
fxt .Create("C123", "C123 data")
.Create("B12", "B12 data")
.Create("A1", "A1 data")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!#|!!!!!|!!!!#|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
, "!!!!!|!!!!!|!!!!!|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!=|!!!!;|!!!!9|"
, "!!!!!\t##PX+\tC123\tC123 data\t"
, "!!!!\"\t##PX/\tB12\tB12 data\t"
, "!!!!#\t##PX0\tA1\tA1 data\t"
))
;
}
@Test public void Rename() {
fxt .Create("A1", "A1 data")
.Create("B12", "B12 data")
.Create("C123", "C123 data")
.Rename("C123", "C1234")
.Tst_regy_title("0|A1|C123|3\n")
.Tst_data_title(String_.Concat_lines_nl
( "!!!!>|!!!!?|!!!!@|"
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
))
.Tst_data_page(String_.Concat_lines_nl
( "!!!!9|!!!!;|!!!!=|"
, "!!!!!\t##PX+\tA1\tA1 data\t"
, "!!!!\"\t##PX/\tB12\tB12 data\t"
, "!!!!#\t##PX0\tC123\tC123 data\t"
))
;
}
}
class Xow_data_mgr_fxt {
Xoae_app app;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public void Clear() {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
wiki.Db_mgr().Save_mgr().Page_id_next_(0);
}
public Xow_data_mgr_fxt Create(String ttl_str, String data) {
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
wiki.Db_mgr().Save_mgr().Data_create(wiki, ttl, Bry_.new_u8(data));
return this;
}
public Xow_data_mgr_fxt Update(String ttl_str, String data) {
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
Xoae_page page = Xoae_page.New_test(wiki, ttl);
wiki.Db_mgr().Save_mgr().Data_update(page, Bry_.new_u8(data));
return this;
}
public Xow_data_mgr_fxt Rename(String old_ttl, String new_ttl) {
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(old_ttl));
Xoae_page page = Xoae_page.New_test(wiki, ttl);
wiki.Db_mgr().Save_mgr().Data_rename(page, ttl.Ns().Id(), Bry_.new_u8(new_ttl));
return this;
}
public Xow_data_mgr_fxt Tst_regy_title(String expd) {return Tst_regy(Xotdb_dir_info_.Name_title, expd);}
Xow_data_mgr_fxt Tst_regy(String name, String expd) {
Io_url file_orig = Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/ns/000/" + name + "/reg.csv");
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(file_orig));
return this;
}
public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Tid__main, 0, expd);}
public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Tid__main, 0, expd);}
public Xow_data_mgr_fxt Tst_data(byte dir_tid, int ns_id, int fil, String expd) {
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(dir_tid, ns_id, fil);
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
return this;
}
}

View File

@@ -1,58 +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.wikis.tdbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.brys.*; import gplx.core.ios.*; import gplx.core.encoders.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.wikis.tdbs.bldrs.*;
public class Xotdb_page_raw_parser {
public void Init(Gfo_usr_dlg usr_dlg, Xowe_wiki wiki, int load_len) {
this.wiki = wiki; ns_mgr = wiki.Ns_mgr();
rdr = new Io_line_rdr(usr_dlg, new Io_url[1]);
rdr.Line_dlm_(Byte_ascii.Tab).Load_len_(load_len).Key_gen_(Io_line_rdr_key_gen_all.Instance);
}
public void Init_ns(Xow_ns ns_itm) {this.ns_itm = ns_itm;}
public void Reset_one(Io_url url) {
rdr.Reset_one(url);
}
public void Load(Gfo_usr_dlg usr_dlg, Xowe_wiki wiki, Xow_ns ns_itm, Io_url[] urls, int load_len) {
this.wiki = wiki; ns_mgr = wiki.Ns_mgr(); this.ns_itm = ns_itm;
rdr = new Io_line_rdr(usr_dlg, urls);
rdr.Line_dlm_(Byte_ascii.Tab).Load_len_(load_len).Key_gen_(Io_line_rdr_key_gen_all.Instance);
} Io_line_rdr rdr; Xowe_wiki wiki; Xow_ns_mgr ns_mgr; Xow_ns ns_itm;
public void Skip_first_line() {
rdr.Read_next();
int pos = Bry_find_.Find_fwd(rdr.Bfr(), Byte_ascii.Nl);
// rdr.Move(pos + 1);
rdr.Truncate(pos + 1);
}
public boolean Read(Xowd_page_itm page) {
boolean read = false;
read = rdr.Read_next(); if (!read) return false;
int id = Base85_.To_int_by_bry(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 2);
page.Id_(id);
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read timestamp");
int timestamp = Base85_.To_int_by_bry(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp));
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read ttl");
byte[] ttl = Bry_.Mid(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
page.Ttl_(ttl, ns_mgr);
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read text");
byte[] text = Bry_.Mid(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
page.Text_(text);
rdr.Bfr_last_read_add(1);
return true;
}
}

View File

@@ -1,41 +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.wikis.tdbs.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
import gplx.core.strings.*;
public class Xob_stat_itm {
public String Ns() {return ns;} private String ns;
public int Fils;
public long Size, SizeMax = Int_.Min_value, SizeMin = Int_.Max_value;
public int SizeMaxIdx, SizeMinIdx;
public void Tally(long size, int idx) {
Fils++;
Size += size;
if (size > SizeMax) {SizeMax = size; SizeMaxIdx = idx;}
if (size < SizeMin) {SizeMin = size; SizeMinIdx = idx;}
}
public void To_str(String_bldr sb) {
XtoStr_fld(sb, ns).XtoStr_fld(sb, Fils).XtoStr_fld(sb, Size).XtoStr_fld(sb, SizeMax).XtoStr_fld(sb, SizeMaxIdx).XtoStr_fld(sb, SizeMin);
sb.Add(Int_.To_str(SizeMinIdx));
}
Xob_stat_itm XtoStr_fld(String_bldr sb, long v) {sb.Add(Long_.To_str(v)).Add(Xob_stat_itm.Dlm); return this;}
Xob_stat_itm XtoStr_fld(String_bldr sb, int v) {sb.Add(Int_.To_str(v)).Add(Xob_stat_itm.Dlm); return this;}
Xob_stat_itm XtoStr_fld(String_bldr sb, String v) {sb.Add(v).Add(Xob_stat_itm.Dlm); return this;}
public Xob_stat_itm(String ns) {
this.ns = ns;
}
public Object NewByKey(Object o) {return new Xob_stat_itm((String)o);} public static final Xob_stat_itm Instance = new Xob_stat_itm(); Xob_stat_itm() {}
public static final char Dlm = '|';
}

View File

@@ -1,67 +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.wikis.tdbs.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
import gplx.core.strings.*;
import gplx.xowa.wikis.nss.*;
public class Xob_stat_mgr {
public Xob_stat_type GetOrNew(byte tid) {
Xob_stat_type rv = (Xob_stat_type)regy.Get_by(tid);
if (rv == null) {
rv = new Xob_stat_type(tid);
regy.Add(tid, rv);
}
return rv;
}
public String Print(Xow_ns_mgr nsMgr) {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < regy.Count(); i++) {
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
sb.Add(String_.PadEnd(Xotdb_dir_info_.Tid_name(typ.Tid()), 6, " "));
}
sb.Add_str_w_crlf("ns");
String[] nsAry = GetNmsAry(nsMgr);
for (String ns : nsAry) {
for (int i = 0; i < regy.Count(); i++) {
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
Xob_stat_itm itm = (Xob_stat_itm)typ.GetOrNew(ns);
sb.Add(Int_.To_str_pad_bgn_zero(itm.Fils, 5)).Add(" ");
}
sb.Add_str_w_crlf(ns);
}
return sb.To_str();
}
public String To_str() {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < regy.Count(); i++) {
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
typ.To_str(sb);
}
return sb.To_str();
}
String[] GetNmsAry(Xow_ns_mgr nsMgr) {
Ordered_hash nsRegy = Ordered_hash_.New();
for (int i = 0; i < regy.Count(); i++) {
Xob_stat_type typ = (Xob_stat_type)regy.Get_at(i);
for (int j = 0; j < typ.Count(); j++) {
Xob_stat_itm itm = (Xob_stat_itm)typ.GetAt(j);
if (!nsRegy.Has(itm.Ns()))
nsRegy.Add_as_key_and_val(itm.Ns());
}
}
return (String[])nsRegy.To_ary(String.class);
}
Ordered_hash regy = Ordered_hash_.New();
}

View File

@@ -1,41 +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.wikis.tdbs.stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.tdbs.*;
import gplx.core.strings.*; import gplx.xowa.wikis.tdbs.*;
public class Xob_stat_type {
public byte Tid() {return tid;} private byte tid;
public Xob_stat_type(byte tid) {this.tid = tid;}
public Xob_stat_itm GetOrNew(String ns) {
Xob_stat_itm rv = (Xob_stat_itm)regy.Get_by(ns);
if (rv == null) {
rv = new Xob_stat_itm(ns);
regy.Add(ns, rv);
}
return rv;
}
public Xob_stat_itm GetAt(int i) {return (Xob_stat_itm)regy.Get_at(i);}
public int Count() {return regy.Count();}
public void To_str(String_bldr sb) {
for (int i = 0; i < regy.Count(); i++) {
Xob_stat_itm itm = (Xob_stat_itm)regy.Get_at(i);
sb.Add(Xotdb_dir_info_.Tid_name(tid)).Add(Xob_stat_itm.Dlm);
itm.To_str(sb);
sb.Add(Byte_ascii.Nl);
}
}
Ordered_hash regy = Ordered_hash_.New();
public static final Xob_stat_type Instance = new Xob_stat_type(); Xob_stat_type() {}
}