Add mention keyword

This commit is contained in:
Veronica Berglyd Olsen
2024-10-24 23:53:48 +02:00
parent 41e5152771
commit 9214da3756
2 changed files with 33 additions and 27 deletions
+2 -1
View File
@@ -155,11 +155,12 @@ class nwKeyWords:
OBJECT_KEY = "@object" OBJECT_KEY = "@object"
ENTITY_KEY = "@entity" ENTITY_KEY = "@entity"
CUSTOM_KEY = "@custom" CUSTOM_KEY = "@custom"
MENTION_KEY = "@mention"
# Set of Valid Keys # Set of Valid Keys
VALID_KEYS = { VALID_KEYS = {
TAG_KEY, POV_KEY, FOCUS_KEY, CHAR_KEY, PLOT_KEY, TIME_KEY, TAG_KEY, POV_KEY, FOCUS_KEY, CHAR_KEY, PLOT_KEY, TIME_KEY,
WORLD_KEY, OBJECT_KEY, ENTITY_KEY, CUSTOM_KEY WORLD_KEY, OBJECT_KEY, ENTITY_KEY, CUSTOM_KEY, MENTION_KEY
} }
# Map from Keys to Item Class # Map from Keys to Item Class
+10 -5
View File
@@ -487,13 +487,14 @@ class NWIndex:
if nBits == 0: if nBits == 0:
return [] return []
# Check that the key is valid # Check that the keyword is valid
isGood[0] = tBits[0] in nwKeyWords.VALID_KEYS kBit = tBits[0]
isGood[0] = kBit in nwKeyWords.VALID_KEYS
if not isGood[0] or nBits == 1: if not isGood[0] or nBits == 1:
return isGood return isGood
# For a tag, only the first value is accepted, the rest are ignored # For a tag, only the first value is accepted, the rest are ignored
if tBits[0] == nwKeyWords.TAG_KEY and nBits > 1: if kBit == nwKeyWords.TAG_KEY and nBits > 1:
check, _ = self.parseValue(tBits[1]) check, _ = self.parseValue(tBits[1])
if check in self._tagsIndex: if check in self._tagsIndex:
isGood[1] = self._tagsIndex.tagHandle(check) == tHandle isGood[1] = self._tagsIndex.tagHandle(check) == tHandle
@@ -501,12 +502,16 @@ class NWIndex:
isGood[1] = True isGood[1] = True
return isGood return isGood
if kBit == nwKeyWords.MENTION_KEY and nBits > 1:
isGood[1:nBits] = [aBit in self._tagsIndex for aBit in tBits[1:nBits]]
return isGood
# If we're still here, we check that the references exist # If we're still here, we check that the references exist
# Class references cannot have the | symbol in them # Class references cannot have the | symbol in them
refKey = nwKeyWords.KEY_CLASS[tBits[0]].name if rClass := nwKeyWords.KEY_CLASS.get(kBit):
for n in range(1, nBits): for n in range(1, nBits):
if (aBit := tBits[n]) in self._tagsIndex: if (aBit := tBits[n]) in self._tagsIndex:
isGood[n] = self._tagsIndex.tagClass(aBit) == refKey and "|" not in aBit isGood[n] = self._tagsIndex.tagClass(aBit) == rClass.name and "|" not in aBit
return isGood return isGood