Wikibase: Fix getBestStatements to return normal if no preferred [#297]

pull/620/head
gnosygnu 6 years ago
parent 51e42d65ad
commit 225959160c

@ -67,48 +67,55 @@ public class Keyval_ {
}
public static String Ary__to_str__nest(Keyval... ary) {
Bry_bfr bfr = Bry_bfr_.New();
Ary__to_str__nest__obj(bfr, 0, true, ary);
Ary__to_str__nest__ary(bfr, 0, true, ary);
return bfr.To_str_and_clear();
}
private static void Ary__to_str__nest__obj(Bry_bfr bfr, int indent, boolean is_kv, Object[] ary) {
private static void Ary__to_str__nest__ary(Bry_bfr bfr, int indent, boolean is_kv, Object[] ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Object val = ary[i];
if (indent > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent; EX: " "
String key = null;
if (is_kv) {
Keyval kv = (Keyval)val;
key = Object_.Xto_str_strict_or_empty(kv.Key());
val = kv.Val();
Ary__to_str__nest__val(bfr, indent, is_kv, i, ary[i]);
}
}
private static void Ary__to_str__nest__val(Bry_bfr bfr, int indent, boolean is_kv, int idx, Object val) {
if (indent > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, indent * 2); // add indent; EX: " "
String key = null;
if (is_kv) {
Keyval kv = (Keyval)val;
key = Object_.Xto_str_strict_or_empty(kv.Key());
val = kv.Val();
}
else {
key = Int_.To_str(idx + 1);
}
bfr.Add_str_u8(key).Add_byte_eq(); // add key + eq : "key="
if (val == null)
bfr.Add_str_a7(String_.Null_mark);
else {
Class<?> val_type = Type_.Type_by_obj(val);
if (Type_.Eq(val_type, Keyval[].class)) { // val is Keyval[]; recurse
bfr.Add_byte_nl(); // add nl: "\n"
Ary__to_str__nest__ary(bfr, indent + 1, true, (Keyval[])val);
return; // don't add \n below
}
else if (Type_.Eq(val_type, Keyval.class)) { // val is Keyval; recurse
bfr.Add_byte_nl(); // add nl: "\n"
Ary__to_str__nest__val(bfr, indent + 1, true, 1, (Keyval)val);
return; // don't add \n below
}
else {
key = Int_.To_str(i + 1);
else if (Type_.Eq(val_type, Object[].class)) { // val is Object[]
bfr.Add_byte_nl();
Ary__to_str__nest__ary(bfr, indent + 1, false, (Object[])val);
return; // don't add \n below
}
bfr.Add_str_u8(key).Add_byte_eq(); // add key + eq : "key="
if (val == null)
bfr.Add_str_a7(String_.Null_mark);
else {
Class<?> val_type = Type_.Type_by_obj(val);
if (Type_.Eq(val_type, Keyval[].class)) { // val is Keyval[]; recurse
bfr.Add_byte_nl(); // add nl : "\n"
Ary__to_str__nest__obj(bfr, indent + 1, true, (Keyval[])val);
continue; // don't add \n below
}
else if (Type_.Eq(val_type, Object[].class)) { // val is Object[]
bfr.Add_byte_nl();
Ary__to_str__nest__obj(bfr, indent + 1, false, (Object[])val);
continue; // don't add \n below
}
else if (Type_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
boolean val_as_bool = Bool_.Cast(val);
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
}
else
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(val)); // call toString()
else if (Type_.Eq(val_type, Bool_.Cls_ref_type)) { // val is boolean
boolean val_as_bool = Bool_.Cast(val);
bfr.Add(val_as_bool ? Bool_.True_bry : Bool_.False_bry); // add "true" or "false"; don't call toString
}
bfr.Add_byte_nl();
else
bfr.Add_str_u8(Object_.Xto_str_strict_or_null_mark(val)); // call toString()
}
bfr.Add_byte_nl();
}
public static Keyval as_(Object obj) {return obj instanceof Keyval ? (Keyval)obj : null;}
public static Keyval new_(String key) {return new Keyval(Type_ids_.Id__str, key, key);}

@ -99,7 +99,14 @@ public class Scrib_lib_title_tst {
fxt.Test__proc__objs__flat(lib, Scrib_lib_title.Invk_getContent, Object_.Ary("A") , "#REDIRECT [[B]]"); // fails with null
}
@Test public void ProtectionLevels() {
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_protectionLevels, Object_.Ary("A") , String_.Concat_lines_nl_skip_last("1=", " move=1=sysop", " edit=1=sysop"));
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_protectionLevels, Object_.Ary("A"),
String_.Concat_lines_nl_skip_last
( "1="
, " move="
, " 1=sysop"
, " edit="
, " 1=sysop"
));
}
@Test public void CascadingProtection() {
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_cascadingProtection, Object_.Ary("A") , Scrib_lib_title.CascadingProtection_rv);

@ -188,9 +188,10 @@ public class Scrib_lib_wikibase implements Scrib_lib {
Wbase_prop_mgr prop_mgr = core.Wiki().Appe().Wiki_mgr().Wdata_mgr().Prop_mgr();
Wbase_claim_base[] statements = this.entity_accessor.getEntityStatements(prefixedEntityId, propertyId, rank);
if (statements == null)
return rslt.Init_null();
return rslt.Init_obj(Scrib_lib_wikibase_srl.Srl_claims_prop_ary(prop_mgr, String_.new_u8(propertyId), statements, 1));
if (statements == null) return rslt.Init_null();
String propertyIdAsString = String_.new_u8(propertyId);
return rslt.Init_obj(Keyval_.new_(propertyIdAsString, Scrib_lib_wikibase_srl.Srl_claims_prop_ary(prop_mgr, propertyIdAsString, statements, 1)));
}
public boolean RenderSnak(Scrib_proc_args args, Scrib_proc_rslt rslt) {
Xowe_wiki wiki = core.Wiki();

@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.parsers.*; import gplx.xowa.xtns.wbases.stores.*;
class Scrib_lib_wikibase_srl {
public class Scrib_lib_wikibase_srl {
public static Keyval[] Srl(Wbase_prop_mgr prop_mgr, Wdata_doc wdoc, boolean header_enabled, boolean legacy_style) {// REF.MW:/Wikibase/lib/includes/serializers/EntitySerializer.php!getSerialized; http://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
int base_adj = legacy_style ? 0 : 1;
List_adp rv = List_adp_.New();

@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import gplx.xowa.xtns.wbases.core.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.enums.*; import gplx.xowa.xtns.wbases.claims.itms.*;
class Scrib_lib_wikibase_srl_visitor implements Wbase_claim_visitor {
public class Scrib_lib_wikibase_srl_visitor implements Wbase_claim_visitor {
public Keyval[] Rv() {return rv;} Keyval[] rv;
public void Visit_str(Wbase_claim_string itm) {
rv = new Keyval[2];

@ -13,10 +13,10 @@ 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.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
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.*;
public class Scrib_lib_wikibase_tst {
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();
@Before public void init() {
@ -164,27 +164,6 @@ public class Scrib_lib_wikibase_tst {
Keyval[] args = Wbase_snak_utl_.Get_snak(wdata_fxt, wdata_fxt.Make_claim_monolingual(3, "en", "abc_en"));
fxt.Test__proc__kvps__flat(lib, Scrib_lib_wikibase.Invk_renderSnak, args, "abc_en");
}
@Test public void GetEntityStatements__best() {
// wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("Q2").Add_claims(wdata_fxt.Make_claim_string(3, "P3_val")).Xto_wdoc());
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2")
.Add_claims
( wdata_fxt.Make_claim_string(3, "P3_val").Rank_tid_(Wbase_claim_rank_.Tid__preferred)
).Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntityStatements, Object_.Ary("q2", "P3", "best"), String_.Concat_lines_nl_skip_last
( "1="
, " 1="
, " id=P3"
, " mainsnak="
, " datavalue="
, " type=string"
, " value=P3_val"
, " property=P3"
, " snaktype=value"
, " datatype=string"
, " rank=preferred"
, " type=statement"
));
}
@Test public void GetEntityUrl() {
fxt.Test_scrib_proc_str(lib, Scrib_lib_wikibase.Invk_getEntityUrl, Object_.Ary("Q2" ), "https://www.wikidata.org/wiki/Special:EntityPage/Q2");
}

@ -13,10 +13,10 @@ 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.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
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.*;
public class Scrib_lib_wikibase_entity_tst {
public class Entity__tst {
@Before public void init() {
fxt.Clear_for_lib();
lib = fxt.Core().Lib_wikibase_entity().Init();

@ -0,0 +1,81 @@
/*
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.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.*;
public class GetEntityStatements__tst {
private final Scrib_invoke_func_fxt fxt = new Scrib_invoke_func_fxt();
private final Wdata_wiki_mgr_fxt wdata_fxt = new Wdata_wiki_mgr_fxt();
private Scrib_lib lib;
@Before public void init() {
fxt.Clear_for_invoke();
lib = fxt.Core().Lib_wikibase().Init();
wdata_fxt.Init(fxt.Parser_fxt(), false);
}
@Test public void Get_preferred() {
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2")
.Add_claims
( wdata_fxt.Make_claim_string(3, "3c").Rank_tid_(Wbase_claim_rank_.Tid__deprecated)
, wdata_fxt.Make_claim_string(3, "3b").Rank_tid_(Wbase_claim_rank_.Tid__normal)
, wdata_fxt.Make_claim_string(3, "3a").Rank_tid_(Wbase_claim_rank_.Tid__preferred)
).Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntityStatements, Object_.Ary("q2", "P3", "best"), String_.Concat_lines_nl_skip_last
( "1="
, " P3="
, " 1="
, " id=P3"
, " mainsnak="
, " datavalue="
, " type=string"
, " value=3a"
, " property=P3"
, " snaktype=value"
, " datatype=string"
, " rank=preferred"
, " type=statement"
));
}
@Test public void Get_normal_when_no_preferred() {
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2")
.Add_claims
( wdata_fxt.Make_claim_string(3, "3c").Rank_tid_(Wbase_claim_rank_.Tid__deprecated)
, wdata_fxt.Make_claim_string(3, "3b").Rank_tid_(Wbase_claim_rank_.Tid__normal)
).Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntityStatements, Object_.Ary("q2", "P3", "best"), String_.Concat_lines_nl_skip_last
( "1="
, " P3="
, " 1="
, " id=P3"
, " mainsnak="
, " datavalue="
, " type=string"
, " value=3b"
, " property=P3"
, " snaktype=value"
, " datatype=string"
, " rank=normal"
, " type=statement"
));
}
@Test public void Never_get_deprecated() {
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2")
.Add_claims
( wdata_fxt.Make_claim_string(3, "3c").Rank_tid_(Wbase_claim_rank_.Tid__deprecated)
).Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntityStatements, Object_.Ary("q2", "P3", "best"), String_.Concat_lines_nl_skip_last
("1=<<NULL>>"));
}
}

@ -0,0 +1,82 @@
/*
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.wikibases; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*; import gplx.xowa.xtns.scribunto.libs.*;
import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.stores.*; import gplx.xowa.xtns.wbases.claims.itms.*;
public class Srl__fxt {
private Wdata_doc_bldr wdoc_bldr;
private Wbase_prop_mgr prop_mgr;
public void Clear() {
wdata_fxt = new Wdata_wiki_mgr_fxt();
wdata_fxt.Init();
wdoc_bldr = wdata_fxt.Wdoc_bldr("q2");
header_enabled = false;
this.prop_mgr = wdata_fxt.App().Wiki_mgr().Wdata_mgr().Prop_mgr();
}
public Wdata_wiki_mgr_fxt Wdata_fxt() {return wdata_fxt;} private Wdata_wiki_mgr_fxt wdata_fxt;
private boolean header_enabled;
public Srl__fxt Init_header_enabled_y_() {header_enabled = true; return this;}
public Srl__fxt Init_label(String lang, String label) {
wdoc_bldr.Add_label(lang, label);
return this;
}
public Srl__fxt Init_description(String lang, String description) {
wdoc_bldr.Add_description(lang, description);
return this;
}
public Srl__fxt Init_link(String xwiki, String val) {
wdoc_bldr.Add_sitelink(xwiki, val);
return this;
}
public Srl__fxt Init_alias(String lang, String... ary) {
wdoc_bldr.Add_alias(lang, ary);
return this;
}
public Srl__fxt Init_prop(Wbase_claim_base prop) {wdoc_bldr.Add_claims(prop); return this;}
public Srl__fxt Test(String... expd) {return Test(false, expd);}
public Srl__fxt Test(boolean base0, String... expd) {
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc_bldr.Xto_wdoc(), header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
public Srl__fxt Test(Wdata_doc wdoc, String... expd) {return Test(false, wdoc, expd);}
public Srl__fxt Test(boolean base0, Wdata_doc wdoc, String... expd) {
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc, header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
private String Xto_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr_.New();
Xto_str(bfr, ary, 0);
return bfr.To_str_and_clear();
}
private void Xto_str(Bry_bfr bfr, Keyval[] ary, int depth) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Keyval kv = ary[i];
Xto_str(bfr, kv, depth);
}
}
private void Xto_str(Bry_bfr bfr, Keyval kv, int depth) {
bfr.Add_byte_repeat(Byte_ascii.Space, depth * 2);
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
Object kv_val = kv.Val();
if (kv_val == null) {bfr.Add_str_a7("null").Add_byte_nl(); return;}
Class<?> kv_val_cls = kv_val.getClass();
if (Type_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval[])kv_val, depth + 1);}
else if (Type_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval)kv_val, depth + 1);}
else bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(Object_.Xto_str_strict_or_empty(kv_val)).Add_byte(Byte_ascii.Apos).Add_byte_nl();
}
}

@ -13,11 +13,11 @@ 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.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
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.core.tests.*;
import gplx.langs.jsons.*; 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.parsers.*; import gplx.xowa.xtns.wbases.stores.*;
public class Scrib_lib_wikibase_srl_tst {
@Before public void init() {fxt.Clear();} private Scrib_lib_wikibase_srl_fxt fxt = new Scrib_lib_wikibase_srl_fxt();
public class Srl__tst {
@Before public void init() {fxt.Clear();} private Srl__fxt fxt = new Srl__fxt();
@Test public void Label() {
fxt.Init_label("en", "Earth").Init_label("fr", "Terre").Init_label("de", "Erde");
fxt.Test
@ -419,68 +419,3 @@ public class Scrib_lib_wikibase_srl_tst {
Gftest.Eq__int(456, (int)keyval.Val()); // NOTE: must be 456 not "456"
}
}
class Scrib_lib_wikibase_srl_fxt {
private Wdata_doc_bldr wdoc_bldr;
private Wbase_prop_mgr prop_mgr;
public void Clear() {
wdata_fxt = new Wdata_wiki_mgr_fxt();
wdata_fxt.Init();
wdoc_bldr = wdata_fxt.Wdoc_bldr("q2");
header_enabled = false;
this.prop_mgr = wdata_fxt.App().Wiki_mgr().Wdata_mgr().Prop_mgr();
}
public Wdata_wiki_mgr_fxt Wdata_fxt() {return wdata_fxt;} private Wdata_wiki_mgr_fxt wdata_fxt;
private boolean header_enabled;
public Scrib_lib_wikibase_srl_fxt Init_header_enabled_y_() {header_enabled = true; return this;}
public Scrib_lib_wikibase_srl_fxt Init_label(String lang, String label) {
wdoc_bldr.Add_label(lang, label);
return this;
}
public Scrib_lib_wikibase_srl_fxt Init_description(String lang, String description) {
wdoc_bldr.Add_description(lang, description);
return this;
}
public Scrib_lib_wikibase_srl_fxt Init_link(String xwiki, String val) {
wdoc_bldr.Add_sitelink(xwiki, val);
return this;
}
public Scrib_lib_wikibase_srl_fxt Init_alias(String lang, String... ary) {
wdoc_bldr.Add_alias(lang, ary);
return this;
}
public Scrib_lib_wikibase_srl_fxt Init_prop(Wbase_claim_base prop) {wdoc_bldr.Add_claims(prop); return this;}
public Scrib_lib_wikibase_srl_fxt Test(String... expd) {return Test(false, expd);}
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, String... expd) {
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc_bldr.Xto_wdoc(), header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
public Scrib_lib_wikibase_srl_fxt Test(Wdata_doc wdoc, String... expd) {return Test(false, wdoc, expd);}
public Scrib_lib_wikibase_srl_fxt Test(boolean base0, Wdata_doc wdoc, String... expd) {
Keyval[] actl = Scrib_lib_wikibase_srl.Srl(prop_mgr, wdoc, header_enabled, base0);
Tfds.Eq_ary_str(expd, String_.SplitLines_nl(Xto_str(actl)));
return this;
}
private String Xto_str(Keyval[] ary) {
Bry_bfr bfr = Bry_bfr_.New();
Xto_str(bfr, ary, 0);
return bfr.To_str_and_clear();
}
private void Xto_str(Bry_bfr bfr, Keyval[] ary, int depth) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Keyval kv = ary[i];
Xto_str(bfr, kv, depth);
}
}
private void Xto_str(Bry_bfr bfr, Keyval kv, int depth) {
bfr.Add_byte_repeat(Byte_ascii.Space, depth * 2);
bfr.Add_str_u8(kv.Key()).Add_byte(Byte_ascii.Colon);
Object kv_val = kv.Val();
if (kv_val == null) {bfr.Add_str_a7("null").Add_byte_nl(); return;}
Class<?> kv_val_cls = kv_val.getClass();
if (Type_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval[])kv_val, depth + 1);}
else if (Type_.Eq(kv_val_cls, Keyval[].class)) {bfr.Add_byte_nl(); Xto_str(bfr, (Keyval)kv_val, depth + 1);}
else bfr.Add_byte(Byte_ascii.Apos).Add_str_u8(Object_.Xto_str_strict_or_empty(kv_val)).Add_byte(Byte_ascii.Apos).Add_byte_nl();
}
}

@ -55,19 +55,31 @@ public class Wbase_entity_accessor {
Wbase_claim_grp statements = entity.Claim_list_get(propertyId);
if (statements == null)
return null;
int statements_len = statements.Len();
for (int i = 0; i < statements_len; i++) {
Wbase_claim_base statement = statements.Get_at(0);
Wbase_claim_base statement = statements.Get_at(i);
if ( selected_rank == ID_ALL
|| (selected_rank == ID_BEST && statement.Rank_tid() == Wbase_claim_rank_.Tid__preferred)
) {
rv.Add(statement);
}
}
// no preferred exists; add normal
if (rv.Len() == 0 && selected_rank == ID_BEST) {
for (int i = 0; i < statements_len; i++) {
Wbase_claim_base statement = statements.Get_at(i);
if (statement.Rank_tid() == Wbase_claim_rank_.Tid__normal) {
rv.Add(statement);
}
}
}
// $serialization = $this->newClientStatementListSerializer()->serialize( $statements );
// $this->renumber( $serialization );
// return $serialization;
return (Wbase_claim_base[])rv.To_ary(Wbase_claim_base.class);
return rv.Len() == 0 ? null : (Wbase_claim_base[])rv.To_ary(Wbase_claim_base.class);
}
private static final int ID_NULL = 0, ID_BEST = 1, ID_ALL = 2;

Loading…
Cancel
Save