Change terminology to be less ambiguous

merge-requests/30/head
Bob Mottram 2021-07-24 15:43:52 +01:00
parent 84bcc6d103
commit f1d42b62db
1 changed files with 12 additions and 13 deletions

View File

@ -26,7 +26,7 @@ from utils import acctDir
from media import processMetaData from media import processMetaData
def _loadProductIds(baseDir: str, systemLanguage: str) -> {}: def _loadDfcIds(baseDir: str, systemLanguage: str) -> {}:
"""Loads the product types ontology """Loads the product types ontology
This is used to add an id to shared items This is used to add an id to shared items
""" """
@ -54,7 +54,7 @@ def _loadProductIds(baseDir: str, systemLanguage: str) -> {}:
print('productTypes ontology does not contain the language ' + print('productTypes ontology does not contain the language ' +
systemLanguage) systemLanguage)
return None return None
productIds = {} dfcIds = {}
for item in productTypes['@graph']: for item in productTypes['@graph']:
if not item.get('@id'): if not item.get('@id'):
continue continue
@ -66,9 +66,9 @@ def _loadProductIds(baseDir: str, systemLanguage: str) -> {}:
if not label.get('@value'): if not label.get('@value'):
continue continue
if label['@language'] == systemLanguage: if label['@language'] == systemLanguage:
productIds[label['@value'].lower()] = item['@id'] dfcIds[label['@value'].lower()] = item['@id']
break break
return productIds return dfcIds
def getValidSharedItemID(displayName: str) -> str: def getValidSharedItemID(displayName: str) -> str:
@ -139,19 +139,18 @@ def _addShareDurationSec(duration: str, published: str) -> int:
return 0 return 0
def _getshareProductId(baseDir: str, systemLanguage: str, def _getshareDfcId(baseDir: str, systemLanguage: str, itemType: str) -> str:
itemType: str) -> str: """Attempts to obtain a DFC Id for the shared item,
"""Attempts to obtain an Id for the shared item,
based upon productTypes ontology. based upon productTypes ontology.
See https://github.com/datafoodconsortium/ontology See https://github.com/datafoodconsortium/ontology
""" """
productIds = _loadProductIds(baseDir, systemLanguage) dfcIds = _loadDfcIds(baseDir, systemLanguage)
if not productIds: if not dfcIds:
return '' return ''
itemTypeLower = itemType.lower() itemTypeLower = itemType.lower()
matchName = '' matchName = ''
matchId = '' matchId = ''
for name, uri in productIds.items(): for name, uri in dfcIds.items():
if name not in itemTypeLower: if name not in itemTypeLower:
continue continue
if len(name) > len(matchName): if len(name) > len(matchName):
@ -160,7 +159,7 @@ def _getshareProductId(baseDir: str, systemLanguage: str,
if not matchId: if not matchId:
# bag of words match # bag of words match
maxMatchedWords = 0 maxMatchedWords = 0
for name, uri in productIds.items(): for name, uri in dfcIds.items():
words = name.split(' ') words = name.split(' ')
score = 0 score = 0
for wrd in words: for wrd in words:
@ -190,7 +189,7 @@ def addShare(baseDir: str,
durationSec = _addShareDurationSec(duration, published) durationSec = _addShareDurationSec(duration, published)
itemID = getValidSharedItemID(displayName) itemID = getValidSharedItemID(displayName)
productId = _getshareProductId(baseDir, systemLanguage, itemType) dfcId = _getshareDfcId(baseDir, systemLanguage, itemType)
# has an image for this share been uploaded? # has an image for this share been uploaded?
imageUrl = None imageUrl = None
@ -232,7 +231,7 @@ def addShare(baseDir: str,
"summary": summary, "summary": summary,
"imageUrl": imageUrl, "imageUrl": imageUrl,
"itemQty": itemQty, "itemQty": itemQty,
"productId": productId, "dfcId": dfcId,
"itemType": itemType, "itemType": itemType,
"category": itemCategory, "category": itemCategory,
"location": location, "location": location,