.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.wikidata.WDURLAttribute Class Reference
Inheritance diagram for searx.engines.wikidata.WDURLAttribute:
Collaboration diagram for searx.engines.wikidata.WDURLAttribute:

Public Member Functions

 __init__ (self, name, url_id=None, url_path_prefix=None, kwargs=None)
 get_str (self, result, language)
Public Member Functions inherited from searx.engines.wikidata.WDAttribute
 __init__ (self, name)
 get_select (self)
 get_label (self, language)
 get_where (self)
 get_wikibase_label (self)
 get_group_by (self)
 __repr__ (self)

Public Attributes

 url_id = url_id
 url_path_prefix = url_path_prefix
 kwargs = kwargs
Public Attributes inherited from searx.engines.wikidata.WDAttribute
 name = name

Static Public Attributes

str HTTP_WIKIMEDIA_IMAGE = 'http://commons.wikimedia.org/wiki/Special:FilePath/'

Static Private Attributes

str __slots__ = 'url_id', 'url_path_prefix', 'kwargs'

Detailed Description

Definition at line 591 of file wikidata.py.

Constructor & Destructor Documentation

◆ __init__()

searx.engines.wikidata.WDURLAttribute.__init__ ( self,
name,
url_id = None,
url_path_prefix = None,
kwargs = None )
:param url_id: ID matching one key in ``external_urls.json`` for
    converting IDs to full URLs.

:param url_path_prefix: Path prefix if the values are of format
    ``account@domain``.  If provided, value are rewritten to
    ``https://<domain><url_path_prefix><account>``.  For example::

      WDURLAttribute('P4033', url_path_prefix='/@')

    Adds Property `P4033 <https://www.wikidata.org/wiki/Property:P4033>`_
    to the wikidata query.  This field might return for example
    ``libreoffice@fosstodon.org`` and the URL built from this is then:

    - account: ``libreoffice``
    - domain: ``fosstodon.org``
    - result url: https://fosstodon.org/@libreoffice

Definition at line 597 of file wikidata.py.

597 def __init__(self, name, url_id=None, url_path_prefix=None, kwargs=None):
598 """
599 :param url_id: ID matching one key in ``external_urls.json`` for
600 converting IDs to full URLs.
601
602 :param url_path_prefix: Path prefix if the values are of format
603 ``account@domain``. If provided, value are rewritten to
604 ``https://<domain><url_path_prefix><account>``. For example::
605
606 WDURLAttribute('P4033', url_path_prefix='/@')
607
608 Adds Property `P4033 <https://www.wikidata.org/wiki/Property:P4033>`_
609 to the wikidata query. This field might return for example
610 ``libreoffice@fosstodon.org`` and the URL built from this is then:
611
612 - account: ``libreoffice``
613 - domain: ``fosstodon.org``
614 - result url: https://fosstodon.org/@libreoffice
615 """
616
617 super().__init__(name)
618 self.url_id = url_id
619 self.url_path_prefix = url_path_prefix
620 self.kwargs = kwargs
621

References __init__().

Referenced by __init__().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ get_str()

searx.engines.wikidata.WDURLAttribute.get_str ( self,
result,
language )

Reimplemented from searx.engines.wikidata.WDAttribute.

Definition at line 622 of file wikidata.py.

622 def get_str(self, result, language):
623 value = result.get(self.name + 's')
624 if not value:
625 return None
626
627 value = value.split(',')[0]
628 if self.url_id:
629 url_id = self.url_id
630 if value.startswith(WDURLAttribute.HTTP_WIKIMEDIA_IMAGE):
631 value = value[len(WDURLAttribute.HTTP_WIKIMEDIA_IMAGE) :]
632 url_id = 'wikimedia_image'
633 return get_external_url(url_id, value)
634
635 if self.url_path_prefix:
636 [account, domain] = [x.strip("@ ") for x in value.rsplit('@', 1)]
637 return f"https://{domain}{self.url_path_prefix}{account}"
638
639 return value
640
641

References searx.engines.wikidata.WDAttribute.name, url_id, and url_path_prefix.

Member Data Documentation

◆ __slots__

str searx.engines.wikidata.WDURLAttribute.__slots__ = 'url_id', 'url_path_prefix', 'kwargs'
staticprivate

Definition at line 595 of file wikidata.py.

◆ HTTP_WIKIMEDIA_IMAGE

str searx.engines.wikidata.WDURLAttribute.HTTP_WIKIMEDIA_IMAGE = 'http://commons.wikimedia.org/wiki/Special:FilePath/'
static

Definition at line 593 of file wikidata.py.

◆ kwargs

searx.engines.wikidata.WDURLAttribute.kwargs = kwargs

Definition at line 620 of file wikidata.py.

◆ url_id

searx.engines.wikidata.WDURLAttribute.url_id = url_id

Definition at line 618 of file wikidata.py.

Referenced by get_str().

◆ url_path_prefix

searx.engines.wikidata.WDURLAttribute.url_path_prefix = url_path_prefix

Definition at line 619 of file wikidata.py.

Referenced by get_str().


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/engines/wikidata.py