Permalink
Browse files

add getters for Extractor Entity

  • Loading branch information...
1 parent 5f4473c commit 7d872cb480a3cfbd864e8e549c832d4654c9008e @hjz hjz committed Jun 8, 2011
Showing with 36 additions and 20 deletions.
  1. +20 −4 src/com/twitter/Extractor.java
  2. +16 −16 tests/com/twitter/ExtractorTest.java
@@ -9,10 +9,10 @@
*/
public class Extractor {
public static class Entity {
- public Integer start = null;
- public Integer end = null;
- public String value = null;
- public String type = null;
+ protected Integer start = null;
+ protected Integer end = null;
+ protected String value = null;
+ protected String type = null;
public Entity(Matcher matcher, String valueType, Integer groupNumber) {
// Offset -1 on start index to include @, # symbols for mentions and hashtags
@@ -59,6 +59,22 @@ public boolean equals(Object obj) {
public int hashCode() {
return this.type.hashCode() + this.value.hashCode() + this.start + this.end;
}
+
+ public Integer getStart() {
+ return start;
+ }
+
+ public Integer getEnd() {
+ return end;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public String getType() {
+ return type;
+ }
}
/**
@@ -61,12 +61,12 @@ public void testMultipleMentions() {
public void testMentionWithIndices() {
List<Extractor.Entity> extracted = extractor.extractMentionedScreennamesWithIndices(" @user1 mention @user2 here @user3 ");
assertEquals(extracted.size(), 3);
- assertEquals(extracted.get(0).start.intValue(), 1);
- assertEquals(extracted.get(0).end.intValue(), 7);
- assertEquals(extracted.get(1).start.intValue(), 16);
- assertEquals(extracted.get(1).end.intValue(), 22);
- assertEquals(extracted.get(2).start.intValue(), 28);
- assertEquals(extracted.get(2).end.intValue(), 34);
+ assertEquals(extracted.get(0).getStart().intValue(), 1);
+ assertEquals(extracted.get(0).getEnd().intValue(), 7);
+ assertEquals(extracted.get(1).getStart().intValue(), 16);
+ assertEquals(extracted.get(1).getEnd().intValue(), 22);
+ assertEquals(extracted.get(2).getStart().intValue(), 28);
+ assertEquals(extracted.get(2).getEnd().intValue(), 34);
}
}
@@ -97,12 +97,12 @@ public void testMultipleHashtags() {
public void testHashtagWithIndices() {
List<Extractor.Entity> extracted = extractor.extractHashtagsWithIndices(" #user1 mention #user2 here #user3 ");
assertEquals(extracted.size(), 3);
- assertEquals(extracted.get(0).start.intValue(), 1);
- assertEquals(extracted.get(0).end.intValue(), 7);
- assertEquals(extracted.get(1).start.intValue(), 16);
- assertEquals(extracted.get(1).end.intValue(), 22);
- assertEquals(extracted.get(2).start.intValue(), 28);
- assertEquals(extracted.get(2).end.intValue(), 34);
+ assertEquals(extracted.get(0).getStart().intValue(), 1);
+ assertEquals(extracted.get(0).getEnd().intValue(), 7);
+ assertEquals(extracted.get(1).getStart().intValue(), 16);
+ assertEquals(extracted.get(1).getEnd().intValue(), 22);
+ assertEquals(extracted.get(2).getStart().intValue(), 28);
+ assertEquals(extracted.get(2).getEnd().intValue(), 34);
}
}
@@ -112,10 +112,10 @@ public void testHashtagWithIndices() {
public static class URLTest extends ExtractorTest {
public void testUrlWithIndices() {
List<Extractor.Entity> extracted = extractor.extractURLsWithIndices("http://t.co url https://www.twitter.com ");
- assertEquals(extracted.get(0).start.intValue(), 0);
- assertEquals(extracted.get(0).end.intValue(), 11);
- assertEquals(extracted.get(1).start.intValue(), 16);
- assertEquals(extracted.get(1).end.intValue(), 39);
+ assertEquals(extracted.get(0).getStart().intValue(), 0);
+ assertEquals(extracted.get(0).getEnd().intValue(), 11);
+ assertEquals(extracted.get(1).getStart().intValue(), 16);
+ assertEquals(extracted.get(1).getEnd().intValue(), 39);
}
}
/**

0 comments on commit 7d872cb

Please sign in to comment.