Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override max length for individual props #1519

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions followthemoney/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PropertyDict(TypedDict, total=False):
hidden: Optional[bool]
matchable: Optional[bool]
deprecated: Optional[bool]
maxLength: Optional[int]
# stub: Optional[bool]
rdf: Optional[str]
range: Optional[str]
Expand Down Expand Up @@ -58,6 +59,7 @@ class Property:
"type",
"matchable",
"deprecated",
"max_length",
"_range",
"format",
"range",
Expand Down Expand Up @@ -109,6 +111,9 @@ def __init__(self, schema: "Schema", name: str, data: PropertySpec) -> None:
else:
self.matchable = self.type.matchable

#: The maximum length of the property value.
self.max_length = int(data.get("maxLength") or self.type.max_length)

#: If the property is of type ``entity``, the set of valid schema to be added
#: in this property can be constrained. For example, an asset can be owned,
#: but a person cannot be owned.
Expand Down Expand Up @@ -197,6 +202,7 @@ def to_dict(self) -> PropertyToDict:
"qname": self.qname,
"label": self.label,
"type": self.type.name,
"maxLength": self.max_length,
}
if self.description:
data["description"] = self.description
Expand Down
1 change: 1 addition & 0 deletions followthemoney/schema/Address.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Address:
postalCode:
label: "Postal code"
description: "Zip code or postcode."
maxLength: 16
region:
label: "Region"
description: "Also province or area."
Expand Down
3 changes: 3 additions & 0 deletions followthemoney/schema/BankAccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ BankAccount:
accountNumber:
label: Account number
type: identifier
maxLength: 64
iban:
label: IBAN
# type: identifier
# format: iban
type: iban
maxLength: 64
bic:
label: Bank Identifier Code
type: identifier
format: bic
maxLength: 16
bank:
label: Bank
type: entity
Expand Down
3 changes: 3 additions & 0 deletions followthemoney/schema/Company.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Company:
label: "VOEN"
description: "Azerbaijan taxpayer ID"
type: identifier
maxLength: 32
coatoCode:
label: "COATO / SOATO / OKATO"
type: identifier
Expand Down Expand Up @@ -107,6 +108,8 @@ Company:
label: PermID
description: LSEG/Refinitiv code for a company
type: identifier
maxLength: 16
ricCode:
label: Reuters Instrument Code
type: identifier
maxLength: 16
1 change: 1 addition & 0 deletions followthemoney/schema/CryptoWallet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CryptoWallet:
label: Address
description: Public key used to identify the wallet
type: identifier
maxLength: 128
privateKey:
label: Private key
creationDate:
Expand Down
1 change: 1 addition & 0 deletions followthemoney/schema/Identification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ Identification:
number:
label: "Document number"
type: identifier
maxLength: 64
authority:
label: "Authority"
7 changes: 7 additions & 0 deletions followthemoney/schema/LegalEntity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ LegalEntity:
label: "V.A.T. Identifier"
description: "(EU) VAT number"
type: identifier
maxLength: 32
jurisdiction:
label: Jurisdiction
type: country
Expand Down Expand Up @@ -109,30 +110,36 @@ LegalEntity:
description: "Russian company ID"
type: identifier
# format: inn
maxLength: 32
ogrnCode:
label: "OGRN"
description: "Major State Registration Number"
type: identifier
# format: ogrn
maxLength: 32
leiCode:
# cf. https://www.gleif.org/en/about-lei/introducing-the-legal-entity-identifier-lei
label: "LEI"
description: "Legal Entity Identifier"
type: identifier
format: lei
maxLength: 32
dunsCode:
label: "DUNS"
description: "Data Universal Numbering System - Dun & Bradstreet identifier"
type: identifier
maxLength: 32
npiCode:
label: "NPI"
description: "National Provider Identifier"
type: identifier
maxLength: 32
swiftBic:
label: "SWIFT/BIC"
description: "Bank identifier code"
type: identifier
format: bic
maxLength: 16
parent:
label: "Parent company"
description: "If this entity is a subsidiary, another entity (company or organisation) is its parent"
Expand Down
1 change: 1 addition & 0 deletions followthemoney/schema/Sanction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Sanction:
unscId:
label: "UN SC identifier"
type: identifier
maxLength: 16
program:
label: "Program"
provisions:
Expand Down
2 changes: 2 additions & 0 deletions followthemoney/schema/Security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Security:
description: International Securities Identification Number
type: identifier
format: isin
maxLength: 16
registrationNumber:
label: Registration number
type: identifier
Expand All @@ -35,6 +36,7 @@ Security:
label: Financial Instrument Global Identifier
type: identifier
format: figi
maxLength: 16
issuer:
label: "Issuer"
type: entity
Expand Down
1 change: 1 addition & 0 deletions followthemoney/schema/Thing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Thing:
label: Wikidata ID
type: identifier
format: qid
maxLength: 32
keywords:
label: Keywords
topics:
Expand Down
2 changes: 2 additions & 0 deletions followthemoney/schema/Vessel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Vessel:
imoNumber:
label: IMO Number
type: identifier
maxLength: 16
crsNumber:
label: CRS Number
type: identifier
Expand Down Expand Up @@ -50,3 +51,4 @@ Vessel:
mmsi:
label: MMSI
type: identifier
maxLength: 16
4 changes: 2 additions & 2 deletions followthemoney/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PropertyTypeToDict(TypedDict, total=False):
label: str
plural: str
description: Optional[str]
max_length: int
maxLength: int
group: Optional[str]
matchable: Optional[bool]
pivot: Optional[bool]
Expand Down Expand Up @@ -198,7 +198,7 @@ def to_dict(self) -> PropertyTypeToDict:
"label": gettext(self.label),
"plural": gettext(self.plural),
"description": gettext(self.docs),
"max_length": self.max_length,
"maxLength": self.max_length,
}
if self.group:
data["group"] = self.group
Expand Down
6 changes: 5 additions & 1 deletion followthemoney/types/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def compare(self, left: str, right: str) -> float:
right_clean = clean_name_light(right)
if left_clean is None or right_clean is None:
return 0.0
return levenshtein_similarity(left_clean, right_clean)
return levenshtein_similarity(
left_clean,
right_clean,
max_length=self.max_length,
)

def node_id(self, value: str) -> Optional[str]:
slug = slugify(value)
Expand Down
Loading
Loading