mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
uca category support and other changes
This commit is contained in:
@@ -44,15 +44,45 @@ class Wdata_prop_val_visitor implements Wbase_claim_visitor {
|
||||
bfr.Add(label);
|
||||
}
|
||||
public void Visit_quantity(Wbase_claim_quantity itm) {
|
||||
byte[] amount_bry = itm.Amount();
|
||||
long val = Bry_.To_long_or(amount_bry, Byte_ascii.Comma_bry, 0, amount_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
|
||||
// get val
|
||||
byte[] val_bry = itm.Amount();
|
||||
long val = Bry_.To_long_or(val_bry, Byte_ascii.Comma_bry, 0, val_bry.length, 0); // NOTE: must cast to long for large numbers; EX:{{#property:P1082}} PAGE:en.w:Earth; DATE:2015-08-02
|
||||
|
||||
// get lo, hi
|
||||
long lo = itm.Lbound_as_num().To_long();
|
||||
long hi = itm.Ubound_as_num().To_long();
|
||||
|
||||
// fmt val
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by(lang_key);
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(val)); // amount; EX: 1,234
|
||||
if (itm.Lbound_as_num().To_long() != val && itm.Ubound_as_num().To_long() != val) { // NOTE: do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
|
||||
bfr.Add(Bry__quantity_margin_of_error); // symbol: EX: ±
|
||||
if (lo == val && hi == val) // lo, hi, val are same; print val only;
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(val)); // amount; EX: 1,234
|
||||
else {
|
||||
long lo_dif = val - lo;
|
||||
long hi_dif = hi - val;
|
||||
if (lo_dif == hi_dif) { // lo_dif, hi_dif are same; print val±dif
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(val)); // amount; EX: 1,234
|
||||
bfr.Add(Bry__quantity_margin_of_error); // symbol: EX: ±
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(lo_dif)); // amount; EX: 4
|
||||
}
|
||||
else { // lo_dif, hi_dif are diff; print lo - hi; this may not be what MW does
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(lo)); // lo; EX: 1,230
|
||||
bfr.Add_byte(Byte_ascii.Dash); // dash: EX: -
|
||||
bfr.Add(lang.Num_mgr().Format_num_by_long(hi)); // hi; EX: 1,238
|
||||
}
|
||||
}
|
||||
|
||||
// output unit
|
||||
bfr.Add_byte_space();
|
||||
int unit_qid_bgn = Bry_find_.Find_fwd(itm.Unit(), Wikidata_url);
|
||||
if (unit_qid_bgn == Bry_find_.Not_found) // entity missing; just output unit literally
|
||||
bfr.Add(itm.Unit()); // unit; EX: 1
|
||||
else { // entity exists; EX:"http://www.wikidata.org/entity/Q11573" (meter)
|
||||
byte[] xid = Bry_.Mid(itm.Unit(), Wikidata_url.length);
|
||||
Wdata_doc entity_doc = wdata_mgr.Doc_mgr.Get_by_xid_or_null(xid);
|
||||
bfr.Add(entity_doc.Label_list__get_or_fallback(lang));
|
||||
}
|
||||
}
|
||||
private static final byte[] Wikidata_url = Bry_.new_a7("http://www.wikidata.org/entity/");
|
||||
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
|
||||
Wdata_prop_val_visitor_.Render__geo(bfr, itm.Lat(), itm.Lng());
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class Io_stream_rdr_mgr {
|
||||
Io_url src_itm_url = src_itm.Url();
|
||||
Io_stream_rdr rv = unzip_mgr.Handles(src_itm_url)
|
||||
? unzip_mgr.New_rdr(src_itm_url)
|
||||
: Io_stream_rdr_.file_(src_itm_url);
|
||||
: Io_stream_rdr_.New__raw(src_itm_url);
|
||||
rv.Len_(src_itm.Size());
|
||||
return rv;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class Io_stream_unzip_mgr {
|
||||
public Io_stream_rdr New_rdr(Io_url url) {
|
||||
return stdout_enabled
|
||||
? Io_stream_rdr_process.new_(stdout_process.Exe_url(), url, stdout_process.Xto_process_bldr_args(url.Raw()))
|
||||
: Io_stream_rdr_.bzip2_(url)
|
||||
: Io_stream_rdr_.New__bzip2(url)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,20 +53,33 @@ public class Wdata_pf_property__basic__tst {
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_geo(1, "6.789", "1.2345")));
|
||||
fxt.Test_parse("{{#property:p1}}", "1.2345, 6.789");
|
||||
}
|
||||
@Test public void Quantity() {
|
||||
@Test public void Quantity__plus_minus__y() {
|
||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "2", "+1236", "+1232")));
|
||||
fxt.Test_parse("{{#property:p1}}", "1,234±2");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "meter", "+1236", "+1232")));
|
||||
fxt.Test_parse("{{#property:p1}}", "1,234±2 meter");
|
||||
}
|
||||
@Test public void Quantity__no_plus_minus() { // PURPOSE:do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
|
||||
@Test public void Quantity__plus_minus__n() { // PURPOSE:do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
|
||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "1", "+1234", "+1234")));
|
||||
fxt.Test_parse("{{#property:p1}}", "1,234");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "meter", "+1234", "+1234")));
|
||||
fxt.Test_parse("{{#property:p1}}", "1,234 meter");
|
||||
}
|
||||
@Test public void Quantity__range() { // PURPOSE:do not output ± if lbound == val == ubound; PAGE:en.w:Tintinan DATE:2015-08-02
|
||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "meter", "+1236", "+1233")));
|
||||
fxt.Test_parse("{{#property:p1}}", "1,233-1,236 meter");
|
||||
}
|
||||
@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_links_add("enwiki", "Test_page", "q1");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+4321000000", "1", "4321000000", "4321000000")));
|
||||
fxt.Test_parse("{{#property:p1}}", "4,321,000,000");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+4321000000", "meter", "4321000000", "4321000000")));
|
||||
fxt.Test_parse("{{#property:p1}}", "4,321,000,000 meter");
|
||||
}
|
||||
@Test public void Quantity__unit__entity() {// PURPOSE: get entity name; EX:{{#invoke:Wikidata|getUnits|P2386|FETCH_WIKIDATA}} PAGE:en.w:Arecibo_Observatory; DATE:2016-10-11
|
||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||
fxt.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_quantity(1, "+1234", "http://www.wikidata.org/entity/q2", "+1236", "+1232")));
|
||||
Wdata_doc wdoc = fxt.doc_("q2", fxt.Make_claim_string(2, "a"));
|
||||
wdoc.Label_list().Add(Bry_.new_a7("en"), new gplx.xowa.xtns.wbases.core.Wdata_langtext_itm(Bry_.new_a7("en"), Bry_.new_a7("meter")));
|
||||
fxt.Init__docs__add(wdoc);
|
||||
fxt.Test_parse("{{#property:p1}}", "1,234±2 meter");
|
||||
}
|
||||
@Test public void Monolingualtext() {
|
||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||
|
||||
Reference in New Issue
Block a user