mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-06-13 12:54:14 +00:00
Wikibase: Default 'null' to 0, not 1 [#792]
This commit is contained in:
parent
f19228c886
commit
72051f4ce9
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
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.scribunto.libs;
|
||||||
|
|
||||||
|
import gplx.Bry_;
|
||||||
|
import gplx.Double_;
|
||||||
|
import gplx.Keyval;
|
||||||
|
import gplx.core.tests.Gftest;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
|
||||||
|
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_globecoordinate;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class Scrib_lib_wikibase_srl_visitor_tst {
|
||||||
|
private final Scrib_lib_wikibase_srl_visitor_fxt fxt = new Scrib_lib_wikibase_srl_visitor_fxt();
|
||||||
|
@Test
|
||||||
|
public void Geo_null_precision() {
|
||||||
|
fxt.TestGeoPrecision(0, "null"); // 2020-09-03|ISSUE#:792|null precision should default to 0 not 1;PAGE:wd:Q168751
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Scrib_lib_wikibase_srl_visitor_fxt {
|
||||||
|
private final Scrib_lib_wikibase_srl_visitor visitor = new Scrib_lib_wikibase_srl_visitor();
|
||||||
|
public void TestGeoPrecision(double expd, String prc) {
|
||||||
|
String lat = "12";
|
||||||
|
String lng = "34";
|
||||||
|
visitor.Visit_globecoordinate(new Wbase_claim_globecoordinate(123, Wbase_claim_value_type_.Tid__value, Bry_.new_a7(lat), Bry_.new_a7(lng), null, Bry_.new_u8_safe(prc), null));
|
||||||
|
Keyval[] actl = visitor.Rv();
|
||||||
|
Keyval[] actlGeo = (Keyval[])actl[1].Val();
|
||||||
|
Gftest.Eq__double(expd, Double_.cast(actlGeo[4].Val()));
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
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.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,29 +13,42 @@ 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
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
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.*;
|
package gplx.xowa.xtns.wbases.claims.itms;
|
||||||
import gplx.xowa.xtns.wbases.claims.enums.*;
|
|
||||||
public class Wbase_claim_globecoordinate extends Wbase_claim_base {
|
import gplx.Bry_;
|
||||||
public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {super(pid, snak_tid);
|
import gplx.Decimal_adp;
|
||||||
this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
|
import gplx.Decimal_adp_;
|
||||||
}
|
import gplx.Object_;
|
||||||
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
|
import gplx.String_;
|
||||||
public byte[] Lat() {return lat;} private final byte[] lat;
|
import gplx.xowa.xtns.wbases.claims.Wbase_claim_visitor;
|
||||||
public byte[] Lng() {return lng;} private final byte[] lng;
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_type_;
|
||||||
public byte[] Alt() {return alt;} private final byte[] alt;
|
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
|
||||||
public byte[] Prc() {return prc;} private final byte[] prc;
|
|
||||||
public byte[] Glb() {return glb;} private final byte[] glb;
|
public class Wbase_claim_globecoordinate extends Wbase_claim_base {
|
||||||
public byte[] Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
|
public Wbase_claim_globecoordinate(int pid, byte snak_tid, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {
|
||||||
|
super(pid, snak_tid);
|
||||||
public void Glb_ttl_(byte[] v) {glb_ttl = v;}
|
this.lat = lat; this.lng = lng; this.alt = alt; this.prc = prc; this.glb = glb;
|
||||||
public Decimal_adp Prc_as_num() {
|
}
|
||||||
if (prc_as_num == null)
|
@Override public byte Val_tid() {return Wbase_claim_type_.Tid__globecoordinate;}
|
||||||
prc_as_num = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
|
public byte[] Lat() {return lat;} private final byte[] lat;
|
||||||
return prc_as_num;
|
public byte[] Lng() {return lng;} private final byte[] lng;
|
||||||
} private Decimal_adp prc_as_num;
|
public byte[] Alt() {return alt;} private final byte[] alt;
|
||||||
|
public byte[] Prc() {return prc;} private final byte[] prc;
|
||||||
@Override public void Welcome(Wbase_claim_visitor visitor) {visitor.Visit_globecoordinate(this);}
|
public byte[] Glb() {return glb;} private final byte[] glb;
|
||||||
@Override public String toString() {// TEST:
|
public byte[] Glb_ttl() {return glb_ttl;} private byte[] glb_ttl;
|
||||||
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));
|
|
||||||
}
|
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_.Zero // 2020-09-03|ISSUE#:792|null precision should default to 0 not 1;PAGE:wd:Q168751
|
||||||
|
: 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
XOWA: the XOWA Offline Wiki Application
|
XOWA: the XOWA Offline Wiki Application
|
||||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||||
|
|
||||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
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.
|
or alternatively under the terms of the Apache License Version 2.0.
|
||||||
@ -13,89 +13,93 @@ 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
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||||
*/
|
*/
|
||||||
package gplx.xowa.xtns.wbases.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*;
|
package gplx.xowa.xtns.wbases.hwtrs;
|
||||||
import org.junit.*;
|
|
||||||
import gplx.langs.jsons.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.itms.times.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.apps.apis.xowa.html.*;
|
import gplx.Bry_;
|
||||||
public class Wdata_visitor__html_wtr_tst {
|
import gplx.xowa.xtns.wbases.claims.itms.times.Wbase_date;
|
||||||
@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
|
import org.junit.Before;
|
||||||
@Test public void Monolingualtext() {
|
import org.junit.Test;
|
||||||
fxt
|
|
||||||
.Test_claim_val
|
public class Wdata_visitor__html_wtr_tst {
|
||||||
( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto")
|
@Before public void init() {fxt.init();} private Wdata_hwtr_mgr_fxt fxt = new Wdata_hwtr_mgr_fxt();
|
||||||
, "Motto [en]"
|
@Test public void Monolingualtext() {
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Time() {
|
( fxt.Wdata_fxt().Make_claim_monolingual(1, "en", "Motto")
|
||||||
fxt
|
, "Motto [en]"
|
||||||
.Test_claim_val
|
);
|
||||||
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Wbase_date.Fmt_ymdhns)
|
}
|
||||||
, "4:05:06 3 Feb 2001"
|
@Test public void Time() {
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Time__julian() {
|
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Wbase_date.Fmt_ymdhns)
|
||||||
fxt
|
, "4:05:06 3 Feb 2001"
|
||||||
.Test_claim_val
|
);
|
||||||
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Bry_.Empty, Bry_.new_a7("http://www.wikidata.org/entity/Q1985786"))
|
}
|
||||||
, "4:05:06 3 Feb 2001"
|
@Test public void Time__julian() {
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Quantity_ubound_lbound() {
|
( fxt.Wdata_fxt().Make_claim_time(1, "2001-02-03 04:05:06", Bry_.Empty, Bry_.new_a7("http://www.wikidata.org/entity/Q1985786"))
|
||||||
fxt
|
, "4:05:06 3 Feb 2001"
|
||||||
.Test_claim_val
|
);
|
||||||
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "", "60", "30")
|
}
|
||||||
, "30-60"
|
@Test public void Quantity_ubound_lbound() {
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Quantity_same() {
|
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "", "60", "30")
|
||||||
fxt
|
, "30-60"
|
||||||
.Test_claim_val
|
);
|
||||||
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "1", "60", "40")
|
}
|
||||||
, "50±10"
|
@Test public void Quantity_same() {
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Quantity_frac() {
|
( fxt.Wdata_fxt().Make_claim_quantity(1, "50", "1", "60", "40")
|
||||||
fxt
|
, "50±10"
|
||||||
.Test_claim_val
|
);
|
||||||
( fxt.Wdata_fxt().Make_claim_quantity(1, "+0.1234", "1", "+0.1235", "+0.1233")
|
}
|
||||||
, "0.1234±0.0001"
|
@Test public void Quantity_frac() {
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Entity_qid() {
|
( fxt.Wdata_fxt().Make_claim_quantity(1, "+0.1234", "1", "+0.1235", "+0.1233")
|
||||||
fxt
|
, "0.1234±0.0001"
|
||||||
.Init_resolved_qid(1, "item_1")
|
);
|
||||||
.Test_claim_val
|
}
|
||||||
( fxt.Wdata_fxt().Make_claim_entity_qid(1, 1)
|
@Test public void Entity_qid() {
|
||||||
, "<a href='/wiki/Q1'>item_1</a>"
|
fxt
|
||||||
);
|
.Init_resolved_qid(1, "item_1")
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Entity_pid() {
|
( fxt.Wdata_fxt().Make_claim_entity_qid(1, 1)
|
||||||
fxt
|
, "<a href='/wiki/Q1'>item_1</a>"
|
||||||
.Init_resolved_pid(1, "item_1")
|
);
|
||||||
.Test_claim_val
|
}
|
||||||
( fxt.Wdata_fxt().Make_claim_entity_pid(1, 1)
|
@Test public void Entity_pid() {
|
||||||
, "<a href='/wiki/Property:P1'>item_1</a>"
|
fxt
|
||||||
);
|
.Init_resolved_pid(1, "item_1")
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Globecoordinate() {
|
( fxt.Wdata_fxt().Make_claim_entity_pid(1, 1)
|
||||||
fxt
|
, "<a href='/wiki/Property:P1'>item_1</a>"
|
||||||
.Init_resolved_qid(2, "Earth")
|
);
|
||||||
.Test_claim_val
|
}
|
||||||
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
|
@Test public void Globecoordinate() {
|
||||||
, "0°7'39"S, 51°30'26"E (<a href='/wiki/Q2'>Earth</a>)"
|
fxt
|
||||||
);
|
.Init_resolved_qid(2, "Earth")
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Globecoordinate__globe__null() {
|
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
|
||||||
fxt
|
, "0°7'39"S, 51°30'26"E (<a href='/wiki/Q2'>Earth</a>)"
|
||||||
.Test_claim_val
|
);
|
||||||
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
|
}
|
||||||
, "0°7'39"S, 51°30'26"E"
|
@Test public void Globecoordinate__globe__null() {
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
@Test public void Globecoordinate__precision__0() { // PURPOSE: 0 precision was causing divide by 0 error; PAGE:ru.w:Лысково_(Калужская_область) DATE:2016-11-24
|
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
|
||||||
fxt
|
, "0°7'39"S, 51°30'26"E"
|
||||||
.Test_claim_val
|
);
|
||||||
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", "0", "null", "")
|
}
|
||||||
, "0°6'S, 51°30'E"
|
@Test public void Globecoordinate__precision__0() { // PURPOSE: 0 precision was causing divide by 0 error; PAGE:ru.w:Лысково_(Калужская_область) DATE:2016-11-24
|
||||||
);
|
fxt
|
||||||
}
|
.Test_claim_val
|
||||||
}
|
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", "0", "null", "")
|
||||||
|
, "0°6'S, 51°30'E"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user