├── .gitignore ├── src ├── ReviewPhrases.java ├── Review.java ├── SimpleRunner.java ├── Postprocess.java ├── Phrases.java ├── Extract.java └── Pattern.java ├── phrases.iml ├── stopwords.txt ├── test └── TestPatterns.java ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | .idea/ -------------------------------------------------------------------------------- /src/ReviewPhrases.java: -------------------------------------------------------------------------------- 1 | import com.mongodb.BasicDBObject; 2 | import com.mongodb.DBObject; 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class ReviewPhrases implements Serializable{ 7 | 8 | private Review review; 9 | 10 | private List phrases; 11 | 12 | public ReviewPhrases(Review review, List phrases) { 13 | this.review = review; 14 | this.phrases = phrases; 15 | } 16 | 17 | public DBObject toDBObject() { 18 | DBObject dbObject = new BasicDBObject(); 19 | dbObject.put("review", review.toDBObject()); 20 | dbObject.put("phrases", phrases); 21 | 22 | return dbObject; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Review.java: -------------------------------------------------------------------------------- 1 | import com.mongodb.BasicDBObject; 2 | import com.mongodb.DBObject; 3 | import java.io.Serializable; 4 | 5 | public class Review implements Serializable{ 6 | 7 | private String text; 8 | 9 | private String reviewId; 10 | 11 | private String business; 12 | 13 | public Review(String text, String reviewId, String business) { 14 | this.text = text; 15 | this.reviewId = reviewId; 16 | this.business = business; 17 | } 18 | 19 | public Object toDBObject() { 20 | DBObject dbObject = new BasicDBObject(); 21 | dbObject.put("text", text); 22 | dbObject.put("reviewId", reviewId); 23 | dbObject.put("business", business); 24 | 25 | return dbObject; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/SimpleRunner.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | 3 | public class SimpleRunner { 4 | 5 | public static void main(String[] args) { 6 | Extract extract = new Extract(); 7 | List patterns = extract.run("Cafe is conveniently located on Pier 39 in San Fransisco and offers a great view of the bay along with a good hearty breakfast. I had heard some mixed things about Cafe but I wanted to see for myself so I went Sunday morning before my flight home. The restaurant itself is very clean and as expected for being in the middle of a big tourist location it is pretty busy. My meal consisted of banana and pecan french toast, country potatoes, fruit and 2 eggs over easy. The food was good but not great, my biggest complaint was the syrup was very thin and not super flavorful and the french toast was a little dry. 3 stars for A ok (not bad)"); 8 | for (Pattern pattern : patterns) { 9 | System.out.println(pattern.toAspect()); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /phrases.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Postprocess.java: -------------------------------------------------------------------------------- 1 | import edu.stanford.nlp.ling.CoreAnnotations; 2 | import edu.stanford.nlp.ling.CoreLabel; 3 | import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations; 4 | import edu.stanford.nlp.pipeline.Annotation; 5 | import edu.stanford.nlp.pipeline.StanfordCoreNLP; 6 | import edu.stanford.nlp.sentiment.SentimentCoreAnnotations; 7 | import edu.stanford.nlp.trees.Tree; 8 | import edu.stanford.nlp.util.CoreMap; 9 | 10 | import java.util.List; 11 | import java.util.Properties; 12 | 13 | public class Postprocess { 14 | 15 | public Postprocess() { 16 | 17 | } 18 | 19 | public List run(List patterns) { 20 | 21 | Properties props = new Properties(); 22 | props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment"); 23 | StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 24 | 25 | for (Pattern pattern : patterns) { 26 | Annotation annotation = pipeline.process(pattern.toSentences()); 27 | for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { 28 | Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class); 29 | int sentiment = RNNCoreAnnotations.getPredictedClass(tree); 30 | for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { 31 | String lemma = token.get(CoreAnnotations.LemmaAnnotation.class); 32 | 33 | } 34 | } 35 | } 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Phrases.java: -------------------------------------------------------------------------------- 1 | import com.mongodb.*; 2 | 3 | import java.net.UnknownHostException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Phrases { 8 | 9 | final static String MongoUri = "mongodb://localhost:27030/"; 10 | final static String Database = "YelpReviews"; 11 | final static String Reviews = "Review"; 12 | final static String Phrases = "Phrases"; 13 | MongoClient mongoClient; 14 | DB database; 15 | DBCollection reviewsCollection, phrasesCollection; 16 | 17 | public Phrases() { 18 | try { 19 | mongoClient = new MongoClient(new MongoClientURI(MongoUri)); 20 | } catch (UnknownHostException e) { 21 | e.printStackTrace(); 22 | } 23 | database = mongoClient.getDB(Database); 24 | reviewsCollection = database.getCollection(Reviews); 25 | phrasesCollection = database.getCollection(Phrases); 26 | } 27 | 28 | public static void main(String[] args) { 29 | Phrases phrases = new Phrases(); 30 | try { 31 | phrases.run(); 32 | } 33 | catch(Exception exception) { 34 | phrases.run(); 35 | } 36 | } 37 | 38 | public void run() { 39 | DBCursor cursor = reviewsCollection.find(); 40 | int count = cursor.count(); 41 | Extract extractor = new Extract(); 42 | int done = 0; 43 | try { 44 | while (cursor.hasNext()) { 45 | DBObject dbItem = cursor.next(); 46 | String text = dbItem.get("Text").toString(); 47 | String reviewId = dbItem.get("ReviewId").toString(); 48 | String business = dbItem.get("Business").toString(); 49 | 50 | if (!alreadyExtractedPhrases(reviewId)) { 51 | List phrases = extractor.run(text); 52 | Review review = new Review(text, reviewId, business); 53 | savePhrases(review, phrases); 54 | } 55 | 56 | done++; 57 | System.out.println("Done " + done + "/" + count); 58 | } 59 | } finally { 60 | cursor.close(); 61 | } 62 | } 63 | 64 | private boolean alreadyExtractedPhrases(String reviewId) { 65 | return phrasesCollection.find(new BasicDBObject("review.reviewId", reviewId)).count() > 0; 66 | } 67 | 68 | private void savePhrases(Review review, List patterns) { 69 | List phrases = new ArrayList(); 70 | for (Pattern pattern : patterns) { 71 | phrases.add(pattern.toAspect()); 72 | } 73 | ReviewPhrases result = new ReviewPhrases(review, phrases); 74 | phrasesCollection.insert(result.toDBObject()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /stopwords.txt: -------------------------------------------------------------------------------- 1 | a a's able about above according accordingly across actually after afterwards again against ain't all allow allows almost alone along already also although always am among amongst an and another any anybody anyhow anyone anything anyway anyways anywhere apart appear appreciate appropriate are aren't around as aside ask asking associated at available away awfully b be became because become becomes becoming been before beforehand behind being believe below beside besides best better between beyond both brief but by c c'mon c's came can can't cannot cant cause causes certain certainly changes clearly co com come comes concerning consequently consider considering contain containing contains corresponding could couldn't course currently d definitely described despite did didn't different do does doesn't doing don't done down downwards during e each edu eg eight either else elsewhere enough entirely especially et etc even ever every everybody everyone everything everywhere ex exactly example except f far few fifth first five followed following follows for former formerly forth four from further furthermore g get gets getting given gives go goes going gone got gotten greetings h had hadn't happens hardly has hasn't have haven't having he he's hello help hence her here here's hereafter hereby herein hereupon hers herself hi him himself his hither hopefully how howbeit however i i'd i'll i'm i've ie if ignored immediate in inasmuch inc indeed indicate indicated indicates inner insofar instead into inward is isn't it it'd it'll it's its itself j just k keep keeps kept know knows known l last lately later latter latterly least less lest let let's like liked likely little look looking looks ltd m mainly many may maybe me mean meanwhile merely might more moreover most mostly much must my myself n name namely nd near nearly necessary need needs neither never nevertheless new next nine no nobody non none noone nor normally not nothing novel now nowhere o obviously of off often oh ok okay old on once one ones only onto or other others otherwise ought our ours ourselves out outside over overall own p particular particularly per perhaps placed please plus possible presumably probably provides q que quite qv r rather rd re really reasonably regarding regardless regards relatively respectively right s said same saw say saying says second secondly see seeing seem seemed seeming seems seen self selves sensible sent serious seriously seven several shall she should shouldn't since six so some somebody somehow someone something sometime sometimes somewhat somewhere soon sorry specified specify specifying still sub such sup sure t t's take taken tell tends th than thank thanks thanx that that's thats the their theirs them themselves then thence there there's thereafter thereby therefore therein theres thereupon these they they'd they'll they're they've think third this thorough thoroughly those though three through throughout thru thus to together too took toward towards tried tries truly try trying twice two u un under unfortunately unless unlikely until unto up upon us use used useful uses using usually uucp v value various via viz vs w want wants was wasn't way we we'd we'll we're we've welcome well went were weren't what what's whatever when whence whenever where where's whereafter whereas whereby wherein whereupon wherever whether which while whither who who's whoever whole whom whose why will willing wish with within without won't wonder would would wouldn't x y yes yet you you'd you'll you're you've your yours yourself yourselves z zero -------------------------------------------------------------------------------- /src/Extract.java: -------------------------------------------------------------------------------- 1 | import edu.stanford.nlp.ling.CoreAnnotations; 2 | import edu.stanford.nlp.pipeline.Annotation; 3 | import edu.stanford.nlp.pipeline.StanfordCoreNLP; 4 | import edu.stanford.nlp.semgraph.SemanticGraph; 5 | import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations; 6 | import edu.stanford.nlp.trees.TypedDependency; 7 | import edu.stanford.nlp.util.CoreMap; 8 | 9 | import java.io.BufferedReader; 10 | import java.io.FileNotFoundException; 11 | import java.io.FileReader; 12 | import java.io.IOException; 13 | import java.util.*; 14 | 15 | public class Extract { 16 | 17 | final String stopwordsFile = "stopwords.txt"; 18 | List stopwords; 19 | 20 | public Extract() { 21 | 22 | try { 23 | stopwords = LoadStopwords(); 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | 29 | private static List ExtractPrimaryPatterns(Collection tdl) { 30 | List primary = new ArrayList(); 31 | 32 | for (TypedDependency td : tdl) { 33 | Pattern pattern = TryExtractPattern(td); 34 | if (pattern != null) { 35 | primary.add(pattern); 36 | } 37 | } 38 | 39 | return primary; 40 | } 41 | 42 | private static Pattern TryExtractPattern(TypedDependency dependency) { 43 | String rel = dependency.reln().toString(); 44 | String gov = dependency.gov().value(); 45 | String govTag = dependency.gov().label().tag(); 46 | String dep = dependency.dep().value(); 47 | String depTag = dependency.dep().label().tag(); 48 | 49 | Pattern.Relation relation = Pattern.asRelation(rel); 50 | if (relation != null) { 51 | Pattern pattern = new Pattern(gov, govTag, dep, depTag, relation); 52 | if (pattern.isPrimaryPattern()) { 53 | 54 | return pattern; 55 | } 56 | } 57 | 58 | return null; 59 | } 60 | 61 | private static List ExtractCombinedPatterns(List combined, List primary) { 62 | List results = new ArrayList(); 63 | 64 | for (Pattern pattern : combined) { 65 | Pattern aspect = pattern.TryCombine(primary); 66 | if (aspect != null) { 67 | results.add(aspect); 68 | } 69 | } 70 | 71 | return results; 72 | } 73 | 74 | private HashSet ExtractSentencePatterns(CoreMap sentence) { 75 | SemanticGraph semanticGraph = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class); 76 | 77 | List primary = ExtractPrimaryPatterns(semanticGraph.typedDependencies()); 78 | 79 | List combined; 80 | combined = ExtractCombinedPatterns(primary, primary); 81 | combined.addAll(ExtractCombinedPatterns(combined, primary)); 82 | combined.addAll(ExtractCombinedPatterns(combined, primary)); 83 | 84 | return PruneCombinedPatterns(combined); 85 | } 86 | 87 | private HashSet PruneCombinedPatterns(List combined) { 88 | List remove = new ArrayList(); 89 | 90 | HashSet patterns = new HashSet(combined); 91 | for (Pattern pattern : patterns) { 92 | if (patterns.contains(pattern.mother) && pattern.mother.relation != Pattern.Relation.conj_and 93 | && pattern.father.relation != Pattern.Relation.conj_and) { 94 | remove.add(pattern.mother); 95 | remove.add(pattern.father); 96 | } 97 | 98 | //remove patterns containing stopwords 99 | if (stopwords.contains(pattern.head) || stopwords.contains(pattern.modifier)) { 100 | remove.add(pattern); 101 | } 102 | } 103 | patterns.removeAll(remove); 104 | 105 | return patterns; 106 | } 107 | 108 | private List LoadStopwords() throws IOException { 109 | List words = new ArrayList(); 110 | 111 | BufferedReader br = new BufferedReader(new FileReader(stopwordsFile)); 112 | String line; 113 | while ((line = br.readLine()) != null) { 114 | words.add(line); 115 | } 116 | br.close(); 117 | 118 | return words; 119 | } 120 | 121 | public List run(String text) { 122 | List patterns = new ArrayList(); 123 | 124 | Properties props = new Properties(); 125 | props.setProperty("annotators", "tokenize, ssplit, pos, parse"); 126 | StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 127 | Annotation annotation = pipeline.process(text); 128 | List sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); 129 | for (CoreMap sentence : sentences) { 130 | patterns.addAll(ExtractSentencePatterns(sentence)); 131 | } 132 | 133 | return patterns; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /test/TestPatterns.java: -------------------------------------------------------------------------------- 1 | import junit.framework.Assert; 2 | import org.junit.Test; 3 | 4 | import java.util.List; 5 | 6 | public class TestPatterns { 7 | 8 | /** 9 | * 1. amod(N,A)→< N,A > 10 | */ 11 | @Test 12 | public void Pattern1() { 13 | Pattern goal1 = new Pattern("zoom", "great", Pattern.Relation.aspect); 14 | Pattern goal2 = new Pattern("resolution", "great", Pattern.Relation.aspect); 15 | 16 | List patterns = new Extract().run("This camera has great zoom and resolution."); 17 | 18 | Assert.assertTrue(patterns.contains(goal1)); 19 | Assert.assertTrue(patterns.contains(goal2)); 20 | } 21 | 22 | /** 23 | * 2. acomp(V,A)+nsubj(V,N)→< N,A > 24 | */ 25 | @Test 26 | public void Pattern2() { 27 | Pattern goal = new Pattern("camera case", "nice", Pattern.Relation.aspect); 28 | 29 | List patterns = new Extract().run("The camera case looks nice."); 30 | 31 | Assert.assertTrue(patterns.contains(goal)); 32 | } 33 | 34 | /** 35 | * 3. cop(A,V )+nsubj(A,N)→< N,A > 36 | */ 37 | @Test 38 | public void Pattern3() { 39 | Pattern goal1 = new Pattern("screen", "wide", Pattern.Relation.aspect); 40 | Pattern goal2 = new Pattern("screen", "clear", Pattern.Relation.aspect); 41 | 42 | List patterns = new Extract().run("The screen is wide and clear."); 43 | 44 | Assert.assertTrue(patterns.contains(goal1)); 45 | Assert.assertTrue(patterns.contains(goal2)); 46 | } 47 | 48 | /** 49 | * 4. dobj(V,N)+nsubj(V,N')→< N,V > 50 | */ 51 | @Test 52 | public void Pattern4() { 53 | Pattern goal = new Pattern("picture quality", "love", Pattern.Relation.aspect); 54 | 55 | List patterns = new Extract().run("I love the picture quality."); 56 | 57 | Assert.assertTrue(patterns.contains(goal)); 58 | } 59 | 60 | /** 61 | * 5. < h1,m > +conj_and(h1,h2)→< h2,m > 62 | */ 63 | @Test 64 | public void Pattern5() { 65 | Pattern goal1 = new Pattern("zoom", "great", Pattern.Relation.aspect); 66 | Pattern goal2 = new Pattern("resolution", "great", Pattern.Relation.aspect); 67 | 68 | List patterns = new Extract().run("This camera has great zoom and resolution."); 69 | 70 | Assert.assertTrue(patterns.contains(goal1)); 71 | Assert.assertTrue(patterns.contains(goal2)); 72 | } 73 | 74 | /** 75 | * 6. < h,m1 > +conj_and(m1,m2)→< h,m2 > 76 | */ 77 | @Test 78 | public void Pattern6() { 79 | Pattern goal1 = new Pattern("screen", "wide", Pattern.Relation.aspect); 80 | Pattern goal2 = new Pattern("screen", "clear", Pattern.Relation.aspect); 81 | 82 | List patterns = new Extract().run("The screen is wide and clear."); 83 | 84 | Assert.assertTrue(patterns.contains(goal1)); 85 | Assert.assertTrue(patterns.contains(goal2)); 86 | } 87 | 88 | /** 89 | * 6. < h,m1 > +conj_and(m1,m2)→< h,m2 > 90 | */ 91 | @Test 92 | public void Pattern61() { 93 | Pattern goal1 = new Pattern("screen", "love", Pattern.Relation.aspect); 94 | Pattern goal2 = new Pattern("screen", "hate", Pattern.Relation.aspect); 95 | 96 | List patterns = new Extract().run("I love and hate the screen."); 97 | 98 | Assert.assertTrue(patterns.contains(goal1)); 99 | Assert.assertTrue(patterns.contains(goal2)); 100 | } 101 | 102 | /** 103 | * 6. < h,m1 > +conj_and(m1,m2)→< h,m2 > 104 | * This is a shortcoming of the dependency parser as it does not detect acomp 105 | */ 106 | @Test 107 | public void Pattern62() { 108 | Pattern goal1 = new Pattern("screen", "love", Pattern.Relation.aspect); 109 | Pattern goal2 = new Pattern("camera case", "love", Pattern.Relation.aspect); 110 | 111 | List patterns = new Extract().run("I love the screen and the camera case."); 112 | 113 | Assert.assertTrue(patterns.contains(goal1)); 114 | Assert.assertTrue(patterns.contains(goal2)); 115 | } 116 | 117 | 118 | /** 119 | * 7. < h,m > +neg(m,not)→< h, not+m > 120 | */ 121 | @Test 122 | public void Pattern7() { 123 | Pattern goal = new Pattern("battery life", "not long", Pattern.Relation.aspect); 124 | 125 | List patterns = new Extract().run("The battery life is not long"); 126 | 127 | Assert.assertTrue(patterns.contains(goal)); 128 | } 129 | 130 | /** 131 | * 7. < h,m > +neg(m,not)→< h, not+m > 132 | */ 133 | @Test 134 | public void Pattern71() { 135 | //Pattern goal1 = new Pattern("battery life", "good", Pattern.Relation.aspect); 136 | Pattern goal2 = new Pattern("battery life", "not great", Pattern.Relation.aspect); 137 | 138 | List patterns = new Extract().run("The battery life was good but not great"); 139 | 140 | //Assert.assertTrue(patterns.contains(goal1)); 141 | Assert.assertTrue(patterns.contains(goal2)); 142 | } 143 | 144 | /** 145 | * 8. < h,m > +nn(h,N)→< N +h,m > 146 | */ 147 | @Test 148 | public void Pattern8() { 149 | Pattern goal = new Pattern("camera case", "nice", Pattern.Relation.aspect); 150 | 151 | List patterns = new Extract().run("The camera case looks nice."); 152 | 153 | Assert.assertTrue(patterns.contains(goal)); 154 | } 155 | 156 | /** 157 | * 9. < h,m > +nn(N,h)→< h+N,m > 158 | */ 159 | @Test 160 | public void Pattern9() { 161 | Pattern goal = new Pattern("picture quality", "love", Pattern.Relation.aspect); 162 | 163 | List patterns = new Extract().run("I love the picture quality."); 164 | 165 | Assert.assertTrue(patterns.contains(goal)); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/Pattern.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | 3 | public class Pattern { 4 | public String head; 5 | public String headTag; 6 | public String modifier; 7 | public String modifierTag; 8 | public Relation relation; 9 | public Pattern mother; 10 | public Pattern father; 11 | 12 | public Pattern(String head, String modifier, Relation relation) { 13 | 14 | this(head, null, modifier, null, relation); 15 | } 16 | 17 | public Pattern(String head, String headTag, String modifier, String modifierTag, Relation relation) { 18 | 19 | this(head, headTag, modifier, modifierTag, relation, null, null); 20 | } 21 | 22 | public Pattern(String head, String headTag, String modifier, String modifierTag, Relation relation, Pattern mother, Pattern father) { 23 | this.head = head; 24 | this.headTag = headTag; 25 | this.modifier = modifier; 26 | this.modifierTag = modifierTag; 27 | this.relation = relation; 28 | this.mother = mother; 29 | this.father = father; 30 | } 31 | 32 | public static Relation asRelation(String str) { 33 | for (Relation relation : Relation.values()) { 34 | if (relation.name().equalsIgnoreCase(str)) 35 | return relation; 36 | } 37 | return null; 38 | } 39 | 40 | public boolean equals(Object pattern) { 41 | if (!(pattern instanceof Pattern)) { 42 | return false; 43 | } 44 | return ((Pattern) pattern).head.equals(head) 45 | && ((Pattern) pattern).modifier.equals(modifier) 46 | && ((Pattern) pattern).relation.equals(relation); 47 | } 48 | 49 | public int hashCode() { 50 | return (head + modifier + relation).hashCode(); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return head + " " + headTag + " " + modifier + " " + modifierTag + " " + relation; 56 | } 57 | 58 | public String toAspect() { 59 | return head + " " + modifier; 60 | } 61 | 62 | public String toSentences() { 63 | return head + " . " + modifier; 64 | } 65 | 66 | public boolean isPrimaryPattern() { 67 | switch (relation) { 68 | case amod: 69 | return headTag.equals("NN") && modifierTag.startsWith("JJ"); 70 | case acomp: 71 | return headTag.startsWith("VB") && modifierTag.startsWith("JJ"); 72 | case nsubj: 73 | return headTag.startsWith("VB") && modifierTag.equals("NN") 74 | || headTag.startsWith("JJ") && modifierTag.equals("NN") 75 | || headTag.startsWith("VB") && modifierTag.startsWith("PR"); 76 | case cop: 77 | return headTag.startsWith("JJ") && modifierTag.startsWith("VB"); 78 | case dobj: 79 | return headTag.startsWith("VB") && modifierTag.equals("NN"); 80 | case conj_and: 81 | return headTag.equals("NN") && modifierTag.equals("NN") 82 | || headTag.startsWith("JJ") && modifierTag.startsWith("JJ") 83 | || headTag.startsWith("VB") && modifierTag.startsWith("VB"); 84 | case neg: 85 | case conj_but: 86 | return (headTag.startsWith("JJ") || headTag.startsWith("VB")); 87 | case nn: 88 | return headTag.equals("NN") && modifierTag.equals("NN"); 89 | } 90 | 91 | return false; 92 | } 93 | 94 | public Pattern TryCombine(List patterns) { 95 | switch (relation) { 96 | case amod: 97 | return TryCombineAmod(); 98 | case acomp: 99 | return TryCombineAcomp(patterns); 100 | case cop: 101 | return TryCombineCop(patterns); 102 | case dobj: 103 | return TryCombineDobj(patterns); 104 | case aspect: 105 | for (Pattern pattern : patterns) { 106 | Pattern newAspect = null; 107 | switch (pattern.relation) { 108 | case conj_and: 109 | newAspect = TryCombineAspectWithConjAnd(pattern); 110 | break; 111 | case conj_but: 112 | newAspect = TryCombineAspectWithConjBut(pattern); 113 | break; 114 | case neg: 115 | newAspect = TryCombineAspectWithNeg(pattern); 116 | break; 117 | case nn: 118 | newAspect = TryCombineAspectWithNn(pattern); 119 | break; 120 | } 121 | if (newAspect != null) { 122 | return newAspect; 123 | } 124 | } 125 | return null; 126 | } 127 | 128 | return null; 129 | } 130 | 131 | private Pattern TryCombineAspectWithNn(Pattern pattern) { 132 | if (pattern.head == head && pattern.modifierTag.equals("NN")) { 133 | 134 | return new Pattern(pattern.modifier + " " + head, headTag, modifier, modifierTag, Relation.aspect, this, pattern); 135 | } 136 | if (pattern.modifier == head && pattern.headTag.equals("NN")) { 137 | 138 | return new Pattern(head + " " + pattern.head, headTag, modifier, modifierTag, Relation.aspect, this, pattern); 139 | } 140 | 141 | return null; 142 | } 143 | 144 | private Pattern TryCombineAspectWithNeg(Pattern pattern) { 145 | if (pattern.head == modifier 146 | && (pattern.modifier.equals("not") || pattern.modifier.equals("n't"))) { 147 | 148 | return new Pattern(head, headTag, pattern.modifier + " " + modifier, pattern.modifierTag, Relation.aspect, this, pattern); 149 | } 150 | 151 | return null; 152 | } 153 | 154 | private Pattern TryCombineAspectWithConjAnd(Pattern pattern) { 155 | if (pattern.head == head && pattern.modifierTag.equals("NN")) { 156 | 157 | return new Pattern(pattern.modifier, pattern.modifierTag, modifier, modifierTag, Relation.aspect, this, pattern); 158 | } 159 | 160 | if (pattern.head == modifier 161 | && (pattern.modifierTag.startsWith("JJ") 162 | || pattern.modifierTag.startsWith("VB"))) { 163 | 164 | return new Pattern(head, headTag, pattern.modifier, pattern.modifierTag, Relation.aspect, this, pattern); 165 | } 166 | 167 | return null; 168 | } 169 | 170 | private Pattern TryCombineAspectWithConjBut(Pattern pattern) { 171 | if (pattern.head == modifier 172 | && (pattern.modifierTag.startsWith("RB"))) { 173 | 174 | return new Pattern(head, headTag, pattern.modifier + " " + pattern.head, pattern.headTag, Relation.aspect, this, pattern); 175 | } 176 | 177 | return null; 178 | } 179 | 180 | private Pattern TryCombineDobj(List patterns) { 181 | for (Pattern pattern : patterns) { 182 | if (pattern.relation == Pattern.Relation.nsubj 183 | && pattern.headTag.startsWith("VB") 184 | && pattern.modifierTag.startsWith("PR") 185 | && !pattern.modifier.equals(modifier)) { 186 | 187 | return new Pattern(modifier, modifierTag, head, headTag, Relation.aspect, this, pattern); 188 | } 189 | } 190 | 191 | return null; 192 | } 193 | 194 | private Pattern TryCombineCop(List patterns) { 195 | for (Pattern pattern : patterns) { 196 | if (pattern.relation == Pattern.Relation.nsubj 197 | && pattern.headTag.startsWith("JJ") 198 | && pattern.modifierTag.equals("NN") 199 | && pattern.head.equals(head)) { 200 | 201 | return new Pattern(pattern.modifier, pattern.modifierTag, head, headTag, Relation.aspect, this, pattern); 202 | } 203 | } 204 | 205 | return null; 206 | } 207 | 208 | private Pattern TryCombineAcomp(List patterns) { 209 | for (Pattern pattern : patterns) { 210 | if (pattern.relation == Pattern.Relation.nsubj 211 | && pattern.headTag.startsWith("VB") 212 | && pattern.modifierTag.equals("NN") 213 | && pattern.head.equals(head)) { 214 | 215 | return new Pattern(pattern.modifier, pattern.modifierTag, modifier, modifierTag, Relation.aspect, this, pattern); 216 | } 217 | } 218 | 219 | return null; 220 | } 221 | 222 | private Pattern TryCombineAmod() { 223 | return new Pattern(head, headTag, modifier, modifierTag, Relation.aspect); 224 | } 225 | 226 | public enum Relation { 227 | amod, 228 | acomp, 229 | nsubj, 230 | cop, 231 | dobj, 232 | conj_and, 233 | neg, 234 | conj_but, 235 | nn, 236 | aspect 237 | } 238 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Opinion Phrases 2 | ======= 3 | 4 | 5 | In [Predicting what user reviews are about with LDA and gensim](http://www.vladsandulescu.com/topic-prediction-lda-user-reviews/) I played with extracting topics from short reviews and given a new review, tried to predict the most probable topic(s) it can be associated with. LDA relies on a bag-of-words model, which is a very popular document representation approach. The model disregards any syntactic dependencies between the words, i.e. any grammar, as well as word order in the documents. For a deeper read about the assumptions made by the LDA model, try to digest [Blei's paper](http://machinelearning.wustl.edu/mlpapers/paper_files/BleiNJ03.pdf)...if you dare! 6 | 7 | Anyway, much of the research on opinion mining used the bag-of-words model, but as [Samaneh Abbasi Moghaddam](http://www.sfu.ca/~sam39/) also suggests in her PhD thesis [Aspect-based opinion mining in online reviews](http://summit.sfu.ca/item/12790), it is not clear whether this approach is actually the most effective. Instead, she experimented with a LDA model based on opinion phrases. The full details are found in her paper, but I will make a short summary of the method. 8 | In a nutshell, she concluded that bag-of-opinion phrases outperform the bag-of-words topic models and using the grammar relationships outperforms the existing preprocessing techniques in extracting aspects from user reviews. 9 | 10 | **What is an opinion phrase, anyway?** 11 |
12 | An opinion phrase is defined as a pair (aspect, sentiment) like *camera nice* or *room clean*. This is the stuff that people are generally interested in when reading a review, these key points that sum up a user's experience with the product. A very simple way to extract these pairs is to look for nouns and then pick the nearest adjective around it. This approch has obvious shortcomings. 13 | 14 | Luckily, we are contemporary with some clever Stanford guys who made the [Stanford CoreNLP](http://nlp.stanford.edu/software/corenlp.shtml) tool. Given a sentence, it can extract syntactic dependencies between words, output the words' base forms and even predict the overall sentiment of a text. 15 | 16 | **What syntactical relations should be exploited?** 17 |
18 | The following grammatical dependencies are used to extract and construct the opinion phrases inside a short sentence. They are all present and explained in her PhD thesis. 19 | The [Stanford typed dependencies manual](http://nlp.stanford.edu/software/dependencies_manual.pdf) explains very well the grammatical representations used below. 20 | 21 | In order to end-up with opinion phrases, first, basic patterns are extracted: 22 |
23 | 1. Adjectival complement (acomp): *The camera looks nice*, parsed to *acomp(nice, looks)*. 24 |
25 | 2. Adjectival modifier (amod): *This camera has great zoom* parsed to *amod(zoom, great)*; 26 |
27 | 3. "And" conjunct (conj and): *This camera has great zoom and resolution* parsed to *conj and(zoom, resolution)*. 28 |
29 | 4. Copula (cop): *The screen is wide* parsed to *cop(wide, is)*. 30 |
31 | 5. Direct object (dobj): *I love the quality* parsed to *dobj(love, quality)*. 32 |
33 | 6. Negation modifier (neg): *The battery life is not long* parsed to *neg(long, not)*. 34 |
35 | 7. Noun compound modifier (nn): *The battery life is not long* parsed to *nn(life, battery)*. 36 |
37 | 8. Nominal subject (nsubj): *The screen is wide* parsed to *nsubj(wide, screen)*. 38 | 39 | The simple patterns are then combined in a tree-like manner to obtain more valuable opinion phrases. (N indicates a noun, A an adjective, V a verb, h a head term, m a modifier, and < h, m > an opinion phrase)[1]. 40 | 41 | 1.amod(N, A) →< N, A > 42 | *This camera has great zoom and resolution → (zoom, great)* 43 |
44 | 2.acomp(V, A) + nsubj(V, N) →< N, A > 45 | *The camera case looks nice --> (case, nice)* 46 |
47 | 3. cop(A, V ) + nsubj(A, N) →< N, A > 48 | *The screen is wide and clear --> (screen, wide)* 49 |
50 | 4. dobj(V, N) + nsubj(V, N0) →< N, V > 51 | *I love the picture quality --> (picture, love)* 52 |
53 | 5. < h1, m > +conj and(h1, h2) →< h2, m > 54 | *This camera has great zoom and resolution --> (zoom, great), (resolution, great)* 55 |
56 | 6. < h, m1 > +conj and(m1, m2) →< h, m2 > 57 | *The screen is wide and clear --> (screen, wide), (screen, clear)* 58 |
59 | 7. < h, m > +neg(m, not) →< h, not + m > 60 | *The battery life is not long --> (battery life, not long)* 61 |
62 | 8. < h, m > +nn(h, N) →< N + h, m > 63 | *The camera case looks nice --> (camera case, nice)* 64 |
65 | 9. < h, m > +nn(N, h) →< h + N, m > 66 | *I love the picture quality --> (picture quality, love)* 67 | 68 | Of course, these syntactical relations can be improved further on by looking up more combined patterns - did not think about this too much, but I have a gut feeling there are more combined patterns out there. 69 | 70 | **Pruning the extracted patterns** 71 |
72 | As you can see in the code if you look in the [GitHub repository](https://github.com/vladsandulescu/phrases), the pruning step is quite important, as the "tree leafs" are the most significant patterns to keep, the final ones. 73 | I wanted opinion phrases like *fish had* and *bill paid* to go away, so I added the usual [stopwords](http://www.lextek.com/manuals/onix/stopwords2.html) removal to the pruning step. This basically means eliminating the patterns which contain any stopword. 74 | 75 | **Some results** 76 |
77 | Given a real-life user review: 78 |
79 | *Great food and atmosphere. Plenty of TVs to watch the games. The chef and his partners just opened this great location. Pumpkin Soup with pumpkin oil and croutons is such a great start to the Fall season. Wood fired oven pumping out flatbreads. Sweet Potato gnocchi made in house with roasted corn and gorgonzola crema is unbelievable. Very impressive selection of beer handles and delicious cocktails. Amazing view of the sunset as well. Can't wait to return.* 80 | 81 | the extracted opinion phrases were: 82 |
83 | ["atmosphere Great", "food Great", "location great", "start great", "corn roasted", "gorgonzola crema roasted", "selection impressive", "view Amazing"] 84 | 85 | Pretty good right? 86 | 87 | Here's another one: 88 |
89 | *This place is amazing. I come here at least once a month & am never disappointed. Food & service is always great. The buffalo burger it TDF as well as the bruschetta. Outside seating is so cute with a lights (great for date nights) live music inside is a wonderful touch. This place is great to meet with friends, family or date night.* 90 | 91 | opinion phrases: 92 |
93 | ["place amazing", "service great", "burger buffalo", "seating cute", "touch wonderful", "seating Outside", "place great"] 94 | 95 | By now, it should be pretty obvious to see how easier aggregating after specific aspects such as *place* and *service* is. 96 | 97 | Another one: 98 |
99 | *The mailing pack that was sent to me was very thorough and well explained,correspondence from the shop was prompt and accurate,I opted for the cheque payment method which was swift in getting to me. All in all, a fast efficient service that I had the upmost confidence in,very professionally executed and I will suggest you to my friends when there mobiles are due for recycling :-)* 100 | 101 | opinion phrases: 102 |
103 | ["correspondence, prompt", "correspondence, accurate", "service, efficient"] 104 | 105 | OK, one more and that's it: 106 |
107 | *Aside from the wait to order and the other wait to get your food! I was there for a late lunch on Friday and I opted to forgo my usual salad choice and go for the eggplant parm sandwich - yum! Each bite of perfectly crusted eggplant had the most amazing tangy tomato sauce and melted cheese and it was oh so dlvine! I had it on wheat bread and finished my entire sandwich (and yes, I ordered a full size!) What a treat! Don't try to special order at the restaurant - my boyfriend attempted to create his own sandwich and what he ended up with was nothing close to what he ordered. I can't wait to go back to 'make my own pizza' - i know about that thanks to him! I have a feeling that I'll be visiting this place quite a bit since I'm now living in the area after a recent move. It's a good thing - well, it's a tasty thing, maybe not so good for the waistline!* 108 | 109 | opinion phrases: 110 |
111 | ["salad choice usual", "lunch late", "salad choice forgo", "tomato sauce amazing", "eggplant crusted", "tomato sauce tangy", "sandwich finished", "sandwich entire", "size ordered", "size full", "sandwich create", "order special", "pizza make", "move recent", "bit visiting", "thing good", "thing tasty"] 112 | 113 | In this last one, you may notice phrases like *thing good*, *sandwich entire*, *sandwich finished* and *sandwich create*, which don't really help much in any aggregation, so it would be nice to eliminate them. 114 | This could easily be done by cleverly and time-consumingly shove words like *thing*, *entire* and *create* into the stopwords list. Otherwise, the LDA model should filter these out, assuming a lot of people don't mention the exact phrases. 115 | 116 | Check out the [code repository](https://github.com/vladsandulescu/phrases), try extracting opinion phrases by running the code yourself and don't forget to tweet to me if you have any comments. 117 | 118 | The code is written in Java and it requires Stanford CoreNLP 3.4, Stanford Parser, JUnit and Mongo Java driver (if you plan to run it over many reviews stored in Mongo, because why wouldn't you already keep the reviews in Mongo right?). 119 | If you do not want to use Mongo, just call the *run* method in *Extract* class giving it the text to extract opinion phrases from. 120 | 121 | That is basically it. 122 | 123 | ================== 124 | [1]: [Abbasi Moghaddam, Samaneh. Aspect-based opinion mining in online reviews. Diss. Applied Sciences: School of Computing Science, 2013.](http://summit.sfu.ca/item/12790) 125 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------