Repository: nltk/nltk

Issue:
Porter stemmer returns a capital instead of lowercase 
This output is unexpected. The `In` returns the capitalize `In` from PorterStemmer's output.

```python
>>> from nltk.stem import PorterStemmer
>>> porter = PorterStemmer()
>>> porter.stem('In')
'In'
```

More details on https://stackoverflow.com/q/60387288/610569


Discussion:
For any stemming, are we not first supposed to convert them into lowercase as part of normalization?
Another example of capitalized output using `Oh`

```
>>> from nltk.stem import PorterStemmer
>>> porter = PorterStemmer()
>>> porter.stem('Oh')
'Oh'
```
I think it's because originally it wants to remain the original form of abbreviations when the word length less than 2, like abbreviations for states. 
```
def stem(self, word):
    stem = word.lower()

    if self.mode == self.NLTK_EXTENSIONS and word in self.pool:
        return self.pool[word]

    if self.mode != self.ORIGINAL_ALGORITHM and len(word) <= 2:
        # With this line, strings of length 1 or 2 don't go through
        # the stemming process, although no mention is made of this
        # in the published algorithm.
        return word

    stem = self._step1a(stem)
    stem = self._step1b(stem)
    stem = self._step1c(stem)
    stem = self._step2(stem)
    stem = self._step3(stem)
    stem = self._step4(stem)
    stem = self._step5a(stem)
    stem = self._step5b(stem)

    return stem
```

The word 'In' and 'Oh' both are not in `self.pool`, and `len(word)<=2`, which means it doesn't satisfy the stem condition here, so it remains the same. 

If it's not assigned, may I work on this? Its my first time contributing to a project.
@PhanatosZou feel free to make the changes and create a pull request. The main code that needs to be changed is:

```
if self.mode != self.ORIGINAL_ALGORITHM and len(word) <= 2:
    # With this line, strings of length 1 or 2 don't go through
    # the stemming process, although no mention is made of this
    # in the published algorithm.
    return stem
```

But it'll be good to check all keys in `self.pool` and if they are non-caps, then make changes to this too:

```
if self.mode == self.NLTK_EXTENSIONS and word in self.pool:
    return self.pool[stem]
```
Sounds good! I'll work on it.

Resolving patch:
diff --git a/nltk/stem/porter.py b/nltk/stem/porter.py
--- a/nltk/stem/porter.py
+++ b/nltk/stem/porter.py
@@ -648,17 +648,21 @@ def _step5b(self, word):
             word, [("ll", "l", lambda stem: self._measure(word[:-1]) > 1)]
         )
 
-    def stem(self, word):
-        stem = word.lower()
+    def stem(self, word, to_lowercase=True):
+        """
+        :param to_lowercase: if `to_lowercase=True` the word always lowercase
+        """
+        stem = word.lower() if to_lowercase else word
 
         if self.mode == self.NLTK_EXTENSIONS and word in self.pool:
-            return self.pool[word]
+            return self.pool[stem]
 
         if self.mode != self.ORIGINAL_ALGORITHM and len(word) <= 2:
             # With this line, strings of length 1 or 2 don't go through
             # the stemming process, although no mention is made of this
             # in the published algorithm.
-            return word
+            return stem
+
 
         stem = self._step1a(stem)
         stem = self._step1b(stem)


Test patch:
diff --git a/nltk/test/unit/test_stem.py b/nltk/test/unit/test_stem.py
--- a/nltk/test/unit/test_stem.py
+++ b/nltk/test/unit/test_stem.py
@@ -143,3 +143,16 @@ def test_oed_bug(self):
         Ensures that 'oed' can be stemmed without throwing an error.
         """
         assert PorterStemmer().stem('oed') == 'o'
+
+
+    def test_lowercase_option(self):
+        """Test for improvement on https://github.com/nltk/nltk/issues/2507
+
+        Ensures that stems are lowercased when `to_lowercase=True`
+        """
+        porter = PorterStemmer()
+        assert porter.stem('On') == 'on'
+        assert porter.stem('I') == 'i'
+        assert porter.stem('I', to_lowercase=False) == 'I'
+        assert porter.stem('Github') == 'github'
+        assert porter.stem('Github', to_lowercase=False) == 'Github'