Skip to content

Commit 46ea8ea

Browse files
Add option to keep/remove empty claims
1 parent 7805690 commit 46ea8ea

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/Textifier/WikidataTextifier.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class WikidataEntity:
113113
def __bool__(self) -> bool:
114114
return bool(self.id) and self.label is not None and str(self.label) != ""
115115

116-
def to_text(self, lang='en') -> str:
116+
def to_text(self, lang='en', keep_empty: bool = False) -> str:
117117
lang_var = LANGUAGE_VARIABLES.get(lang, LANGUAGE_VARIABLES.get('en'))
118118

119119
label_str = str(self.label) if self.label else '<missing>'
@@ -125,7 +125,9 @@ def to_text(self, lang='en') -> str:
125125
string += f"{lang_var[', ']}{lang_var['also known as']}"
126126
string += f" {lang_var[', '].join(map(str, self.aliases))}"
127127

128-
attributes = [c.to_text(lang) for c in self.claims if c]
128+
attributes = [c.to_text(lang, keep_empty=keep_empty) \
129+
for c in self.claims \
130+
if keep_empty or c]
129131
if len(attributes) > 0:
130132
attributes = "\n- ".join(attributes)
131133
string += f". {lang_var['Attributes include']}:\n- {attributes}"
@@ -178,9 +180,6 @@ def __bool__(self) -> bool:
178180
def to_text(self, lang='en') -> str:
179181
lang_var = LANGUAGE_VARIABLES.get(lang, LANGUAGE_VARIABLES.get('en'))
180182

181-
if not self:
182-
return ""
183-
184183
if self.values:
185184
values = lang_var[', '].join(v.to_text(lang) for v in self.values if v)
186185
return f"{str(self.property.label)}: {values}"

0 commit comments

Comments
 (0)