Skip to content

Instantly share code, notes, and snippets.

Avatar

Telvis Calhoun telvis07

View GitHub Profile
@telvis07
telvis07 / ngram_prune.R
Last active Jul 1, 2016
NLP - prune ngrams by finding the minimum number of ngrams that cover X percent of the word instances
View ngram_prune.R
prune_ngram_df_by_cover_percentage <- function(df, percentage) {
# assumes df contains columns (word, freq)
# assumes df is sorted by freq in descending order
# prune ngrams by finding the minimum number of ngrams that cover X percent of the word instances
sums <- cumsum(df$freq)
cover <- which(sums >= sum(df$freq) * percentage)[1]
print(sprintf("%s of %s (%s%%) cover %s%% of word instances",
cover,
nrow(df),
cover/nrow(df)*100,
View kibana-filtered-query.json
{
"facets": {
"terms": {
"facet_filter": {
"fquery": {
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
View terms-filter-lookup.sh
# index the information for user with id 2, specifically, its friends
curl -XPUT localhost:9200/users/user/2 -d '{
"friends" : ["1", "3"]
}'
# index a tweet, from user with id 2
curl -XPUT localhost:9200/tweets/tweet/1 -d '{
"user" : "1",
"tweet" : "hi i am user 1 "
}'
@telvis07
telvis07 / multi_field_nested_test.sh
Created Dec 11, 2012
multi-field in a nested document
View multi_field_nested_test.sh
curl -XDELETE localhost:9200/test
curl -XPOST localhost:9200/test -d '
{
"mappings": {
"type1": {
"properties": {
"message": {
"index": "analyzed",
"type": "string"
@telvis07
telvis07 / elasticsearch_multi_field_geo_point.sh
Created Dec 6, 2012
multi-field with geo_point in a nested document
View elasticsearch_multi_field_geo_point.sh
curl -XPOST localhost:9200/test -d '
{
"mappings": {
"type1": {
"properties": {
"message": {
"index": "analyzed",
"type": "string"
},
"depart": {
You can’t perform that action at this time.