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

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
/*
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.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.core.primitives.*;
import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wbase_claim_grp {
public Wbase_claim_grp(Int_obj_ref id_ref, Wbase_claim_base[] itms) {this.id_ref = id_ref; this.itms = itms;}
public Int_obj_ref Id_ref() {return id_ref;} private final Int_obj_ref id_ref;
public int Id() {return id_ref.Val();}
public String Id_str() {if (id_str == null) id_str = "P" + Int_.To_str(id_ref.Val()); return id_str;} private String id_str;
public int Len() {return itms.length;} private Wbase_claim_base[] itms;
public Wbase_claim_base Get_at(int i) {return itms[i];}
public static List_adp Xto_list(Ordered_hash hash) {
int len = hash.Count();
List_adp rv = List_adp_.New();
for (int i = 0; i < len; ++i) {
Wbase_claim_grp grp = (Wbase_claim_grp)hash.Get_at(i);
int grp_len = grp.Len();
for (int j = 0; j < grp_len; ++j)
rv.Add(grp.Get_at(j));
}
return rv;
}
}

View File

@@ -0,0 +1,24 @@
/*
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.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wbase_claim_grp_list {
private Ordered_hash hash = Ordered_hash_.New();
public void Add(Wbase_claim_grp itm) {hash.Add(itm.Id_ref(), itm);}
public int Len() {return hash.Count();}
public Wbase_claim_grp Get_at(int i) {return (Wbase_claim_grp)hash.Get_at(i);}
}

View File

@@ -0,0 +1,28 @@
/*
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.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.wbases.claims.itms.*;
public interface Wbase_claim_visitor {
void Visit_str (Wbase_claim_string itm);
void Visit_entity (Wbase_claim_entity itm);
void Visit_monolingualtext (Wbase_claim_monolingualtext itm);
void Visit_quantity (Wbase_claim_quantity itm);
void Visit_time (Wbase_claim_time itm);
void Visit_globecoordinate (Wbase_claim_globecoordinate itm);
void Visit_system (Wbase_claim_value itm);
}

View File

@@ -0,0 +1,23 @@
/*
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.claims; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
public class Wbase_references_grp {
public Wbase_references_grp(Wbase_claim_grp_list references, int[] references_order) {this.references = references; this.references_order = references_order;}
public Wbase_claim_grp_list References() {return references;} private Wbase_claim_grp_list references;
public int[] References_order() {return references_order;} private int[] references_order;
}

View File

@@ -0,0 +1,29 @@
/*
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.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_entity_type_ {
public static final byte
Tid__item = 0
, Tid__property = 1
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.entity_type", 2);
public static final Wbase_enum_itm
Itm__item = Reg.Add(Tid__item , "item")
, Itm__property = Reg.Add(Tid__property , "property")
;
}

View File

@@ -0,0 +1,33 @@
/*
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.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_rank_ {
public static final byte // SERIALIZED.MW
Tid__preferred = 2
, Tid__normal = 1
, Tid__deprecated = 0
, Tid__unknown = 3
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.rank", 4);
public static final Wbase_enum_itm
Itm__preferred = Reg.Add(Tid__preferred , "preferred")
, Itm__normal = Reg.Add(Tid__normal , "normal")
, Itm__deprecated = Reg.Add(Tid__deprecated , "deprecated")
, Itm__unknown = Reg.Add(Tid__unknown , "unknown")
;
}

View File

@@ -0,0 +1,23 @@
/*
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.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_type extends Wbase_enum_itm { public Wbase_claim_type(byte tid, String key_str, String key_for_scrib) {super(tid, key_str);
this.key_for_scrib = key_for_scrib;
}
public String Key_for_scrib() {return key_for_scrib;} private final String key_for_scrib;
}

View File

@@ -0,0 +1,58 @@
/*
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.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_type_ {
public static final byte // SERIALIZED:wbase_prop|datatype
Tid__unknown = 0
, Tid__value = 1
, Tid__bad = 1
, Tid__string = 2
, Tid__quantity = 3
, Tid__time = 4
, Tid__globecoordinate = 5
, Tid__monolingualtext = 6
, Tid__entity = 7
, Tid__property = 8
, Tid__math = 9
, Tid__url = 10
, Tid__externalid = 11
, Tid__commonsmedia = 12
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.data_type", 13);
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
, Itm__string = New(Tid__string , "string") // EX:wd:Property:P1030
, Itm__quantity = New(Tid__quantity , "quantity")
, Itm__time = New(Tid__time , "time")
, Itm__globecoordinate = New(Tid__globecoordinate , "globecoordinate" , "globe-coordinate")
, Itm__monolingualtext = New(Tid__monolingualtext , "monolingualtext")
, Itm__entity = New(Tid__entity , "wikibase-entityid" , "wikibase-item")
, Itm__property = New(Tid__property , "wikibase-property") // EX:wd:Property:P1646
, Itm__url = New(Tid__url , "url") // EX:wd:Property:P1019
, Itm__commonsmedia = New(Tid__commonsmedia , "commonsMedia") // EX:wd:Property:P14
, Itm__externalid = New(Tid__externalid , "external-id") // EX:wd:Property:P1003
, Itm__math = New(Tid__math , "math") // EX:wd:Property:P2534
;
private static Wbase_enum_itm New(byte tid, String key) {return New(tid, key, key);}
private static Wbase_enum_itm New(byte tid, String key, String scrib) {return Reg.Add(new Wbase_claim_type(tid, key, scrib));}
public static String Get_scrib_or_unknown(byte tid) {return ((Wbase_claim_type)Reg.Get_itm_or(tid, Itm__unknown)).Key_for_scrib();}
public static byte Get_tid_or_unknown(String key) {return Get_tid_or_unknown(Bry_.new_u8(key));}
public static byte Get_tid_or_unknown(byte[] key) {return Get_tid_or_unknown(key, 0, key.length);}
public static byte Get_tid_or_unknown(byte[] key, int bgn, int end) {return Reg.Get_tid_or(key, bgn, end, Tid__unknown);}
}

View File

@@ -0,0 +1,31 @@
/*
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.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_claim_value_type_ {
public static final byte // SERIALIZED.MW
Tid__novalue = 0
, Tid__value = 1
, Tid__somevalue = 2
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.value_type", 3);
public static final Wbase_enum_itm
Itm__novalue = Reg.Add(Tid__novalue , "novalue")
, Itm__value = Reg.Add(Tid__value , "value")
, Itm__somevalue = Reg.Add(Tid__somevalue , "somevalue")
;
}

View File

@@ -0,0 +1,58 @@
/*
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.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_enum_hash {
private final Wbase_enum_itm[] ary; private final int ary_len;
private final Hash_adp_bry hash_by_bry = Hash_adp_bry.cs();
public Wbase_enum_hash(String name, int ary_len) {
this.name = name;
this.ary = new Wbase_enum_itm[ary_len];
this.ary_len = ary_len;
}
public String Name() {return name;} private final String name;
public int Len() {return ary_len;}
public Wbase_enum_itm Add(byte tid, String key) {return Add(new Wbase_enum_itm(tid, key));}
public Wbase_enum_itm Add(Wbase_enum_itm rv) {
hash_by_bry.Add(rv.Key_bry(), rv);
ary[rv.Tid()] = rv;
return rv;
}
public Wbase_enum_itm Get_itm_or(byte tid, Wbase_enum_itm or) {return tid < ary_len ? ary[tid] : or;}
public String Get_str_or(byte tid, String or) {return tid < ary_len ? ary[tid].Key_str() : or;}
public String Get_str_or_fail(byte tid) {return ary[tid].Key_str();}
public byte[] Get_bry_or_fail(byte tid) {return ary[tid].Key_bry();}
public byte Get_tid_or_fail(byte[] key) {return ((Wbase_enum_itm)hash_by_bry.Get_by_or_fail(key)).Tid();}
public byte Get_tid_or_max_and_log(byte[] qid, String key) {return Get_tid_or_max_and_log(qid, Bry_.new_u8(key));}
public byte Get_tid_or_max_and_log(byte[] qid, byte[] key) {
Object rv_obj = hash_by_bry.Get_by(key);
if (rv_obj == null) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown enum key for wikibase; qid=~{0} enum=~{1} key=~{2}", qid, name, key);
return Byte_.Max_value_127;
}
return ((Wbase_enum_itm)rv_obj).Tid();
}
public byte Get_tid_or(String key, byte or) {return Get_tid_or(Bry_.new_u8(key), or);}
public byte Get_tid_or(byte[] key, byte or) {
Object obj = hash_by_bry.Get_by_bry(key);
return obj == null ? or : ((Wbase_enum_itm)obj).Tid();
}
public byte Get_tid_or(byte[] key, int bgn, int end, byte or) {
Object obj = hash_by_bry.Get_by_mid(key, bgn, end);
return obj == null ? or : ((Wbase_enum_itm)obj).Tid();
}
}

View File

@@ -0,0 +1,28 @@
/*
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.claims.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
public class Wbase_enum_itm {
public Wbase_enum_itm(byte tid, String key_str) {
this.tid = tid;
this.key_str = key_str;
this.key_bry = Bry_.new_u8(key_str);
}
public byte Tid() {return tid;} private final byte tid;
public String Key_str() {return key_str;} private final String key_str;
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
}

View File

@@ -0,0 +1,46 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public abstract class Wbase_claim_base implements CompareAble {
public Wbase_claim_base(int pid, byte snak_tid) {
this.pid = pid;
this.snak_tid = snak_tid;
}
public int Pid() {return pid;} private final int pid;
public byte Snak_tid() {return snak_tid;} private final byte snak_tid;
public byte Rank_tid() {return rank_tid;} private byte rank_tid = Wbase_claim_rank_.Tid__normal; // TEST: default to normal for tests
public String Prop_type() {return Prop_type_statement;} private static final String Prop_type_statement = "statement";
public byte[] Wguid() {return wguid;} private byte[] wguid;
public Wbase_claim_grp_list Qualifiers() {return qualifiers;} private Wbase_claim_grp_list qualifiers;
public int[] Qualifiers_order() {return qualifiers_order;} private int[] qualifiers_order;
public Wbase_references_grp[] References() {return references;} private Wbase_references_grp[] references;
public abstract byte Val_tid();
public abstract void Welcome(Wbase_claim_visitor visitor);
public void Rank_tid_(byte v) {this.rank_tid = v;}
public void Wguid_(byte[] v) {this.wguid = v;}
public Wbase_claim_base Qualifiers_(Wbase_claim_grp_list v) {qualifiers = v; return this;}
public void Qualifiers_order_(int[] v) {qualifiers_order = v;}
public void References_(Wbase_references_grp[] v) {references = v;}
public int compareTo(Object obj) {
Wbase_claim_base comp = (Wbase_claim_base)obj;
return Int_.Compare(pid, comp.pid);
}
}

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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_entity extends Wbase_claim_base {
public Wbase_claim_entity(int pid, byte snak_tid, byte entity_tid, byte[] entity_id_bry) {super(pid, snak_tid);
this.entity_tid = entity_tid;
this.entity_id_bry = entity_id_bry;
this.entity_id = Bry_.To_int(entity_id_bry);
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__entity;}
public int Entity_id() {return entity_id;} private final int entity_id;
public byte[] Entity_id_bry() {return entity_id_bry;} private final byte[] entity_id_bry;
public byte Entity_tid() {return entity_tid;} private final byte entity_tid;
public boolean Entity_tid_is_qid() {return entity_tid == Wbase_claim_entity_type_.Tid__item;}
public String Entity_tid_str() {return Wbase_claim_entity_type_.Reg.Get_str_or_fail(entity_tid);}
public byte[] Entity_tid_bry() {return Wbase_claim_entity_type_.Reg.Get_bry_or_fail(entity_tid);}
public byte[] Page_ttl_db() {return To_xid__db(entity_tid, entity_id_bry);}
public byte[] Page_ttl_gui() {
return entity_tid == Wbase_claim_entity_type_.Tid__item
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_gui, entity_id_bry)
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, entity_id_bry)
;
}
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_entity(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), this.Entity_tid_str(), Int_.To_str(entity_id));
}
public static byte[] To_xid__db(byte tid, byte[] bry) { // EX: 'item,2' -> q2; 'property,2' -> Property:P2
return tid == Wbase_claim_entity_type_.Tid__item
? Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_qid_bry_db, bry)
: Bry_.Add(Wdata_wiki_mgr.Ttl_prefix_pid_bry, bry)
;
}
}

View File

@@ -0,0 +1,32 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_entity_ {
public static final byte
Tid__entity_type = 0 // EX: "entity-type":"item"
, Tid__numeric_id = 1 // EX: "numeric-id":121410
, Tid__id = 2 // EX: "id":"Q121410"
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.val.entity", 3);
public static final Wbase_enum_itm
Itm__entity_type = Reg.Add(Tid__entity_type , "entity-type")
, Itm__numeric_id = Reg.Add(Tid__numeric_id , "numeric-id")
, Itm__id = Reg.Add(Tid__id , "id")
;
}

View File

@@ -0,0 +1,43 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_globecoordinate extends Wbase_claim_base {
public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {super(pid, snak_tid);
this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
public byte[] Lat() {return lat;} private final byte[] lat;
public byte[] Lng() {return lng;} private final byte[] lng;
public byte[] Alt() {return alt;} private final byte[] alt;
public byte[] Prc() {return prc;} private final byte[] prc;
public byte[] Glb() {return glb;} private final byte[] glb;
public byte[] Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
public void Glb_ttl_(byte[] v) {glb_ttl = v;}
public Decimal_adp Prc_as_num() {
if (prc_as_num == null)
prc_as_num = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
return prc_as_num;
} private Decimal_adp prc_as_num;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), String_.new_u8(lat), String_.new_u8(lng), String_.new_u8(alt), String_.new_u8(prc), String_.new_u8(glb));
}
}

View File

@@ -0,0 +1,43 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_globecoordinate_ {
public static final byte
Tid__latitude = 0
, Tid__longitude = 1
, Tid__altitude = 2
, Tid__precision = 3
, Tid__globe = 4
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.val.globecoordinate", 5);
public static final Wbase_enum_itm
Itm__latitude = Reg.Add(Tid__latitude , "latitude")
, Itm__longitude = Reg.Add(Tid__longitude , "longitude")
, Itm__altitude = Reg.Add(Tid__altitude , "altitude")
, Itm__precision = Reg.Add(Tid__precision , "precision")
, Itm__globe = Reg.Add(Tid__globe , "globe")
;
public static String
Val_globe_dflt_str = "http://www.wikidata.org/entity/Q2"
;
public static byte[]
Val_globe_dflt_bry = Bry_.new_a7(Val_globe_dflt_str)
;
}

View File

@@ -0,0 +1,32 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_monolingualtext extends Wbase_claim_base {
public Wbase_claim_monolingualtext(int pid, byte snak_tid, byte[] lang, byte[] text) {super(pid, snak_tid);
this.lang = lang; this.text = text;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__monolingualtext;}
public byte[] Lang() {return lang;} private final byte[] lang;
public byte[] Text() {return text;} private final byte[] text;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_monolingualtext(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), String_.new_u8(lang), String_.new_u8(text));
}
}

View File

@@ -0,0 +1,30 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_monolingualtext_ {
public static final byte
Tid__text = 0
, Tid__language = 1
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.val.monolingualtext", 2);
public static final Wbase_enum_itm
Itm__text = Reg.Add(Tid__text , "text")
, Itm__language = Reg.Add(Tid__language , "language")
;
}

View File

@@ -0,0 +1,72 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_quantity extends Wbase_claim_base {
public Wbase_claim_quantity(int pid, byte snak_tid, byte[] amount, byte[] unit, byte[] ubound, byte[] lbound) {super(pid, snak_tid);
this.amount = amount; this.unit = unit; this.ubound = ubound; this.lbound = lbound;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__quantity;}
public byte[] Amount() {return amount;} private final byte[] amount;
public byte[] Ubound() {return ubound;} private final byte[] ubound;
public byte[] Lbound() {return lbound;} private final byte[] lbound;
public byte[] Unit() {return unit;} private final byte[] unit;
public Decimal_adp Amount_as_num() {
if (amount_as_num == null) {
amount_as_num = To_decimal_or_null("amount", amount);
if (amount_as_num == null) {
amount_as_num = Decimal_adp_.Zero;
Gfo_usr_dlg_.Instance.Warn_many("", "", "wbase.claim: value is null; name=~{0}", "amount");
}
}
return amount_as_num;
} private Decimal_adp amount_as_num;
public Decimal_adp Ubound_as_num() {
if (ubound_as_num == null) {
ubound_as_num = To_decimal_or_null("upper", ubound);
if (ubound_as_num == null) {
ubound_as_num = amount_as_num;
}
}
return ubound_as_num;
} private Decimal_adp ubound_as_num;
public Decimal_adp Lbound_as_num() {
if (lbound_as_num == null) {
lbound_as_num = To_decimal_or_null("lower", lbound);
if (lbound_as_num == null) {
lbound_as_num = amount_as_num;
}
}
return lbound_as_num;
} private Decimal_adp lbound_as_num;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_quantity(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), String_.new_u8(amount), String_.new_u8(unit), String_.new_u8(ubound), String_.new_u8(lbound));
}
public static final byte[] Unit_1 = Bry_.new_a7("1");
private static Decimal_adp To_decimal_or_null(String name, byte[] bry) {
if (bry == null) return null;
int len = bry.length;
if (len == 0) return null;
if (bry[0] == Byte_ascii.Plus) bry = Bry_.Mid(bry, 1);
return Decimal_adp_.parse(String_.new_a7(bry));
}
}

View File

@@ -0,0 +1,34 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_quantity_ {
public static final byte
Tid__amount = 0
, Tid__unit = 1
, Tid__upperbound = 2
, Tid__lowerbound = 3
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.val.quantity", 4);
public static final Wbase_enum_itm
Itm__amount = Reg.Add(Tid__amount , "amount")
, Itm__unit = Reg.Add(Tid__unit , "unit")
, Itm__upperbound = Reg.Add(Tid__upperbound , "upperBound")
, Itm__lowerbound = Reg.Add(Tid__lowerbound , "lowerBound")
;
}

View File

@@ -0,0 +1,31 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_string extends Wbase_claim_base {
public Wbase_claim_string(int pid, byte snak_tid, byte[] val_bry) {super(pid, snak_tid);
this.val_bry = val_bry;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__string;}
public byte[] Val_bry() {return val_bry;} private final byte[] val_bry;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_str(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), String_.new_u8(val_bry));
}
}

View File

@@ -0,0 +1,92 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.hwtrs.*;
public class Wbase_claim_time extends Wbase_claim_base {
public Wbase_claim_time(int pid, byte snak_tid, byte[] time, byte[] timezone, byte[] before, byte[] after, byte[] precision, byte[] calendar) {super(pid, snak_tid);
this.time = time; this.before = before; this.after = after; this.precision = precision; this.calendar = calendar;
}
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__time;}
public byte[] Time() {return time;} private final byte[] time;
public byte[] Before() {return before;} private final byte[] before;
public byte[] After() {return after;} private final byte[] after;
public byte[] Precision() {return precision;} private final byte[] precision;
public byte[] Calendar() {return calendar;} private final byte[] calendar;
public byte[] Calendar_ttl() {return calendar_ttl;} private byte[] calendar_ttl;
public boolean Calendar_is_julian() {return Bry_.Eq(calendar, Calendar_julian);}
public void Calendar_ttl_(byte[] v) {calendar_ttl = v;}
public Wbase_date Time_as_date() {
if (time_as_date == null) time_as_date = Wbase_date_.Parse(time, this.Precision_int(), this.Before_int(), this.After_int(), this.Calendar_is_julian());
return time_as_date;
} private Wbase_date time_as_date;
public int Precision_int() {
if (precision_int == Int_.Min_value) {
precision_int = Bry_.To_int_or(precision, -1);
if (precision_int == -1) {
precision_int = Wbase_date.Fmt_ymdhns;
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown precision: ~{0}", String_.new_u8(precision));
}
}
return precision_int;
} private int precision_int = Int_.Min_value;
public int Before_int() {
if (before_int == Int_.Min_value) {
before_int = Bry_.To_int_or(before, -1);
if (before_int == -1) {
before_int = 0;
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown before: ~{0}", String_.new_u8(before));
}
}
return before_int;
} private int before_int = Int_.Min_value;
public int After_int() {
if (after_int == Int_.Min_value) {
after_int = Bry_.To_int_or(after, -1);
if (after_int == -1) {
after_int = 0;
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown after: ~{0}", String_.new_u8(after));
}
}
return after_int;
} private int after_int = Int_.Min_value;
public void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs, byte[] ttl) {
try {
Wbase_date date = this.Time_as_date();
Wbase_date_.To_bfr(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, this.Pid(), Err_.Message_gplx_log(e));
}
}
public static void Write_to_bfr(Bry_bfr bfr, Bry_bfr tmp_time_bfr, Bry_fmtr tmp_time_fmtr, Wdata_hwtr_msgs msgs
, byte[] ttl, byte[] pid, Wbase_date date, boolean calendar_is_julian) {
try {
Wbase_date_.To_bfr(bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
} catch (Exception e) {
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to write time; ttl=~{0} pid=~{1} err=~{2}", ttl, pid, Err_.Message_gplx_log(e));
}
}
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_time(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()), String_.new_u8(time), String_.new_u8(before), String_.new_u8(after), String_.new_u8(precision), String_.new_u8(calendar));
}
public static final byte[] Calendar_julian = Bry_.new_a7("http://www.wikidata.org/entity/Q1985786");
}

View File

@@ -0,0 +1,66 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.times.*;
public class Wbase_claim_time_ {
public static final byte
Tid__time = 0
, Tid__timezone = 1
, Tid__before = 2
, Tid__after = 3
, Tid__precision = 4
, Tid__calendarmodel = 5
;
public static final Wbase_enum_hash Reg = new Wbase_enum_hash("claim.val.time", 6);
public static final Wbase_enum_itm
Itm__time = Reg.Add(Tid__time , "time")
, Itm__timezone = Reg.Add(Tid__timezone , "timezone")
, Itm__before = Reg.Add(Tid__before , "before")
, Itm__after = Reg.Add(Tid__after , "after")
, Itm__precision = Reg.Add(Tid__precision , "precision")
, Itm__calendarmodel = Reg.Add(Tid__calendarmodel , "calendarmodel")
;
public static final Wbase_data_itm
Dflt__precision = Wbase_data_itm.New_int(11)
, Dflt__before = Wbase_data_itm.New_int(0)
, Dflt__after = Wbase_data_itm.New_int(0)
, Dflt__timezone = Wbase_data_itm.New_int(0)
, Dflt__calendarmodel = Wbase_data_itm.New_str("http://www.wikidata.org/entity/Q1985727")
;
private static final byte[] Bry_year_prefix = Bry_.new_a7("+0000000");
public static byte[] To_bry(Bry_bfr bfr, String date) {return To_bry(bfr, DateAdp_.parse_fmt(date, "yyyy-MM-dd HH:mm:ss"));}
public static byte[] To_bry(Bry_bfr bfr, DateAdp date) {// +0000000yyyy-MM-ddTHH:mm:ssZ
bfr
.Add(Bry_year_prefix)
.Add_int_fixed(date.Year(), 4)
.Add_byte(Byte_ascii.Dash)
.Add_int_fixed(date.Month(), 2)
.Add_byte(Byte_ascii.Dash)
.Add_int_fixed(date.Day(), 2)
.Add_byte(Byte_ascii.Ltr_T)
.Add_int_fixed(date.Hour(), 2)
.Add_byte(Byte_ascii.Colon)
.Add_int_fixed(date.Minute(), 2)
.Add_byte(Byte_ascii.Colon)
.Add_int_fixed(date.Second(), 2)
.Add_byte(Byte_ascii.Ltr_Z)
;
return bfr.To_bry_and_clear();
}
}

View File

@@ -0,0 +1,33 @@
/*
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.claims.itms; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
public class Wbase_claim_value extends Wbase_claim_base {
public Wbase_claim_value(int pid, byte val_tid, byte snak_tid) {super(pid, snak_tid);
this.val_tid = val_tid;
}
@Override public byte Val_tid() {return val_tid;} private final byte val_tid;
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_system(this);}
@Override public String toString() {// TEST:
return String_.Concat_with_str("|", Wbase_claim_value_type_.Reg.Get_str_or_fail(this.Snak_tid()), Wbase_claim_type_.Reg.Get_str_or_fail(this.Val_tid()));
}
public static Wbase_claim_value New_novalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__novalue);}
public static Wbase_claim_value New_somevalue(int pid) {return new Wbase_claim_value(pid, Wbase_claim_type_.Tid__unknown , Wbase_claim_value_type_.Tid__somevalue);}
}

View File

@@ -0,0 +1,31 @@
/*
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.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wbase_data_itm {
public Wbase_data_itm(int val_int, String val_str, byte[] val_bry) {
this.val_int = val_int;
this.val_str = val_str;
this.val_bry = val_bry;
}
public int Val_int() {return val_int;} private final int val_int;
public String Val_str() {return val_str;} private final String val_str;
public byte[] Val_bry() {return val_bry;} private final byte[] val_bry;
public static Wbase_data_itm New_int(int val) {return new Wbase_data_itm(val, Int_.To_str(val), Int_.To_bry(val));}
public static Wbase_data_itm New_str(String val) {return new Wbase_data_itm( -1, val, Bry_.new_u8(val));}
}

View File

@@ -0,0 +1,42 @@
/*
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.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Wbase_date {
public Wbase_date(long year, int month, int day, int hour, int minute, int second, int precision, int before, int after, boolean calendar_is_julian) {
this.year = year; this.month = month; this.day = day; this.hour = hour; this.minute = minute; this.second = second;
this.precision = precision; this.before = before; this.after = after; this.calendar_is_julian = calendar_is_julian;
}
public long Year() {return year;} private final long year;
public int Month() {return month;} private final int month;
public int Day() {return day;} private final int day;
public int Hour() {return hour;} private final int hour;
public int Minute() {return minute;} private final int minute;
public int Second() {return second;} private final int second;
public int Precision() {return precision;} private final int precision;
public int Before() {return before;} private final int before;
public int After() {return after;} private final int after;
public boolean Calendar_is_julian() {return calendar_is_julian;} private final boolean calendar_is_julian;
public static final int
Fmt_y = 9
, Fmt_ym = 10
, Fmt_ymd = 11
, Fmt_ymdh = 12
, Fmt_ymdhn = 13
, Fmt_ymdhns = 14 // anything >13 ?
;
}

View File

@@ -0,0 +1,168 @@
/*
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.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.xtns.wbases.hwtrs.*;
public class Wbase_date_ {
public static Wbase_date Parse(byte[] date, int precision, int before, int after, boolean calendar_is_julian) {// EX:+00000002001-02-03T04:05:06Z
int year_sign = 1;
switch (date[0]) {
case Byte_ascii.Plus: break;
case Byte_ascii.Dash: year_sign = -1; break;
default: throw Err_.new_unhandled(date[0]);
}
int year_end = Bry_find_.Find_fwd(date, Byte_ascii.Dash, 1);
long year = Long_.parse_or(String_.new_a7(date, 1, year_end), -1); if (year == -1) throw Err_.new_wo_type("parse failed", "raw", String_.new_a7(date));
int month = Bry_.To_int_or(date, year_end + 1, year_end + 3, -1);
int day = Bry_.To_int_or(date, year_end + 4, year_end + 6, -1);
int hour = Bry_.To_int_or(date, year_end + 7, year_end + 9, -1);
int minute = Bry_.To_int_or(date, year_end + 10, year_end + 12, -1);
int second = Bry_.To_int_or(date, year_end + 13, year_end + 15, -1);
return new Wbase_date(year * year_sign, month, day, hour, minute, second, precision, before, after, calendar_is_julian);
}
public static Wbase_date To_julian(Wbase_date date) {
long a = (long)Math_.Floor((14 - date.Month() / 12));
long y = date.Year() + 4800 - a;
long m = date.Month() + 12 * a - 3;
long julian = date.Day() + (long)Math_.Floor((153 * m + 2) / 5) + 365 * y + (long)Math_.Floor(y / 4) - (long)Math_.Floor(y / 100) + (long)Math_.Floor(y / 400) - 32045;
long c = julian + 32082;
long d = (long)Math_.Floor((4 * c + 3) / 1461);
long e = c - (long)Math_.Floor((1461 * d) / 4);
long n = (long)Math_.Floor((5 * e + 2) / 153);
long new_y = d - 4800 + (long)Math_.Floor(n / 10);
int new_m = (int)(n + 3 - 12 * (long)Math_.Floor(n / 10));
int new_d = (int)(e - (long)Math_.Floor((153 * n + 2) / 5) + 1);
return new Wbase_date(new_y, new_m, new_d, date.Hour(), date.Minute(), date.Second(), date.Precision(), date.Before(), date.After(), date.Calendar_is_julian());
}
public static void To_bfr(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
// TOMBSTONE: use "actual" date; do not do conversion to julian; DATE:2016-11-10
// boolean calendar_is_julian = date.Calendar_is_julian();
// if (calendar_is_julian) date = To_julian(date);
long year = date.Year();
int months_bgn = msgs.Month_bgn_idx();
byte[][] months = msgs.Ary();
int precision = date.Precision();
byte[] time_spr = msgs.Sym_time_spr();
switch (precision) {
case Wbase_date.Fmt_ym: // EX: "Feb 2001"
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(year);
break;
case Wbase_date.Fmt_ymd: // EX: "3 Feb 2001"
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
break;
case Wbase_date.Fmt_ymdh: // EX: "4:00 3 Feb 2011"
bfr.Add_int_variable(date.Hour());
bfr.Add(time_spr);
bfr.Add_int_fixed(0, 2);
bfr.Add_byte_space();
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
break;
case Wbase_date.Fmt_ymdhn: // EX: "4:05 3 Feb 2011"
bfr.Add_int_variable(date.Hour());
bfr.Add(time_spr);
bfr.Add_int_fixed(date.Minute(), 2);
bfr.Add_byte_space();
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
break;
default:
if (precision <= 9) // y, round to (9 - prec)
Xto_str_fmt_y(bfr, tmp_fmtr, tmp_bfr, msgs, date, precision);
else { // EX: "4:05:06 3 Feb 2011"
bfr.Add_int_variable(date.Hour());
bfr.Add(time_spr);
bfr.Add_int_fixed(date.Minute(), 2);
bfr.Add(time_spr);
bfr.Add_int_fixed(date.Second(), 2);
bfr.Add_byte_space();
bfr.Add_int_variable(date.Day());
bfr.Add_byte_space();
bfr.Add(months[months_bgn + date.Month() - List_adp_.Base1]);
bfr.Add_byte_space();
bfr.Add_long_variable(date.Year());
}
break;
}
// TOMBSTONE: use "actual" date; do not do conversion to julian; DATE:2016-11-10
// if (calendar_is_julian)
// bfr.Add(msgs.Time_julian());
Xto_str_beforeafter(bfr, tmp_fmtr, tmp_bfr, msgs, date);
}
private static void Xto_str_beforeafter(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date) {
byte[] bry = null;
int before = date.Before();
int after = date.After();
if (before == 0) {
if (after != 0)
bry = tmp_bfr.Add(msgs.Sym_plus()).Add_int_variable(after).To_bry_and_clear();
}
else {
if (after == 0)
bry = tmp_bfr.Add(msgs.Sym_minus()).Add_int_variable(before).To_bry_and_clear();
else if (before == after)
bry = tmp_bfr.Add(msgs.Sym_plusminus()).Add_int_variable(before).To_bry_and_clear();
else
bry = tmp_bfr.Add(msgs.Sym_minus()).Add_int_variable(before).Add(msgs.Sym_list_comma()).Add(msgs.Sym_plus()).Add_int_variable(after).To_bry_and_clear();
}
if (bry != null) {
bry = tmp_fmtr.Fmt_(msgs.Sym_fmt_parentheses()).Bld_bry_many(tmp_bfr, bry);
bfr.Add_byte_space().Add(bry);
}
}
private static void Xto_str_fmt_y(Bry_bfr bfr, Bry_fmtr tmp_fmtr, Bry_bfr tmp_bfr, Wdata_hwtr_msgs msgs, Wbase_date date, int precision) {
int year_pow = 9 - precision;
byte[] year_fmt = msgs.Ary()[msgs.Time_year_idx() + year_pow];
long year = date.Year();
byte[] repl_fmt = null;
if (year <= 0) { // negative
if (year_pow < 4) // negative years < 999 get "BC"
repl_fmt = msgs.Time_relative_bc();
else // negative years > 999 get "ago"
repl_fmt = msgs.Time_relative_ago();
}
else {
if (year_pow > 4) // positive years > 999 get "in time"
repl_fmt = msgs.Time_relative_in();
}
if (repl_fmt != null)
year_fmt = tmp_fmtr.Fmt_(repl_fmt).Bld_bry_many(tmp_bfr, year_fmt);
if (year <= 0)
year *= -1; // convert negative to positive; note that negative year will be reported with "BC" / "ago"
switch (year_pow) {
case 0: break; // noop
default:
year = (int)(year / Math_.Pow(10, year_pow));
break;
}
byte[] year_bry = tmp_fmtr.Fmt_(year_fmt).Bld_bry_many(tmp_bfr, year);
bfr.Add(year_bry);
}
}

View File

@@ -0,0 +1,92 @@
/*
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.claims.itms.times; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
import org.junit.*; import gplx.core.brys.fmtrs.*;
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.hwtrs.*;
public class Wbase_date_tst {
@Before public void init() {fxt.Clear();} private Wbase_date_fxt fxt = new Wbase_date_fxt();
@Test public void Parse() {
fxt.Test_parse("+00000002001-02-03T04:05:06Z", 2001, 2, 3, 4, 5, 6);
fxt.Test_parse("-98765432109-02-03T04:05:06Z", -98765432109L, 2, 3, 4, 5, 6);
}
@Test public void Julian() {
fxt.Test_julian(Int_.Ary(1600, 1, 2), Int_.Ary(1600, 1, 18));
}
@Test public void Xto_str() {
String date = "+00000002001-02-03T04:05:06Z";
fxt.Test_xto_str(date, Wbase_date.Fmt_ym , "Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymd , "3 Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdh , "4:00 3 Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhn , "4:05 3 Feb 2001");
fxt.Test_xto_str(date, Wbase_date.Fmt_ymdhns , "4:05:06 3 Feb 2001");
}
@Test public void Xto_str_year() {
fxt.Test_xto_str("+00000001970-01-01T00:00:00Z", 9, "1970");
fxt.Test_xto_str("-00000001234-01-01T00:00:00Z", 9, "1234 BC");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 8, "1980s");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 7, "19. century");
fxt.Test_xto_str("+00000001987-01-01T00:00:00Z", 6, "1. millenium");
fxt.Test_xto_str("+00000012345-01-01T00:00:00Z", 5, "10,000 years");
fxt.Test_xto_str("+00000123456-01-01T00:00:00Z", 4, "in 100,000 years");
}
@Test public void Xto_str_julian() {
fxt.Init_calendar_is_julian_(Bool_.Y).Test_xto_str("+00000001600-01-02T00:00:00Z", Wbase_date.Fmt_ymd, "2 Jan 1600");
}
@Test public void Xto_str_before_after() {
String date = "+00000002001-02-03T04:05:06Z";
fxt.Clear().Init_before_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1)");
fxt.Clear().Init_after_ (1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (+1)");
fxt.Clear().Init_before_(1).Init_after_(1).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (±1)");
fxt.Clear().Init_before_(1).Init_after_(2).Test_xto_str(date, Wbase_date.Fmt_ymd, "3 Feb 2001 (-1,&#32;+2)");
}
}
class Wbase_date_fxt {
private Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(16);
private Wdata_hwtr_msgs msgs;
private final Bry_fmtr tmp_time_fmtr = Bry_fmtr.new_(); private final Bry_bfr tmp_time_bfr = Bry_bfr_.New_w_size(32);
public Wbase_date_fxt Clear() {
init_before = init_after = 0;
init_calendar_is_julian = false;
return this;
}
public boolean Init_calendar_is_julian() {return init_calendar_is_julian;} public Wbase_date_fxt Init_calendar_is_julian_(boolean v) {init_calendar_is_julian = v; return this;} private boolean init_calendar_is_julian;
public int Init_before() {return init_before;} public Wbase_date_fxt Init_before_(int v) {init_before = v; return this;} private int init_before;
public int Init_after() {return init_after;} public Wbase_date_fxt Init_after_(int v) {init_after = v; return this;} private int init_after;
public void Test_parse(String raw, long expd_y, int expd_m, int expd_d, int expd_h, int expd_n, int expd_s) {
Wbase_date actl_date = Wbase_date_.Parse(Bry_.new_a7(raw), Wbase_date.Fmt_ymdhns, init_before, init_after, init_calendar_is_julian);
Tfds.Eq(expd_y, actl_date.Year());
Tfds.Eq(expd_m, actl_date.Month());
Tfds.Eq(expd_d, actl_date.Day());
Tfds.Eq(expd_h, actl_date.Hour());
Tfds.Eq(expd_n, actl_date.Minute());
Tfds.Eq(expd_s, actl_date.Second());
}
public void Test_julian(int[] orig_ary, int[] expd) {
Wbase_date orig = new Wbase_date(orig_ary[0], orig_ary[1], orig_ary[2], 0, 0, 0, 0, 0, 0, init_calendar_is_julian);
Wbase_date actl = Wbase_date_.To_julian(orig);
Tfds.Eq(expd[0], (int)actl.Year(), "y");
Tfds.Eq(expd[1], actl.Month(), "m");
Tfds.Eq(expd[2], actl.Day(), "d");
}
public void Test_xto_str(String raw, int precision, String expd) {
if (msgs == null) msgs = Wdata_hwtr_msgs.new_en_();
Wbase_date date = Wbase_date_.Parse(Bry_.new_a7(raw), precision, init_before, init_after, init_calendar_is_julian);
Wbase_date_.To_bfr(tmp_bfr, tmp_time_fmtr, tmp_time_bfr, msgs, date);
Tfds.Eq(expd, tmp_bfr.To_str_and_clear());
}
}