Closed VladimirAlexiev closed 3 years ago
I disagree that this API should return unique results. I think both approaches have useful applications.
I thought for sure I had made a uniq
method public on iterators, but I can't seem to find it. Would having a uniq
method available be a reasonable compromise?
$model->subjects($pred, \@objects)->uniq->elements
As an aside, @VladimirAlexiev , you shouldn't need to define your own iri
and IRI
functions. There's now an AtteanIRI
type in Types::Attean
. Conventionally, these types has a function to convert by prepending with to_
.
So you should be able to do just:
use Types::Attean qw( to_AtteanIRI );
and then you should be able to use the to_AtteanIRI
function for both these conversions and many more.
@kasei Agree with adding uniq
to iterator.
$model->subjects($pred, \@objects)->elements->uniq
i.e. you first "materialize" as list and then uniquify?$model->subjects($pred, \@objects)
alone may return duplicates.
elements
and uniq
require materializing the iterator as array, which may be expensive on a large result set, and makes sense if you want to process the whole result set, and are not just searching for something at the beginning of the result set@VladimirAlexiev sorry for the delay in responding. I'm going to release a new version soon with a uniq
method on many iterator types, and include a note in the documentation for subjects
, predicates
, objects
, and graphs
indicating that their results are not necessarily unique.
$model->subjects($pred, \@objects)->elements->uniq
would not be right, as elements
materializes the iterator and returns a list. So uniq
would have to come before elements
.
Attean 0.028 (just released to CPAN) contains the discussed documentation and code changes.
https://metacpan.org/pod/release/GWILLIAMS/Attean-0.026/lib/Attean/API/Model.pm describes methods for returning the subjects, predicates, objects that match a certain pattern.
undef (no constraint) and array of terms (disjunction) are allowed in the pattern. In that case it's very possible that multiple triples will match the pattern; Attean returns the same result multiple times, but should return it only once.
Test case: I'm converting the SKOS ontology to something else.
However, SKOS props are defined with two types, eg
I get each of them twice although I expect to get it once.
Workaround:
List::MoreUtils qw(uniq)