Create indexing.py
Browse files- indexing.py +30 -0
indexing.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
def word_index_multiple_mmr(text):
|
| 6 |
+
words = ["no", "not", "normal", "intact", "deficient", "mmr", "mismatch"]
|
| 7 |
+
word_indices = {word: [] for word in words}
|
| 8 |
+
current_index = 0
|
| 9 |
+
|
| 10 |
+
for word in text.split():
|
| 11 |
+
word_lower = word.lower()
|
| 12 |
+
if word_lower in words:
|
| 13 |
+
word_indices[word_lower].append(current_index)
|
| 14 |
+
current_index += 1
|
| 15 |
+
|
| 16 |
+
mmr_indices = word_indices["mmr"]
|
| 17 |
+
for word, indices in word_indices.items():
|
| 18 |
+
if word != "mmr":
|
| 19 |
+
for i, index in enumerate(indices):
|
| 20 |
+
if i < len(mmr_indices) and index < mmr_indices[i]:
|
| 21 |
+
indices[i] = -index
|
| 22 |
+
|
| 23 |
+
return word_indices
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Example usage
|
| 27 |
+
text = """PMS-2 Positive Tumors displaying loss of any MMR protein are mismatch repair deficient and considered to be MSI-High (MSI-H), whereas those with intact MMR proteins are expected to be microsatellite stable (MSS) or MSI-low (MSI-L). $$ IHC shows normal expression of MLH-1, MSH-2, MSH-6, and PMS-2. $$ The results of the IC analysis suggest the presence of normal DNA mismatch $$ Positive MSH-6. Another MMR protein is also involved."""
|
| 28 |
+
|
| 29 |
+
result = word_index_multiple_mmr(text)
|
| 30 |
+
print(result)
|