Parser: Only print value without ± if lo and hi are null [#839]

master
gnosygnu 3 years ago
parent 659bca3660
commit 17a3b4e7b3

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.
@ -79,8 +79,8 @@ public class Scrib_lib_wikibase_srl_visitor implements Wbase_claim_visitor {
Keyval[] rv = new Keyval[4];
rv[0] = Keyval_.new_(Wbase_claim_quantity_.Itm__amount.Key_str() , itm.Amount_as_num().To_str()); // NOTE: must be num b/c Module code will directly do math calc on it; EX: "99" not "+99"; PAGE:eo.w:Mud<75>; DATE:2015-11-08
rv[1] = Keyval_.new_(Wbase_claim_quantity_.Itm__unit.Key_str() , String_.new_u8(itm.Unit()));
rv[2] = Keyval_.new_(Wbase_claim_quantity_.Itm__upperbound.Key_str() , itm.Ubound_as_num().To_str());
rv[3] = Keyval_.new_(Wbase_claim_quantity_.Itm__lowerbound.Key_str() , itm.Lbound_as_num().To_str());
rv[2] = Keyval_.new_(Wbase_claim_quantity_.Itm__upperbound.Key_str() , itm.Ubound_as_num() == null ? null : itm.Ubound_as_num().To_str());
rv[3] = Keyval_.new_(Wbase_claim_quantity_.Itm__lowerbound.Key_str() , itm.Lbound_as_num() == null ? null : itm.Lbound_as_num().To_str());
return rv;
}
public void Visit_time(Wbase_claim_time itm) {

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.
@ -13,9 +13,28 @@ 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.wikibases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*;
import org.junit.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*;
import gplx.xowa.xtns.wbases.claims.enums.*;
package gplx.xowa.xtns.scribunto.libs.wikibases;
import gplx.Bool_;
import gplx.Bry_;
import gplx.Keyval;
import gplx.Keyval_;
import gplx.List_adp_;
import gplx.Object_;
import gplx.String_;
import gplx.xowa.xtns.scribunto.Scrib_core;
import gplx.xowa.xtns.scribunto.Scrib_invoke_func_fxt;
import gplx.xowa.xtns.scribunto.Scrib_lib;
import gplx.xowa.xtns.scribunto.libs.Scrib_lib_wikibase;
import gplx.xowa.xtns.scribunto.libs.Scrib_lib_wikibase_srl;
import gplx.xowa.xtns.wbases.Wdata_doc;
import gplx.xowa.xtns.wbases.Wdata_wiki_mgr_fxt;
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_base;
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_string;
import org.junit.Before;
import org.junit.Test;
public class Basic__tst {
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt(); private Scrib_lib lib;
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.
@ -116,8 +116,9 @@ public class Wdata_prop_val_visitor implements Wbase_claim_visitor { // THREAD.U
Decimal_adp lo = Decimal__parse_or(lo_bry, val);
Decimal_adp hi = Decimal__parse_or(hi_bry, val);
// fmt val
if (lo.Eq(hi) && hi.Eq(val))// lo, hi, val are same; print val only;
// 2021-02-14|ISSUE#:839|Only print value without ± if lo and hi are null; PAGE:en.w:2019_FIVB_Volleyball_Women%27s_Challenger_Cup#Pool_A;
// TOMBSTONE: if (lo.Eq(hi) && hi.Eq(val))
if (lo_bry == null && hi_bry == null)
bfr.Add(lang.Num_mgr().Format_num_by_decimal(val)); // amount; EX: 1,234
else {
Wdata_hwtr_msgs msgs = wdata_mgr.Hwtr_mgr().Msgs();

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.
@ -13,8 +13,18 @@ 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.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.*;
package gplx.xowa.xtns.wbases.claims.itms;
import gplx.Bry_;
import gplx.Byte_ascii;
import gplx.Decimal_adp;
import gplx.Decimal_adp_;
import gplx.Gfo_usr_dlg_;
import gplx.String_;
import gplx.xowa.xtns.wbases.claims.Wbase_claim_visitor;
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_type_;
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_value_type_;
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;
@ -38,18 +48,12 @@ public class Wbase_claim_quantity extends Wbase_claim_base {
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;

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2020 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.
@ -89,9 +89,11 @@ public class Wdata_pf_property__basic__tst {
fxt.Test_parse("{{#property:p1}}", "1,234±2");
}
@Test public void Quantity__plus_minus__n() { // PURPOSE:do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
// 2021-02-14|ISSUE#:839|Only print value without ± if lo and hi are null; PAGE:en.w:2019_FIVB_Volleyball_Women%27s_Challenger_Cup#Pool_A
// TOMBSTONE:2015-08-02|do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan
@Test public void Quantity__plus_minus__n() {
fxt.Init__docs__add(fxt.Wdoc("Q1")
.Add_claims(fxt.Make_claim_quantity(1, "+1234", "1", "+1234", "+1234"))
.Add_claims(fxt.Make_claim_quantity(1, "+1234", "1", null, null))
.Add_sitelink("enwiki", "Test_page")
);
@ -107,7 +109,7 @@ public class Wdata_pf_property__basic__tst {
}
@Test public void Quantity__long() { // PURPOSE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
fxt.Init__docs__add(fxt.Wdoc("Q1")
.Add_claims(fxt.Make_claim_quantity(1, "+4321000000", "1", "4321000000", "4321000000"))
.Add_claims(fxt.Make_claim_quantity(1, "+4321000000", "1", null, null))
.Add_sitelink("enwiki", "Test_page")
);

Loading…
Cancel
Save