Issue 1840 2 - #2065
Conversation
kbenoit
left a comment
There was a problem hiding this comment.
So locate() is essentially the kwic() from the other Issue 1840 PR, that includes the tokens, but kwic() drops them and returns the same sort of data.frame we had formerly? Will having the locate function separate provide user-facing functionality? or is this intended to be internal only?
I'm fine with kwic() being unchanged from the user standpoint, although it's better now overall from the work we did on the previous PR.
Obviously there a lot of tests that would need redoing, and documentation for locate() if you meant to export this. (You can't noRd exported functions.)
BTW I think this would be simpler to review and fix if we merged the other PR, then made this a new PR, but happy to work with it either way.
|
> microbenchmark::microbenchmark(
+ locate(toks, data_dictionary_LSD2015),
+ tokens_select(toks, data_dictionary_LSD2015),
+ tokens_lookup(toks, data_dictionary_LSD2015),
+ kwic(toks, data_dictionary_LSD2015),
+ times = 1, unit = "relative"
+ )
Unit: relative
expr min lq mean median uq max neval
locate(toks, data_dictionary_LSD2015) 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1
tokens_select(toks, data_dictionary_LSD2015) 1.586143 1.586143 1.586143 1.586143 1.586143 1.586143 1
tokens_lookup(toks, data_dictionary_LSD2015) 1.813328 1.813328 1.813328 1.813328 1.813328 1.813328 1
kwic(toks, data_dictionary_LSD2015) 26.129500 26.129500 26.129500 26.129500 26.129500 26.129500 1 |
|
OK, this looks really good, and the performance is great. This could be a very useful function for building upon, the same way that you've redefined kwic to work on this. We can see if it's possible to build on the I'm happy to help clean this up but how about first, I merge the other PR, then merge master into this branch. that will leave just your two commits as the diff, and we can use those to fix the documentation, tests, etc.? |
|
Glad you liked it. It would be great if you could update the tests and man, but should not be difficult, because it is only to change Also, we might want to change the name to |
|
Happy to clean this up, since that gives me a good, hands-on opportunity to get used to the new functions and get additional insights into their potential. True on the nouns, although that's more for our core object constructors. This is a utility a bit more like Should this be keyworded internal, or should it appear in the online documentation index? |
- move it to locate.R - consolidate kwic.locate() into kwic.tokens() - add tests for locate() - simplify kwic() examples, remove older examples using as.data.frame.kwic() and print.kwic() where window or separator was added - remove the tests for as.data.frame.kwic() and print.kwic() where window or separator was added
|
Ok I tidied this up, after merging the other PR so that we could focus on the changes introduced through the use of the new I consolidated the formerly I did not think we still need to include the tokens object in the kwic return, since no functions would use this. A simple vector of ntoken counts is enough for Because there is an attribute for the kwic return object, I revived Questions/issues:
|
Codecov Report
@@ Coverage Diff @@
## master #2065 +/- ##
==========================================
- Coverage 95.67% 95.65% -0.02%
==========================================
Files 84 85 +1
Lines 4903 4905 +2
==========================================
+ Hits 4691 4692 +1
- Misses 212 213 +1
Continue to review full report at Codecov.
|
|
It is cleaner without tokens attached to the location object, but this would means that we will add a new input to patterns: If we were to add the location object, |
|
I think we should not redefine We could add an option for But all of these options involve adding things that can be done within the framework set up by this PR. So I suggest we don't need to resolve them here. This PR further improves So I'm in favour of merging this, but renaming the function |
|
OK. Let's name it |
…nto issue-1840-2
|
It is done, but no idea why it is failing the test on Windows. |
|
Something strange happening with the windows build of quanteda.textplots (and windows builds generally - not sure what it is but seems to be a CRAN issue). I think we can ignore it. |
|
Please merge if you think it is good enough. |
|
OK. One thought before we finalise this: should we convert an index object to kwic using |
|
It depends on how much we want to promote the index object. |
|
The index object has enormous potential, but we haven't yet figured out all of the best ways to use it or integrate it into other functionality. My conservative suggestion is to keep the functionality separate for now in a coercion function ( |
|
That is fine with me for now. Please make changes as you suggested. |
|
Well, it became immediately clear once I started implementing It does make the as.kwic.index <- function(x, tokens, window = 5L)But then we are not coercing an object, we are constructing it from two inputs plus a parameter. So I think I prefer your solution in the last few commits here, where |
|
I said that |
Based on #2045, I made the output of
kwic()identical to the v2. It callslocate()to get positions of keywords. Users are recommended to uselocate()before runningkwic()to get ideas how many times the patterns hit when they analyze large corpora.It is named
locate()simply because there arefind()andmatch()in base R. I am happy with more creative names.