2015-07-13 01:10:02 +00:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
2015-09-21 03:43:51 +00:00
|
|
|
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*;
|
2016-04-18 03:47:45 +00:00
|
|
|
import gplx.core.btries.*; import gplx.xowa.bldrs.wkrs.*;
|
2015-09-21 03:43:51 +00:00
|
|
|
import gplx.xowa.wikis.data.tbls.*;
|
2016-03-28 03:44:59 +00:00
|
|
|
public class Xobd_parser implements Xob_page_wkr {
|
2016-04-18 03:47:45 +00:00
|
|
|
private final Xob_bldr bldr;
|
|
|
|
private final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7(); // NOTE:ci.ascii:MW_const.en; ctg.v1 assumes [[Category:
|
2016-06-20 03:58:10 +00:00
|
|
|
private final List_adp wkr_list = List_adp_.New();
|
2016-04-18 03:47:45 +00:00
|
|
|
public String Page_wkr__key() {return KEY;} static final String KEY = "page_parser";
|
|
|
|
public Xobd_parser(Xob_bldr bldr) {this.bldr = bldr;}
|
2015-07-13 01:10:02 +00:00
|
|
|
public void Wkr_add(Xobd_parser_wkr wkr) {wkr_list.Add(wkr);}
|
2016-04-18 03:47:45 +00:00
|
|
|
public void Page_wkr__bgn() {
|
2015-07-13 01:10:02 +00:00
|
|
|
int wkr_list_len = wkr_list.Count();
|
|
|
|
for (int i = 0; i < wkr_list_len; i++) {
|
|
|
|
Xobd_parser_wkr wkr = (Xobd_parser_wkr)wkr_list.Get_at(i);
|
2016-04-18 03:47:45 +00:00
|
|
|
wkr.Wkr_bgn(bldr);
|
2015-07-13 01:10:02 +00:00
|
|
|
int hooks_len = wkr.Wkr_hooks().Count();
|
|
|
|
for (int j = 0; j < hooks_len; j++) {
|
|
|
|
byte[] bry = (byte[])wkr.Wkr_hooks().Get_at(j);
|
|
|
|
trie.Add_obj(bry, wkr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-18 03:47:45 +00:00
|
|
|
public void Page_wkr__run(Xowd_page_itm page) {
|
2015-07-13 01:10:02 +00:00
|
|
|
byte[] src = page.Text(); int src_len = src.length;
|
|
|
|
int pos = 0;
|
|
|
|
while (true) {
|
|
|
|
if (pos == src_len) break;
|
|
|
|
Object o = trie.Match_bgn(src, pos, src_len);
|
|
|
|
if (o == null)
|
|
|
|
++pos;
|
|
|
|
else {
|
|
|
|
Xobd_parser_wkr wkr = (Xobd_parser_wkr)o;
|
|
|
|
pos = wkr.Wkr_run(page, src, src_len, pos, trie.Match_pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-18 03:47:45 +00:00
|
|
|
public void Page_wkr__run_cleanup() {}
|
|
|
|
public void Page_wkr__end() {
|
2015-07-13 01:10:02 +00:00
|
|
|
int wkr_list_len = wkr_list.Count();
|
|
|
|
for (int i = 0; i < wkr_list_len; i++) {
|
|
|
|
Xobd_parser_wkr wkr = (Xobd_parser_wkr)wkr_list.Get_at(i);
|
|
|
|
wkr.Wkr_end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
2015-07-20 03:16:49 +00:00
|
|
|
throw Err_.new_unimplemented();
|
2015-07-13 01:10:02 +00:00
|
|
|
}
|
|
|
|
}
|