Skip to content

Commit

Permalink
Improve keywords
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Corry <[email protected]>
  • Loading branch information
kylecorry31 committed Feb 17, 2025
1 parent afb5c61 commit 2e300ac
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.kylecorry.trail_sense.tools.survival_guide.infrastructure

import android.content.Context
import android.util.Log
import androidx.annotation.IdRes
import com.kylecorry.luna.cache.LRUCache
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.shared.text.TextUtils
import com.kylecorry.trail_sense.tools.survival_guide.domain.Chapter
import com.kylecorry.trail_sense.tools.survival_guide.domain.Chapters
import kotlin.math.max

data class SurvivalGuideSearchResult(
val chapter: Chapter,
Expand Down Expand Up @@ -45,7 +48,32 @@ class SurvivalGuideFuzzySearch(private val context: Context) {
"woods",
"outdoors",
"outdoor",
"got"
"got",
"wild",
"survival",
"situation",
"situations",
"nature",
"natural",
"safe",
"safely",
"safety",
"avoid",
"best",
"tell",
"found",
"common",
"nearby",
"dangerous",
"deadly",
"humans",
"human",
"people",
"use",
"uses",
"used",
"using",
"emergency"
)

// These are words which have nearly the same meaning when searched
Expand Down Expand Up @@ -289,6 +317,16 @@ class SurvivalGuideFuzzySearch(private val context: Context) {
): List<SurvivalGuideSearchResult> {
// TODO: Other languages?

// Log.d(
// "SurvivalGuideFuzzySearch", TextUtils.getKeywords(
// query,
// preservedWords = preservedWords,
// additionalStopWords = additionalStopWords,
// additionalContractions = additionalContractions,
// additionalStemWords = additionalStemWords
// ).joinToString(", ")
// )

val sections = loadChapter(chapter).sections

val matches = mutableListOf<SurvivalGuideSearchResult>()
Expand Down Expand Up @@ -317,16 +355,32 @@ class SurvivalGuideFuzzySearch(private val context: Context) {
additionalStemWords = additionalStemWords
)

val headerMatch = TextUtils.getQueryMatchPercent(
query,
section.title ?: context.getString(R.string.overview),
preservedWords = preservedWords + additionalPreservedWords,
additionalStopWords = additionalStopWords,
synonyms = synonyms + additionalSynonyms,
additionalContractions = additionalContractions,
additionalStemWords = additionalStemWords
)

// If the user exactly matched the header, they probably want to see that
val score = if (headerMatch == 1f) {
1.1f
} else {
max(sectionMatch, headerMatch)
}

matches.add(
SurvivalGuideSearchResult(
chapter,
sectionMatch,
score,
index,
section.title,
section.summary
)
)

}

return matches
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/raw/guide_survival_chapter_crafting.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ Stop cuts are used to prevent wood from splitting when you are cutting it. To ma
Batoning is the process of using a knife to split wood. To baton wood, place the knife on the wood where you want to split it and hit the back of the knife with a piece of wood. Be sure to use a knife with a full tang and a fixed blade.

## Sharpening
%% K: sharpen, tool, knife, axe, blade, repair %%
%% K: sharpen, rock, tool, knife, axe, blade, repair %%
%% S: Use a smooth rock to sharpen your tools. %%

If you find a smooth rock, you can use it to sharpen your knife or axe. Preferably the rock will be small enough to hold in your hand. To sharpen your tool, rub the rock in a circular motion along the edge of the blade. Be sure to match the angle of the blade when sharpening.

## Knives
%% K: knife, flint, chert, obsidian, cut, blade %%
%% K: knife, rock, flint, chert, obsidian, cut, blade %%
%% S: You can craft a knife from bone or certain types of rock. %%

### Bone knife
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/raw/guide_survival_chapter_fire.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% K: fire, flame, light, heat, warm %%
%% K: fire, flame, light, heat, warm, burn %%
%% S: In a survival situation, make a tepee fire if you have a fire starter and gather plenty of wood. Otherwise, focus on insulating your clothes and shelter. %%

This chapter covers how to make a fire in a survival situation.
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/raw/guide_survival_chapter_food.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% K: food, eat, meal, hunger, hungry, forage %%
%% K: food, eat, meal, hunger, hungry, forage, identify, edible, inedible %%
%% S: In a survival situation, ration out the food you have and only forage (plants, insects, shellfish) as a last resort. %%

This chapter covers how to find and prepare food in a survival situation.
Expand Down Expand Up @@ -69,7 +69,7 @@ Starvation occurs when the body does not receive enough nutrients to function pr
- Longer healing time for wounds and illnesses.

## Plants and mushrooms
%% K: plant, mushroom, forage, edible, inedible, poison, toxic, identify, leach, test %%
%% K: plant, mushroom, seaweed, weeds, green, sap, fungus, forage, poison, toxic, leach, test, berries %%
%% S: Only eat plants you can confidently identity as safe and don't eat any mushrooms. Aggregate berries, like raspberries and blackberries, are generally safe. %%

The safest method for consuming wild plants is through positive identification. Before your trip, it's wise to study local plants through guidebooks or plant identification cards.
Expand Down Expand Up @@ -164,7 +164,7 @@ Cook all insects using any of the cooking techniques in this chapter.
Worms can be placed in water for 15 minutes to purge their digestive tracts. After purging, they should be cooked before eating.

## Shellfish and crustaceans
%% K: shellfish, crustacean, clam, mussel, snail, limpet, crayfish, lobster, crab, shrimp, shell, bait, basket, trap, seafood %%
%% K: shellfish, crustacean, clam, mussel, snail, limpet, crayfish, lobster, crab, shrimp, shell, bait, basket, trap, seafood, algae, tide, coastal, coast %%
%% S: Many shellfish and crustaceans are found along the shoreline and most can be eaten when cooked. %%

Shellfish and crustaceans are a good source of protein and can be found in both freshwater and saltwater. They are relatively easy to catch, so they make a good survival food source.
Expand Down Expand Up @@ -263,7 +263,7 @@ Alternatively, use a funnel fish trap by placing sticks into a V-shape with a re
5. Cook the fish.

## Other animals
%% K: animal, hunt, bow, trap, snare, deadfall, bird, reptile, amphibian, frog, snake, mammal, skin, kill, meat %%
%% K: animal, hunt, bow, trap, snare, deadfall, bird, reptile, amphibian, frog, snake, mammal, skin, kill, meat, butcher, skin %%
%% S: Hunting or trapping can be energy consuming and difficult without proper tools. %%

In a survival situation, it's best to focus on easier-to-catch animals like insects, shellfish, crustaceans, and fish. But if you have the means to catch other animals, they can provide a good source of protein and nutrients.
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/raw/guide_survival_chapter_medical.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% K: medicine, medical, heal, health, injury, sick, ill, first-aid %%
%% K: medicine, medical, heal, health, injury, sick, ill, first-aid, symptom, treat, prevent %%
%% S: In a survival situation, minor medical issues can become life threatening. Try to stay calm and treat issues to the best of your ability and call for help if needed/possible. %%

This chapter covers some basic medical knowledge and techniques for common injuries and illnesses you may encounter in the wilderness. It is not a substitute for professional medical advice/treatment or in depth first aid guides.
Expand Down Expand Up @@ -308,7 +308,7 @@ If the blister is large or painful:
- Apply adhesive tape or moleskin to prevent blisters.

## Burns
%% K: burn, scald, blister, red, pain, aloe, vera, fire %%
%% K: burn, scald, blister, red, pain, aloe, vera, fire, skin %%
%% S: Treat minor burns by soaking with cool water and loosly bandage. Seek medical attention for severe burns. Prevent by using caution around fires and hot objects. %%

### Treatment
Expand Down Expand Up @@ -666,7 +666,7 @@ Heatstroke:
- Do not overexert yourself.

## Hygiene
%% K: hygiene, clean, wash, soap, sanitize, toothbrush, teeth, tooth, toothpaste, brush, feet, socks, dry, clothes, defecate, urinate, bathroom, trowel %%
%% K: hygiene, clean, wash, soap, shampoo, sanitize, toothbrush, teeth, tooth, toothpaste, brush, feet, socks, dry, clothes, defecate, urinate, bathroom, trowel %%
%% S: Wash hands frequently, especially before eating and after using the bathroom. %%

### Washing
Expand Down Expand Up @@ -779,7 +779,7 @@ While in the wilderness it is common to get objects in your eye, such as dirt, s
- Ensure yourself that you will be okay.

## Poison ivy and contact dermatitis
%% K: poison, ivy, oak, sumac, trumpet, rengas, stinging, nettle, rash, itch, blister, burn, red, swell, dermatitis, contact %%
%% K: poison, ivy, oak, sumac, trumpet, rengas, stinging, nettle, rash, itch, blister, red, swell, dermatitis, contact %%
%% S: Symptoms include a rash, itching, and blisters. Treat by washing the area with soap and water, applying calamine lotion, and taking antihistamines. Prevent by learning to identify and avoid poisonous plants. %%

Contact dermatitis is caused by contact with poisonous plants, such as poison ivy, poison oak, poison sumac, and stinging nettle.
Expand Down Expand Up @@ -884,7 +884,7 @@ If you fall through ice, do the following:
If you are caught in a rip current, swim parallel to the shore until you are out of the current. Then swim back to shore.

## Sunburn
%% K: sunburn, burn, sunscreen, uv, sun, red, pain, swell, blister, spf %%
%% K: sunburn, burn, sunscreen, uv, sun, red, pain, swell, blister, spf, skin %%
%% S: Symptoms include redness, pain, swelling, and blisters. Treat by getting out of the sun, applying a burn cream, and taking pain relievers. Prevent by wearing sunscreen, proper clothing, and staying in the shade. %%

Sunburn is caused by prolonged exposure to ultraviolet (UV) radiation from the sun.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Once you have mastered these skills, you should learn how to do the following:
- Repair clothing.

## Clothing
%% K: wool, polyester, nylon, down, cotton, layer, material, garment, socks, pants, shirt, jacket, fleece, vest, underwear, undergarments, windbreaker, rain, hat, sunglasses, glasses, scarf, bandana, footwear, shoes, boots %%
%% K: wear, dress, wool, polyester, nylon, down, cotton, layer, material, garment, socks, pants, shirt, jacket, fleece, vest, underwear, undergarments, windbreaker, rain, hat, sunglasses, glasses, scarf, bandana, footwear, shoes, boots %%
%% S: Dress in layers and choose clothing made from wool, polyester, or nylon. Only wear shoes that you have worn in. %%

Your first line of defense in any environment is your clothing. Proper attire should keep you dry, regulate your body temperature, protect you from the sun, and prevent insect bites.

textutils
### Materials
When choosing clothing, consider the following materials:
- Wool: Retains warmth even when wet.
Expand Down Expand Up @@ -103,7 +103,7 @@ If you plan to be hiking in wet conditions, consider wearing waterproof boots.
Bring extra pairs of socks, preferably made from wool, and ensure they are taller than your boots to avoid blisters.

## Shelters
%% K: location, lean-to, a-frame, cave, emergency-space-blanket, space-blanket, blanket, tent, hammock, ground, wall, sleep, bag, pad, airflow %%
%% K: build, location, lean-to, a-frame, cave, emergency-space-blanket, space-blanket, blanket, tent, hammock, ground, wall, sleep, bag, pad, airflow %%
%% S: Construct a shelter using natural materials or a tarp. Insulate the shelter with leaves, straw, or clothing. %%

### Choosing a shelter location
Expand Down
4 changes: 2 additions & 2 deletions guides/en-US/guide_survival_chapter_crafting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ Stop cuts are used to prevent wood from splitting when you are cutting it. To ma
Batoning is the process of using a knife to split wood. To baton wood, place the knife on the wood where you want to split it and hit the back of the knife with a piece of wood. Be sure to use a knife with a full tang and a fixed blade.

## Sharpening
%% K: sharpen, tool, knife, axe, blade, repair %%
%% K: sharpen, rock, tool, knife, axe, blade, repair %%
%% S: Use a smooth rock to sharpen your tools. %%

If you find a smooth rock, you can use it to sharpen your knife or axe. Preferably the rock will be small enough to hold in your hand. To sharpen your tool, rub the rock in a circular motion along the edge of the blade. Be sure to match the angle of the blade when sharpening.

## Knives
%% K: knife, flint, chert, obsidian, cut, blade %%
%% K: knife, rock, flint, chert, obsidian, cut, blade %%
%% S: You can craft a knife from bone or certain types of rock. %%

### Bone knife
Expand Down
2 changes: 1 addition & 1 deletion guides/en-US/guide_survival_chapter_fire.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% K: fire, flame, light, heat, warm %%
%% K: fire, flame, light, heat, warm, burn %%
%% S: In a survival situation, make a tepee fire if you have a fire starter and gather plenty of wood. Otherwise, focus on insulating your clothes and shelter. %%

This chapter covers how to make a fire in a survival situation.
Expand Down
8 changes: 4 additions & 4 deletions guides/en-US/guide_survival_chapter_food.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% K: food, eat, meal, hunger, hungry, forage %%
%% K: food, eat, meal, hunger, hungry, forage, identify, edible, inedible %%
%% S: In a survival situation, ration out the food you have and only forage (plants, insects, shellfish) as a last resort. %%

This chapter covers how to find and prepare food in a survival situation.
Expand Down Expand Up @@ -69,7 +69,7 @@ Starvation occurs when the body does not receive enough nutrients to function pr
- Longer healing time for wounds and illnesses.

## Plants and mushrooms
%% K: plant, mushroom, forage, edible, inedible, poison, toxic, identify, leach, test %%
%% K: plant, mushroom, seaweed, weeds, green, sap, fungus, forage, poison, toxic, leach, test, berries %%
%% S: Only eat plants you can confidently identity as safe and don't eat any mushrooms. Aggregate berries, like raspberries and blackberries, are generally safe. %%

The safest method for consuming wild plants is through positive identification. Before your trip, it's wise to study local plants through guidebooks or plant identification cards.
Expand Down Expand Up @@ -164,7 +164,7 @@ Cook all insects using any of the cooking techniques in this chapter.
Worms can be placed in water for 15 minutes to purge their digestive tracts. After purging, they should be cooked before eating.

## Shellfish and crustaceans
%% K: shellfish, crustacean, clam, mussel, snail, limpet, crayfish, lobster, crab, shrimp, shell, bait, basket, trap, seafood %%
%% K: shellfish, crustacean, clam, mussel, snail, limpet, crayfish, lobster, crab, shrimp, shell, bait, basket, trap, seafood, algae, tide, coastal, coast %%
%% S: Many shellfish and crustaceans are found along the shoreline and most can be eaten when cooked. %%

Shellfish and crustaceans are a good source of protein and can be found in both freshwater and saltwater. They are relatively easy to catch, so they make a good survival food source.
Expand Down Expand Up @@ -263,7 +263,7 @@ Alternatively, use a funnel fish trap by placing sticks into a V-shape with a re
5. Cook the fish.

## Other animals
%% K: animal, hunt, bow, trap, snare, deadfall, bird, reptile, amphibian, frog, snake, mammal, skin, kill, meat %%
%% K: animal, hunt, bow, trap, snare, deadfall, bird, reptile, amphibian, frog, snake, mammal, skin, kill, meat, butcher, skin %%
%% S: Hunting or trapping can be energy consuming and difficult without proper tools. %%

In a survival situation, it's best to focus on easier-to-catch animals like insects, shellfish, crustaceans, and fish. But if you have the means to catch other animals, they can provide a good source of protein and nutrients.
Expand Down
10 changes: 5 additions & 5 deletions guides/en-US/guide_survival_chapter_medical.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%% K: medicine, medical, heal, health, injury, sick, ill, first-aid %%
%% K: medicine, medical, heal, health, injury, sick, ill, first-aid, symptom, treat, prevent %%
%% S: In a survival situation, minor medical issues can become life threatening. Try to stay calm and treat issues to the best of your ability and call for help if needed/possible. %%

This chapter covers some basic medical knowledge and techniques for common injuries and illnesses you may encounter in the wilderness. It is not a substitute for professional medical advice/treatment or in depth first aid guides.
Expand Down Expand Up @@ -308,7 +308,7 @@ If the blister is large or painful:
- Apply adhesive tape or moleskin to prevent blisters.

## Burns
%% K: burn, scald, blister, red, pain, aloe, vera, fire %%
%% K: burn, scald, blister, red, pain, aloe, vera, fire, skin %%
%% S: Treat minor burns by soaking with cool water and loosly bandage. Seek medical attention for severe burns. Prevent by using caution around fires and hot objects. %%

### Treatment
Expand Down Expand Up @@ -666,7 +666,7 @@ Heatstroke:
- Do not overexert yourself.

## Hygiene
%% K: hygiene, clean, wash, soap, sanitize, toothbrush, teeth, tooth, toothpaste, brush, feet, socks, dry, clothes, defecate, urinate, bathroom, trowel %%
%% K: hygiene, clean, wash, soap, shampoo, sanitize, toothbrush, teeth, tooth, toothpaste, brush, feet, socks, dry, clothes, defecate, urinate, bathroom, trowel %%
%% S: Wash hands frequently, especially before eating and after using the bathroom. %%

### Washing
Expand Down Expand Up @@ -779,7 +779,7 @@ While in the wilderness it is common to get objects in your eye, such as dirt, s
- Ensure yourself that you will be okay.

## Poison ivy and contact dermatitis
%% K: poison, ivy, oak, sumac, trumpet, rengas, stinging, nettle, rash, itch, blister, burn, red, swell, dermatitis, contact %%
%% K: poison, ivy, oak, sumac, trumpet, rengas, stinging, nettle, rash, itch, blister, red, swell, dermatitis, contact %%
%% S: Symptoms include a rash, itching, and blisters. Treat by washing the area with soap and water, applying calamine lotion, and taking antihistamines. Prevent by learning to identify and avoid poisonous plants. %%

Contact dermatitis is caused by contact with poisonous plants, such as poison ivy, poison oak, poison sumac, and stinging nettle.
Expand Down Expand Up @@ -884,7 +884,7 @@ If you fall through ice, do the following:
If you are caught in a rip current, swim parallel to the shore until you are out of the current. Then swim back to shore.

## Sunburn
%% K: sunburn, burn, sunscreen, uv, sun, red, pain, swell, blister, spf %%
%% K: sunburn, burn, sunscreen, uv, sun, red, pain, swell, blister, spf, skin %%
%% S: Symptoms include redness, pain, swelling, and blisters. Treat by getting out of the sun, applying a burn cream, and taking pain relievers. Prevent by wearing sunscreen, proper clothing, and staying in the shade. %%

Sunburn is caused by prolonged exposure to ultraviolet (UV) radiation from the sun.
Expand Down
Loading

0 comments on commit 2e300ac

Please sign in to comment.