mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-09-29 23:10:52 +00:00
Wikibase.Coordinate: Reverse NS / EW direction for geocoordinates; also, standardize spacing / symbols for wikibase
This commit is contained in:
parent
8501ec6fd8
commit
26a56950cd
@ -45,16 +45,18 @@ public class Map_dd2dms_func extends Pf_func_base {
|
|||||||
tmp_bfr.Mkr_rls();
|
tmp_bfr.Mkr_rls();
|
||||||
Map_math map_math = Map_math.Instance;
|
Map_math map_math = Map_math.Instance;
|
||||||
if (map_math.Ctor(coord, prec, Bry_.Empty, 2))
|
if (map_math.Ctor(coord, prec, Bry_.Empty, 2))
|
||||||
bfr.Add(map_math.Get_dms(plus, minus));
|
bfr.Add(map_math.Get_dms(Bool_.N, plus, minus));
|
||||||
else
|
else
|
||||||
map_math.Fail(ctx, src, self, bfr, this.Name());
|
map_math.Fail(ctx, src, self, bfr, this.Name());
|
||||||
}
|
}
|
||||||
public static void Deg_to_dms(Bry_bfr bfr, boolean coord_is_lng, byte[] coord, int prec) {
|
public static void Deg_to_dms(Bry_bfr bfr, boolean wikibase, boolean coord_is_lng, byte[] coord, int prec) { // NOTE: called by wikibase
|
||||||
Map_math map_math = Map_math.Instance;
|
Map_math map_math = Map_math.Instance;
|
||||||
if (map_math.Ctor(coord, prec, Bry_.Empty, 2)) {
|
if (map_math.Ctor(coord, prec, Bry_.Empty, 2)) {
|
||||||
bfr.Add(map_math.Get_dms(Bry_.Empty, Bry_.Empty));
|
bfr.Add(map_math.Get_dms(wikibase, Bry_.Empty, Bry_.Empty));
|
||||||
byte[] dir = coord_is_lng ? map_math.Coord_dir_ns() : map_math.Coord_dir_ew();
|
byte[] dir = coord_is_lng ? map_math.Coord_dir_ew() : map_math.Coord_dir_ns();
|
||||||
bfr.Add_byte_space().Add(dir);
|
if (!wikibase) // NOTE: do not add space if wikibase, else will fail in Module:en.w:WikidataCoord; PAGE:en.w:Hulme_Arch_Bridge DATE:2017-04-02
|
||||||
|
bfr.Add_byte_space();
|
||||||
|
bfr.Add(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static final Map_dd2dms_func Instance = new Map_dd2dms_func(); Map_dd2dms_func() {}
|
public static final Map_dd2dms_func Instance = new Map_dd2dms_func(); Map_dd2dms_func() {}
|
||||||
|
@ -72,7 +72,7 @@ public class Map_geolink_func extends Pf_func_base {
|
|||||||
}
|
}
|
||||||
private static byte[] Xto_dms(Xop_ctx ctx, Map_math math, boolean pass, byte[] pos, byte[] neg) {
|
private static byte[] Xto_dms(Xop_ctx ctx, Map_math math, boolean pass, byte[] pos, byte[] neg) {
|
||||||
return pass
|
return pass
|
||||||
? math.Get_dms(pos, neg)
|
? math.Get_dms(Bool_.N, pos, neg)
|
||||||
: ctx.Wiki().Msg_mgr().Val_by_key_obj("mapsources-math-incorrect-input")
|
: ctx.Wiki().Msg_mgr().Val_by_key_obj("mapsources-math-incorrect-input")
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -110,19 +110,27 @@ class Map_math {// REF.MW:MapSources_math.php
|
|||||||
}
|
}
|
||||||
step = 2;
|
step = 2;
|
||||||
}
|
}
|
||||||
private static final byte[] Bry_deg = Bry_.new_u8("°"), Bry_quot = Bry_.new_a7(""");
|
public byte[] Get_dms(boolean wikibase, byte[] plus, byte[] minus) { // REF.MW: getDMSString
|
||||||
public byte[] Get_dms(byte[] plus, byte[] minus) { // REF.MW: getDMSString
|
|
||||||
if (step < 2) Set_coord();
|
if (step < 2) Set_coord();
|
||||||
double deg = coord_deg;
|
double deg = coord_deg;
|
||||||
if ( dec < 0
|
if ( dec < 0
|
||||||
&& (Bry_.Len_gt_0(plus) || Bry_.Len_gt_0(minus))) {
|
&& ( (Bry_.Len_gt_0(plus) || Bry_.Len_gt_0(minus))
|
||||||
|
|| wikibase // NOTE: wikibase will always pass in empty plus / minus; still need to suppress "-" sign because letter has already been reversed; EX:"-2 E" -> "2 W" x> "-2 W" DATE:2017-04-02
|
||||||
|
)
|
||||||
|
) {
|
||||||
deg = Math_.Abs_double(deg);
|
deg = Math_.Abs_double(deg);
|
||||||
}
|
}
|
||||||
tmp_bfr.Add_double(deg).Add(Bry_deg);
|
tmp_bfr.Add_double(deg).Add(Bry_deg);
|
||||||
if (prec > 0)
|
if (prec > 0) {
|
||||||
tmp_bfr.Add_byte_space().Add_double(coord_min).Add_byte(Byte_ascii.Apos);
|
if (!wikibase) // NOTE: do not add space if wikibase, else will fail in Module:en.w:WikidataCoord; PAGE:en.w:Hulme_Arch_Bridge DATE:2017-04-02
|
||||||
if (prec > 2)
|
tmp_bfr.Add_byte_space();
|
||||||
tmp_bfr.Add_byte_space().Add_double(coord_sec).Add(Bry_quot);
|
tmp_bfr.Add_double(coord_min).Add(wikibase ? Bry_apos_wb : Bry_apos_mw);
|
||||||
|
}
|
||||||
|
if (prec > 2) {
|
||||||
|
if (!wikibase) // NOTE: do not add space if wikibase, else will fail in Module:en.w:WikidataCoord; PAGE:en.w:Hulme_Arch_Bridge DATE:2017-04-02
|
||||||
|
tmp_bfr.Add_byte_space();
|
||||||
|
tmp_bfr.Add_double(coord_sec).Add(wikibase ? Bry_quot_wb : Bry_quot_mw);
|
||||||
|
}
|
||||||
byte[] letter = null;
|
byte[] letter = null;
|
||||||
if (dir_id == Dir_lat_id)
|
if (dir_id == Dir_lat_id)
|
||||||
letter = coord_dir_ns;
|
letter = coord_dir_ns;
|
||||||
@ -132,8 +140,10 @@ class Map_math {// REF.MW:MapSources_math.php
|
|||||||
letter = plus;
|
letter = plus;
|
||||||
if (dec < 0 && Bry_.Len_gt_0(minus))
|
if (dec < 0 && Bry_.Len_gt_0(minus))
|
||||||
letter = minus;
|
letter = minus;
|
||||||
if (letter != null)
|
if (letter != null) {
|
||||||
tmp_bfr.Add_byte_space().Add(letter);
|
tmp_bfr.Add_byte_space();
|
||||||
|
tmp_bfr.Add(letter);
|
||||||
|
}
|
||||||
return tmp_bfr.To_bry_and_clear();
|
return tmp_bfr.To_bry_and_clear();
|
||||||
}
|
}
|
||||||
private void Parse_input(byte[] src) { // REF.MW: toDec
|
private void Parse_input(byte[] src) { // REF.MW: toDec
|
||||||
@ -257,6 +267,13 @@ class Map_math {// REF.MW:MapSources_math.php
|
|||||||
src = Trie__normalize__rest.Replace(bfr, src, 0, src.length); // normalize rest;
|
src = Trie__normalize__rest.Replace(bfr, src, 0, src.length); // normalize rest;
|
||||||
return Bry_.Trim(src);
|
return Bry_.Trim(src);
|
||||||
}
|
}
|
||||||
|
private static final byte[]
|
||||||
|
Bry_deg = Bry_.new_u8("°")
|
||||||
|
, Bry_quot_mw = Bry_.new_a7(""")
|
||||||
|
, Bry_quot_wb = Bry_.new_a7(""") // REF:en.w:Module:WikidataCoord
|
||||||
|
, Bry_apos_mw = Bry_.new_a7("'")
|
||||||
|
, Bry_apos_wb = Bry_.new_a7("'") // REF:en.w:Module:WikidataCoord
|
||||||
|
;
|
||||||
private static final byte Dir_unknown_id = 0, Dir_lat_id = 1, Dir_long_id = 2;
|
private static final byte Dir_unknown_id = 0, Dir_lat_id = 1, Dir_long_id = 2;
|
||||||
public static final byte[] Dir_lat_bry = Bry_.new_a7("lat"), Dir_long_bry = Bry_.new_a7("long");
|
public static final byte[] Dir_lat_bry = Bry_.new_a7("lat"), Dir_long_bry = Bry_.new_a7("long");
|
||||||
private static final Btrie_slim_mgr Dir_trie = Btrie_slim_mgr.ci_a7() // NOTE:ci.ascii:MW_const.en
|
private static final Btrie_slim_mgr Dir_trie = Btrie_slim_mgr.ci_a7() // NOTE:ci.ascii:MW_const.en
|
||||||
|
@ -114,7 +114,7 @@ public class Scrib_lib_wikibase_tst {
|
|||||||
}
|
}
|
||||||
@Test public void RenderSnak__geo() {
|
@Test public void RenderSnak__geo() {
|
||||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_geo(3, "3.4", "1.2"));
|
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° 12' 0" E, 3° 24' 0" N (<a href='/wiki/Q2'>http://www.wikidata.org/entity/Q2</a>)");
|
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "1°12'0"N, 3°24'0"E (<a href='/wiki/Q2'>http://www.wikidata.org/entity/Q2</a>)");
|
||||||
}
|
}
|
||||||
@Test public void RenderSnak__monolingual() {
|
@Test public void RenderSnak__monolingual() {
|
||||||
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "abc_en"));
|
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "abc_en"));
|
||||||
|
@ -133,9 +133,9 @@ public class Wdata_prop_val_visitor implements Wbase_claim_visitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build String
|
// build String
|
||||||
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(bfr, Bool_.N, lat, precision_int);
|
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(bfr, Bool_.Y, Bool_.N, lat, precision_int);
|
||||||
bfr.Add_byte_comma().Add_byte_space();
|
bfr.Add_byte_comma().Add_byte_space();
|
||||||
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(bfr, Bool_.Y, lng, precision_int);
|
gplx.xowa.xtns.mapSources.Map_dd2dms_func.Deg_to_dms(bfr, Bool_.Y, Bool_.Y, lng, precision_int);
|
||||||
|
|
||||||
// write globe if any
|
// write globe if any
|
||||||
if (wikidata_page) {
|
if (wikidata_page) {
|
||||||
|
@ -81,21 +81,21 @@ public class Wdata_visitor__html_wtr_tst {
|
|||||||
.Init_resolved_qid(2, "Earth")
|
.Init_resolved_qid(2, "Earth")
|
||||||
.Test_claim_val
|
.Test_claim_val
|
||||||
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
|
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "123", "http://www.wikidata.org/entity/Q2")
|
||||||
, "0° 7' 39" W, 51° 30' 26" N (<a href='/wiki/Q2'>Earth</a>)"
|
, "0°7'39"S, 51°30'26"E (<a href='/wiki/Q2'>Earth</a>)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@Test public void Globecoordinate__globe__null() {
|
@Test public void Globecoordinate__globe__null() {
|
||||||
fxt
|
fxt
|
||||||
.Test_claim_val
|
.Test_claim_val
|
||||||
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
|
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", ".000027777", "null", "")
|
||||||
, "0° 7' 39" W, 51° 30' 26" N"
|
, "0°7'39"S, 51°30'26"E"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@Test public void Globecoordinate__precision__0() { // PURPOSE: 0 precision was causing divide by 0 error; PAGE:ru.w:Лысково_(Калужская_область) DATE:2016-11-24
|
@Test public void Globecoordinate__precision__0() { // PURPOSE: 0 precision was causing divide by 0 error; PAGE:ru.w:Лысково_(Калужская_область) DATE:2016-11-24
|
||||||
fxt
|
fxt
|
||||||
.Test_claim_val
|
.Test_claim_val
|
||||||
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", "0", "null", "")
|
( fxt.Wdata_fxt().Make_claim_geo(1, "51.5072222", "-0.1275", "0", "null", "")
|
||||||
, "0° 6' W, 51° 30' N"
|
, "0°6'S, 51°30'E"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class Wdata_pf_property__basic__tst {
|
|||||||
@Test public void Geodata() {
|
@Test public void Geodata() {
|
||||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
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.Init__docs__add(fxt.doc_("q1", fxt.Make_claim_geo(1, "6.789", "1.2345")));
|
||||||
fxt.Test_parse("{{#property:p1}}", "1° 14' 4.2" E, 6° 47' 20.4" N");
|
fxt.Test_parse("{{#property:p1}}", "1°14'4.2"N, 6°47'20.4"E");
|
||||||
}
|
}
|
||||||
@Test public void Quantity__plus_minus__y() {
|
@Test public void Quantity__plus_minus__y() {
|
||||||
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
fxt.Init_links_add("enwiki", "Test_page", "q1");
|
||||||
|
Loading…
Reference in New Issue
Block a user