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
+21 -20
View File
@@ -145,34 +145,35 @@ class nwFiles:
class nwKeyWords: class nwKeyWords:
TAG_KEY = "@tag" TAG_KEY = "@tag"
POV_KEY = "@pov" POV_KEY = "@pov"
FOCUS_KEY = "@focus" FOCUS_KEY = "@focus"
CHAR_KEY = "@char" CHAR_KEY = "@char"
PLOT_KEY = "@plot" PLOT_KEY = "@plot"
TIME_KEY = "@time" TIME_KEY = "@time"
WORLD_KEY = "@location" WORLD_KEY = "@location"
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
KEY_CLASS = { KEY_CLASS = {
POV_KEY: nwItemClass.CHARACTER, POV_KEY: nwItemClass.CHARACTER,
FOCUS_KEY: nwItemClass.CHARACTER, FOCUS_KEY: nwItemClass.CHARACTER,
CHAR_KEY: nwItemClass.CHARACTER, CHAR_KEY: nwItemClass.CHARACTER,
PLOT_KEY: nwItemClass.PLOT, PLOT_KEY: nwItemClass.PLOT,
TIME_KEY: nwItemClass.TIMELINE, TIME_KEY: nwItemClass.TIMELINE,
WORLD_KEY: nwItemClass.WORLD, WORLD_KEY: nwItemClass.WORLD,
OBJECT_KEY: nwItemClass.OBJECT, OBJECT_KEY: nwItemClass.OBJECT,
ENTITY_KEY: nwItemClass.ENTITY, ENTITY_KEY: nwItemClass.ENTITY,
CUSTOM_KEY: nwItemClass.CUSTOM, CUSTOM_KEY: nwItemClass.CUSTOM,
} }
+12 -7
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