Dylan parse features#646
Conversation
…hist-uni.github.io into dylan-parse-features
✅ Deploy Preview for obu ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
khemarato
left a comment
There was a problem hiding this comment.
Good start. Let's learn some software engineering! 😺
| var warning = ""; | ||
| var words = data.q.trim().split(" "); | ||
|
|
||
| // Dylan's edit - remove quotes? - line 178 - 187 |
There was a problem hiding this comment.
There's no need to plant your flag 😆
There was a problem hiding this comment.
hahaha - sowwy
Its the first thing I thought of to be clear about things but you're right. I'm just learning.
Can I ask though, how should I handle comments?
There was a problem hiding this comment.
Let's just say, there's no need for you to add any comments? The test cases should document what your functions do.
There was a problem hiding this comment.
yeah that makes sense - it keeps me very focused on the TDD part of the project as well then which is good.
| var words = data.q.trim().split(" "); | ||
|
|
||
| // Dylan's edit - remove quotes? - line 178 - 187 | ||
| // /["']/g is a JavaScript regular expression literal - g = global flag (match all occurrences, not just the first) |
There was a problem hiding this comment.
You can assume readers know about regex strings.
There was a problem hiding this comment.
understood
|
|
||
| // Normalize leading nikaya index, e.g. "MN6" -> "MN 6" | ||
| // I wrote out some for loops and char checks but AI suggested regex when I had him check my code. | ||
| // Regex seems straight forward you just need to research it as I still need to. I would have preferred manually doing it so I can practice my ability |
There was a problem hiding this comment.
Learning and practicing regex is a good skill too!
There was a problem hiding this comment.
understood - I'll make it a regular addition to my parsing work
| // /["']/g is a JavaScript regular expression literal - g = global flag (match all occurrences, not just the first) | ||
| var preWordsParse = data.q.replace(/["']/g, ""); | ||
|
|
||
| // Normalize leading nikaya index, e.g. "MN6" -> "MN 6" |
There was a problem hiding this comment.
Make this its own function, normalizeSuttaRefs or something and start off by describing what you want that function to do in the tests file. Start off with a base case that searches without a ref should be returned unaltered. Run the tests and watch it fail. Then add an implementation that just returns the string that you passed in, rerun the test and watch it pass. This is called "test-driven development." Then slowly add more complicated test cases and getting your code to pass them, until you've eventually built up all the functionality you want.
| preWordsParse = preWordsParse.replace(/\b([\p{L}]+?)sutta\b/giu, "$1 sutta"); | ||
|
|
||
| // check if preWordsParse has sutta using regex .text() | ||
| const hasSutta = /\bsutta\b/i.test(preWordsParse); |
There was a problem hiding this comment.
Do the same here. Make hasSutta a function and add tests for it in the test file.
…hist-uni.github.io into dylan-parse-features
…hist-uni.github.io into dylan-parse-features
…hist-uni.github.io into dylan-parse-features
…hist-uni.github.io into dylan-parse-features
…hist-uni.github.io into dylan-parse-features
…hist-uni.github.io into dylan-parse-features
…-TheDreamer/buddhist-uni.github.io into dylan-parse-features
…hist-uni.github.io into dylan-parse-features
…hist-uni.github.io into dylan-parse-features
Here are some regex parsing edits to help clean user input - This is to match user input with our backend ruleset for querying the database items.
Result: ability to return more database items that match user input.
There is one particular regex that identifies the word sutta and puts a space before it in order to split it from the rest of the pali words. This can help when typing sutta names as all one word. Some sutta names seem to have only one pali name then sutta - this can help the search.
However, two pali names and sutta are harder to detect when written all in one word - So therefore, the edit to add with this is on branch dylan-search-function, where I implement the one word token search, that solves even more cases like this.
But highlights don't work with the one word query so this needs to be looked into further as well.