mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Wikibase: Show {{#property}} geo-coordinates in degrees, not raw numbers
This commit is contained in:
parent
653c36895f
commit
bc10e474c2
@ -111,7 +111,7 @@ public class Scrib_lib_wikibase_tst {
|
||||
}
|
||||
@Test public void RenderSnak__geo() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_geo(3, "3.4", "1.2"));
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "1.2, 3.4");
|
||||
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "1° 12' 0" E, 3° 24' 0" N (<a href='/wiki/Q2'>http://www.wikidata.org/entity/Q2</a>)");
|
||||
}
|
||||
@Test public void RenderSnak__monolingual() {
|
||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "abc_en"));
|
||||
|
@ -118,14 +118,30 @@ public class Wdata_prop_val_visitor implements Wbase_claim_visitor {
|
||||
}
|
||||
return bfr == null ? bry : bfr.To_bry_and_clear();
|
||||
}
|
||||
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {Write_geo(bfr, wdata_mgr, lang, itm.Lat(), itm.Lng());}
|
||||
public static void Write_geo(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, Xol_lang_itm lang, byte[] lat, byte[] lng) {
|
||||
bfr.Add(lat);
|
||||
bfr.Add(Bry__geo_dlm);
|
||||
bfr.Add(lng);
|
||||
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {Write_geo(Bool_.N, bfr, wdata_mgr.Hwtr_mgr().Lbl_mgr(), itm.Lat(), itm.Lng(), itm.Alt(), itm.Prc(), itm.Glb());}
|
||||
public static void Write_geo(boolean wikidata_page, Bry_bfr bfr, Wdata_lbl_mgr lbl_mgr, byte[] lat, byte[] lng, byte[] alt, byte[] prc, byte[] glb) {
|
||||
// get precision
|
||||
Decimal_adp precision_frac = Bry_.Eq(prc, Object_.Bry__null) ? Decimal_adp_.One : Decimal_adp_.parse(String_.new_a7(prc));
|
||||
int precision_int = Math_.Log10(Decimal_adp_.One.Divide(precision_frac).To_int()); // convert precision to log10 integer; EX: .00027777 -> 3600 -> 3
|
||||
|
||||
// build String
|
||||
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(bfr, Bool_.N, lat, precision_int);
|
||||
bfr.Add_byte_comma().Add_byte_space();
|
||||
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(bfr, Bool_.Y, lng, precision_int);
|
||||
|
||||
// write globe if any
|
||||
if (wikidata_page) {
|
||||
byte[] glb_ttl = Wdata_lbl_itm.Extract_ttl(glb);
|
||||
if (glb_ttl != null) {
|
||||
byte[] glb_lbl = lbl_mgr.Get_text__ttl(glb_ttl, glb);
|
||||
bfr.Add_byte_space().Add_byte(Byte_ascii.Paren_bgn);
|
||||
Wdata_hwtr_mgr.Write_link_wikidata(bfr, glb_ttl, glb_lbl);
|
||||
bfr.Add_byte(Byte_ascii.Paren_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] Wikidata_url = Bry_.new_a7("http://www.wikidata.org/entity/");
|
||||
private static final byte[] Bry__geo_dlm = Bry_.new_a7(", ");
|
||||
public void Visit_system(Wbase_claim_value itm) {}
|
||||
public static final byte[] Bry__quantity_margin_of_error = Bry_.new_u8("±");
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public class Wdata_prop_val_visitor_ {
|
||||
Wdata_prop_val_visitor.Write_quantity(bfr, wdata_mgr, lang, amount, lbound, ubound, unit);
|
||||
}
|
||||
private static void Write_geo(Bry_bfr bfr, Wdata_wiki_mgr wdata_mgr, Xol_lang_itm lang, byte[] page_url, Keyval[] kvs) {
|
||||
byte[] lat = null, lng = null;
|
||||
byte[] lat = null, lng = null, alt = null, prc = null, glb = null;
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Keyval kv = kvs[i];
|
||||
@ -151,12 +151,12 @@ public class Wdata_prop_val_visitor_ {
|
||||
switch (val_tid) {
|
||||
case Wbase_claim_globecoordinate_.Tid__latitude: lat = To_bry_by_double(kv.Val()); break;
|
||||
case Wbase_claim_globecoordinate_.Tid__longitude: lng = To_bry_by_double(kv.Val()); break;
|
||||
case Wbase_claim_globecoordinate_.Tid__altitude: break;
|
||||
case Wbase_claim_globecoordinate_.Tid__precision: break;
|
||||
case Wbase_claim_globecoordinate_.Tid__globe: break;
|
||||
case Wbase_claim_globecoordinate_.Tid__altitude: alt = To_bry_by_str(kv.Val()); break;
|
||||
case Wbase_claim_globecoordinate_.Tid__precision: prc = To_bry_by_double(kv.Val()); break;
|
||||
case Wbase_claim_globecoordinate_.Tid__globe: glb = To_bry_by_str(kv.Val()); break;
|
||||
}
|
||||
}
|
||||
Wdata_prop_val_visitor.Write_geo(bfr, wdata_mgr, lang, lat, lng);
|
||||
Wdata_prop_val_visitor.Write_geo(Bool_.Y, bfr, wdata_mgr.Hwtr_mgr().Lbl_mgr(), lat, lng, alt, prc, glb);
|
||||
}
|
||||
private static void Write_langtext(Bry_bfr bfr, byte[] page_url, Keyval[] kvs) {
|
||||
byte[] text = null;
|
||||
|
@ -28,7 +28,6 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
private final Wdata_prop_val_visitor prop_val_visitor;
|
||||
private final Wdata_doc_parser wdoc_parser_v1 = new Wdata_doc_parser_v1(), wdoc_parser_v2 = new Wdata_doc_parser_v2();
|
||||
private final Object thread_lock = new Object();
|
||||
private Wdata_hwtr_mgr hwtr_mgr;
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(32);
|
||||
public Wdata_wiki_mgr(Xoae_app app) {
|
||||
this.app = app;
|
||||
@ -51,6 +50,11 @@ public class Wdata_wiki_mgr implements Gfo_evt_itm, Gfo_invk {
|
||||
Doc_mgr.Enabled_(v);
|
||||
}
|
||||
public byte[] Domain() {return domain;} public void Domain_(byte[] v) {domain = v;} private byte[] domain = Bry_.new_a7("www.wikidata.org");
|
||||
public Wdata_hwtr_mgr Hwtr_mgr() {
|
||||
if (hwtr_mgr == null)
|
||||
Hwtr_mgr_assert();
|
||||
return hwtr_mgr;
|
||||
} private Wdata_hwtr_mgr hwtr_mgr;
|
||||
public Xowe_wiki Wdata_wiki() {
|
||||
if (wdata_wiki == null) {
|
||||
synchronized (thread_lock) { // LOCK:must synchronized b/c multiple threads may init wdata_mgr at same time;
|
||||
|
@ -32,7 +32,7 @@ public class Wdata_hwtr_mgr {
|
||||
private Wdata_lang_sorter lang_sorter = new Wdata_lang_sorter();
|
||||
public Bry_fmtr Fmtr_main() {return fmtr_main;} private final Bry_fmtr fmtr_main = Bry_fmtr.new_("~{oview}~{toc}~{claims}~{links}~{labels}~{descriptions}~{aliases}~{json}", "oview", "toc", "claims", "links", "labels", "descriptions", "aliases", "json");
|
||||
public Wdata_hwtr_msgs Msgs() {return msgs;} private Wdata_hwtr_msgs msgs;
|
||||
@gplx.Internal protected Wdata_lbl_mgr Lbl_mgr() {return lbl_mgr;} private final Wdata_lbl_mgr lbl_mgr = new Wdata_lbl_mgr();
|
||||
public Wdata_lbl_mgr Lbl_mgr() {return lbl_mgr;} private final Wdata_lbl_mgr lbl_mgr = new Wdata_lbl_mgr();
|
||||
public void Init_by_ctor(Xoapi_wikibase wikibase_api, Wdata_lbl_wkr lbl_wkr, Gfo_url_encoder href_encoder, Xoapi_toggle_mgr toggle_mgr, Xow_xwiki_mgr xwiki_mgr) {
|
||||
lbl_mgr.Wkr_(lbl_wkr);
|
||||
fmtr_oview.Init_by_ctor(wikibase_api, href_encoder);
|
||||
|
@ -72,22 +72,7 @@ class Wdata_visitor__html_wtr implements Wbase_claim_visitor {
|
||||
} private static final byte[] Time_plus_minus_spr = Bry_.new_a7(" / ");
|
||||
public void Visit_time(Wbase_claim_time itm) {itm.Write_to_bfr(tmp_bfr, tmp_time_bfr, tmp_time_fmtr, msgs, ttl);}
|
||||
public void Visit_globecoordinate(Wbase_claim_globecoordinate itm) {
|
||||
try {
|
||||
Decimal_adp precision_frac = itm.Prc_as_num(); // precision is a decimal; EX: .00027777
|
||||
int precision_int = Math_.Log10(Decimal_adp_.One.Divide(precision_frac).To_int()); // convert precision to log10 integer; EX: .00027777 -> 3600 -> 3
|
||||
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(tmp_bfr, Bool_.Y, itm.Lng(), precision_int);
|
||||
tmp_bfr.Add_byte_comma().Add_byte_space();
|
||||
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(tmp_bfr, Bool_.N, itm.Lat(), precision_int);
|
||||
byte[] glb_ttl = itm.Glb_ttl();
|
||||
if (glb_ttl != null) {
|
||||
byte[] glb_lbl = lbl_mgr.Get_text__ttl(glb_ttl, itm.Glb());
|
||||
tmp_bfr.Add_byte_space().Add_byte(Byte_ascii.Paren_bgn);
|
||||
Wdata_hwtr_mgr.Write_link_wikidata(tmp_bfr, glb_ttl, glb_lbl);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Paren_end);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to write globecoordinate; ttl=~{0} pid=~{1} err=~{2}", ttl, itm.Pid(), Err_.Message_gplx_full(e));
|
||||
}
|
||||
Wdata_prop_val_visitor.Write_geo(Bool_.Y, tmp_bfr, lbl_mgr, itm.Lat(), itm.Lng(), itm.Alt(), itm.Prc(), itm.Glb());
|
||||
}
|
||||
public void Visit_system(Wbase_claim_value itm) {
|
||||
switch (itm.Snak_tid()) {
|
||||
|
@ -76,14 +76,14 @@ public class Wdata_visitor__html_wtr_tst {
|
||||
.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")
|
||||
, "51° 30' 26" N, 0° 7' 39" W (<a href='/wiki/Q2'>Earth</a>)"
|
||||
, "0° 7' 39" W, 51° 30' 26" N (<a href='/wiki/Q2'>Earth</a>)"
|
||||
);
|
||||
}
|
||||
@Test public void Globecoordinate_null() {
|
||||
fxt
|
||||
.Test_claim_val
|
||||
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
|
||||
, "51° 30' 26" N, 0° 7' 39" W"
|
||||
, "0° 7' 39" W, 51° 30' 26" N"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class Wdata_pf_property__basic__tst {
|
||||
@Test public void Geodata() {
|
||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||
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");
|
||||
fxt.Test_parse("{{#property:p1}}", "1° 14' 4.2" E, 6° 47' 20.4" N");
|
||||
}
|
||||
@Test public void Quantity__plus_minus__y() {
|
||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||
|
Loading…
Reference in New Issue
Block a user