@py3compat.format_doctest_out
    def preferredLabel(self, subject, lang=None, default=None,
                       labelProperties=(SKOS.prefLabel, RDFS.label)):
        """
        Find the preferred label for subject.

        By default prefers skos:prefLabels over rdfs:labels. In case at least
        one prefLabel is found returns those, else returns labels. In case a
        language string (e.g., 'en', 'de' or even '' for no lang-tagged
        literals) is given, only such labels will be considered.

        Return a list of (labelProp, label) pairs, where labelProp is either
        skos:prefLabel or rdfs:label.

        >>> from rdflib import ConjunctiveGraph, URIRef, RDFS, Literal
        >>> from rdflib.namespace import SKOS
        >>> from pprint import pprint
        >>> g = ConjunctiveGraph()
        >>> u = URIRef(%(u)s'http://example.com/foo')
        >>> g.add([u, RDFS.label, Literal('foo')])
        >>> g.add([u, RDFS.label, Literal('bar')])
        >>> pprint(sorted(g.preferredLabel(u)))
        [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'),
          rdflib.term.Literal(%(u)s'bar')),
         (rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'),
          rdflib.term.Literal(%(u)s'foo'))]
        >>> g.add([u, SKOS.prefLabel, Literal('bla')])
        >>> pprint(g.preferredLabel(u))
        [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
          rdflib.term.Literal(%(u)s'bla'))]
        >>> g.add([u, SKOS.prefLabel, Literal('blubb', lang='en')])
        >>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE
        [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
          rdflib.term.Literal(%(u)s'bla')),
          (rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
          rdflib.term.Literal(%(u)s'blubb', lang='en'))]
        >>> g.preferredLabel(u, lang='') #doctest: +NORMALIZE_WHITESPACE
        [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
          rdflib.term.Literal(%(u)s'bla'))]
        >>> pprint(g.preferredLabel(u, lang='en'))
        [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'),
          rdflib.term.Literal(%(u)s'blubb', lang='en'))]
        """

        if default is None:
            default = []

        # setup the language filtering
        if lang is not None:
            if lang == '':  # we only want not language-tagged literals
                langfilter = lambda l: l.language is None
            else:
                langfilter = lambda l: l.language == lang
        else:  # we don't care about language tags
            langfilter = lambda l: True

        for labelProp in labelProperties:
            labels = filter(langfilter, self.objects(subject, labelProp))
            if len(labels) == 0:
                continue
            else:
                return [(labelProp, l) for l in labels]
        return default
dataset/ETHPy150Open RDFLib/rdflib/rdflib/graph.py/Graph.preferredLabel/original