Skip to content

Commit

Permalink
Working update of README
Browse files Browse the repository at this point in the history
  • Loading branch information
mananshah99 committed Mar 13, 2015
1 parent 9a5e0f0 commit 9e43e1f
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# sentR
A continually developed R package to provide functional sentiment analysis utility.
An R package that provide functional sentiment analysis utilities.

## Install

Expand All @@ -8,43 +8,40 @@ A continually developed R package to provide functional sentiment analysis utili
2. Require devtools: run `require('devtools')`
3. Install sentR@latest: run `install_github('mananshah99/sentR')`

## Sentiment Scoring Functions
# Sentiment Scoring Examples

### score.aggregate = function(sentences, pos.words, neg.words, .progress='none')
Scores the sentiment of text by setting words in `pos.words` to `+1` and words in `neg.words` to `-1` in the vector of sentences.
Input:

Example:
```
require('sentR')
positive <- c('happy', 'well-off', 'good')
negative <- c('sad', 'bad', 'miserable', 'terrible')
test <- c('I am a very happy person.', 'I am a very sad person', 'R has good data analysis tools')
out <- score.aggregate(test, positive, negative)
out
```
Output:
```
score text
1 1 I am a very happy person.
2 -1 I am a very sad person
3 1 R has good data analysis tools
```

### score.naivebayes = function(train.sentences, test.sentences, .progress = 'none')
Scores the sentiment of text by using the Naive Bayes modeling functionality from `e1071`.
### score.viralheat = function (text, api.key)
Scores the sentiment of text using the ViralHeat API (requires an API key)

## Sentiment Scraping Utilities
# Create small vectors for happy and sad words (useful in aggregate(...) function)
positive <- c('happy', 'well-off', 'good', 'happiness')
negative <- c('sad', 'bad', 'miserable', 'terrible')
### scrape.IMDb <- function(url)
Scrapes the IMDb website for movie reviews and returns a list of scores.
# Words to test sentiment
test <- c('I am a very happy person.', 'I am a very sad person',
'I’ve always understood happiness to be appreciation. There is no greater happiness than appreciation for what one has- both physically and in the way of relationships and ideologies. The unhappy seek that which they do not have and can not fully appreciate the things around them. I don’t expect much from life. I don’t need a high paying job, a big house or fancy cars. I simply wish to be able to live my life appreciating everything around me.
')
### scrape.striplinks <- function(text)
Strips all links of the form `http*` found in text. Useful for normalizing sentimetn scores
# 1. Simple Summation
out <- classify.aggregate(test, positive, negative)
out
## Plotting Utilities
# 2. Naive Bayes
out <- classify.naivebayes(test)
out
```

### multiplot <- function(..., plotlist=NULL, cols)
Allows for multiple `ggplot` instances to be printed together.
Output:
```
score
1 1
2 -1
3 2
POS NEG POS/NEG SENT
[1,] "9.47547003995745" "0.445453222112551" "21.2715265477714" "positive"
[2,] "1.03127774142571" "9.47547003995745" "0.108836578774127" "negative"
[3,] "67.1985217685598" "35.1792261323723" "1.9101762362738" "positive"
```

0 comments on commit 9e43e1f

Please sign in to comment.