Repository navigation
Expand file tree
/
Copy pathquery-classifier.js
More file actions
27 lines (23 loc) · 14.2 KB
/
Copy pathquery-classifier.js
File metadata and controls
27 lines (23 loc) · 14.2 KB
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
// train-model.js
// trains a naive Bayesian classifer on Dear Abby prompts
var natural = require('natural'), classifier = new natural.BayesClassifier();
//classifier.addDocument('I\'m 22 and my mom is probably my best friend. She\'s from Lebanon and grew up during a time of war. Her culture taught her to sacrifice -- to put the needs of others before her own. She has a good job and earns an excellent salary. My father is retired. Their marriage is not a good one, and Mom is in sort of a rut. She dresses sloppy and buys only "bargains." Her hair is always a mess. Every time we go shopping, it\'s a fight because I want her to buy the nice clothes she can afford. I want her to be presentable. But she\'s stubborn and always makes an excuse for why she "doesn\'t need them" or "can\'t get them." How should I handle this situation?','concern for mother');
//classifier.addDocument('Up to this point in my academic career, I have always been known for being a smart, diligent student. I graduated from high school with academic accolades and one of the highest GPAs in the graduating class. However, since starting college this semester, I have become apathetic toward school, as if to say, "I have worked this hard already; why bother working anymore?" Because of this, I\'m failing most of my classes -- as only a freshman, mind you. Although I recognize my attitude is terrible, I haven\'t been able to get rid of it and get to work again.I\'m confused about where this apathy came from, and I don\'t want it to get any worse. Would you have any ideas as to why I might feel this way, and possible suggestions about how to get myself back on track?','apathy about school');
//classifier.addDocument('My sister "Adele" chose to adopt a baby boy when she was in her late 50s. She isn\'t married. Before the adoption, she asked me if something happened to her, would I take care of the child. I had already raised my children and was going through a divorce, so I said, "No. I\'m too old and I want to enjoy my future retirement." She got mad. Adele is now approaching 70 with a high-maintenance 12-year-old son she has signed up for every extracurricular activity under the sun. I have seen him twice since the adoption. If and when the question comes up again, how do I handle it?','concern about adoption');
classifier.addDocument('I recently tried to retrieve my e-mail when my husband\'s e-mail account popped up. I noticed a few messages from one particular woman, and curiosity got the better of me. I opened them and discovered she and my husband have been chatting online. (His e-mail to her indicates they have "hot" conversations.) When I confronted my husband, he said it only happened a few times. I told him it\'s a form of cheating. He insists it has nothing to do with his love for me -- that it is a fantasy thing. I don\'t care for his explanation, and I\'m taking it personally. I can\'t forget the things I read and I\'m considering ending our marriage. Because he is not carrying on a physical relationship with someone doesn\'t mean his online relationship isn\'t as damaging. Do you agree?','suspected cheating');
classifier.addDocument('I have been in a committed relationship with my girlfriend for about one year now. We first met during freshman year of college but started dating our senior year. We now live together, and both have good jobs in Atlanta. She asked could she go with her girlfriends to New York for NBA All-Star Weekend. Although I had some doubts, I convinced myself that it would be OK because I trust her. However, when she got back, things seemed a little backward with her. So I began to ask about her experience, and she acted as if everything was fine. Looking at some of her Instagram photographs, I noticed she had met a lot of celebrities, but I knew that would be the norm for that type of weekend. I don\'t want to jump to conclusions, but I think my girlfriend may have cheated on me while in New York. Any thoughts?','suspected cheating');
classifier.addDocument('You have helped so many people, I hope you can help me. I have been married more than 20 years, and we have two lovely daughters. Everything was fine until my wife started to work as a secretary for a bank branch manager. When I found out they had been having an affair for nearly two years, it crushed me. I asked my wife if she wanted a divorce, and she said, "No." I didn\'t either for the sake of the children and, strange as it sounds, I still loved her. She agreed to quit working there, and about the same time the branch manager got transferred to a branch in another city, so I thought everything was all right. She then took a job as a secretary to an attorney in a law firm. I became suspicious when I would call her at the office at 2 or 3 in the afternoon and was told, "She and Mr. \'Jones\' went to lunch and then to see a client to take a deposition." A private detective discovered that the "deposition" was taking place in a motel! When I confronted her, she admitted that she and her boss were having an affair. We saw a counselor and our pastor, but my wife insisted it was no big deal and everyone was doing it. She still doesn\'t want a divorce and assured me it was over as far as her cheating goes. She now works in an office with only women, so I\'m hopeful her cheating is a thing of the past. Abby, how do I cope with the second infidelity, since it, too, lasted more than a year? I want to save our marriage because of the kids. I saw a psychiatrist, but he didn\'t help much. Any advice, Abby? I\'m really hurting.','suspected cheating');
classifier.addDocument('I have been in a long-distance relationship with "Victor" for several years. Recently I began to suspect he was cheating. What raised my suspicion was that I suddenly couldn\'t reach him on the weekends. Usually we would Skype -- Sunday night for me, Monday morning for him. Last February when I visited him, I snooped in his phone -- spare me the condemnation. I found an email he had written to an old girlfriend in which he suggested they plan their "next" rendezvous. I plan on dumping him, but I don\'t know how to go about it. I\'ve always been bad at dumping people. Should I write him a letter and confess that I snooped? My first inclination is to disconnect completely and say nothing. I\'m afraid to confront him because he is obviously a good liar. I\'m afraid if I do, he\'ll make me doubt the evidence ... trust me, he\'s that good!','suspected cheating');
classifier.addDocument('I have a conundrum: my boyfriend constantly texts this girl. Not normally an issue, but he fucked her pretty regularly right before he and I got together. He says it was never more than a sexual attraction, but this girlwho has a boyfriend, mind youis in love with him. I know this because my boyfriend has told me so. They don\'t hang out and they don\'t have phone calls, but the texting is bothering me because she\'s clearly not speaking to him as "just a friend." He\'s informed me that, yes, she does flirt with him but he insists he never responds in kind. I\'ve tried to talk to him about it but he doesn\'t think he\'s doing anything wrong because he is respectful of our relationship when he responds to her.','suspected cheating');
classifier.addDocument('I am 18, and like most of my friends, I have gone away to college. We have a friend whose life went off track during our senior year because of drinking, drugs and other misbehavior. She\'s now without a place to live or any support system. She calls us from time to time, and we aren\'t sure what to believe or how to help her since we are all in a different place in our lives, and far away. We won\'t give her money because we are worried about what she might do with it, but we really do want to help her and be there for her. What is the best approach?','other');
classifier.addDocument('I\'m a college sophomore living in a dorm. My best friend lives a few doors down. We have always had a wonderful, caring friendship and many things in common. Lately, however, she has not been spending much time with me. Normally this would not concern me because we are both very busy right now -- but we recently had an argument in which I discovered her inability to handle confrontation. When I brought up my concern, it led to a fight. She burst into tears and said she can\'t handle it when I "yell" at her. Abby, I hadn\'t raised my voice. Later, more calmly, she told me she cannot handle confrontation and will never, under any circumstances, take the first step. This worries me, not only for our friendship, but for her own emotional health. When she doesn\'t want to spend time with me, I wonder whether she\'s angry with me and won\'t say so. This could seriously affect her in her future friendships and romances. I tried to talk to her about addressing her fear of confrontation, perhaps through some sort of therapy. She doesn\'t think she has a problem. I\'d like to help her. Am I right that this could cause her problems?','other');
classifier.addDocument('I have been trying to reach a good friend of mine for several weeks, but he never answers his phone or returns my calls. I find this incredibly annoying. I know that he is busy, but so am I. So the other day, I was looking at Facebook and saw a picture of him at a party that I had also been invited to attend. I got so mad. I get that he went to the party, but if he is out having a great time, why can\'t he give me the respect to return my call? I thought of posting something nasty on Facebook, but I didn\'t. What can I do to make it known that I feel slighted?','other');
classifier.addDocument('One of my friends refuses to leave a toxic relationship. They have been together for two years, but during this time, there has always been drama. He is very protective of her and will freak out whenever the relationship is threatened. He even threatened me once, as well as a couple of her other best friends, and she never did anything about it. Recently, she has been cheating on him with multiple guys. I thought this would be the perfect opportunity for her to end the relationship, but she refuses to leave him, claiming that she loves him too much. I have continually tried to get her to end things, but she refuses and gets defensive. I do not know if I can be friends with her if she continues seeing this guy. How should I approach her about leaving him for good?','other');
classifier.addDocument('Straight-out-of-college female here. I\'ve begun my foray into the real world with my first job at a large firm and, as an added bonus, a hunky, kind man. My relationship is new; we got together in January of this year. I have some work to do on myself: post-abusive relationship and recently uncovered mommy issues have landed me in therapy. I am a work in progress, and he is both aware and supportive. Really feels like this is a potential LTR. The one thing (I call it a thing and not an issue or a problem) is that he is "hung up" on his ex. They dated for two years and had a hard time distancing themselves from each other. From my understanding, he really only cut off communication with her after he met me. They met up recently as she is moving out of state and she contacted him in an attempt to gain closure. He says that their relationship is done but that he has unresolved feelings. When I asked him to explain, he said that he was still attempting to dissect their breakup and that their meeting was supposed to provide clarity. The only thing that is clear is that he didn\'t get what he needed.','other');
classifier.addDocument('My husband, "Sam," and I have been married three years and have a good relationship. He\'s a wonderful father and husband, and I really couldn\'t ask for much more. However, there is one thing I just don\'t know what to do about. He had a rough divorce from his first wife, who was also the first woman he ever had sex with (they waited until they were married). She started doing drugs shortly afterward and cheated on him several times. Counseling with her didn\'t work, and eventually he filed for divorce. We married five years after his divorce, and we also waited to have sex until we were married. This was by mutual agreement. Once we were married, I realized he has some big hang-ups about sex in general. There can never be any foreplay, we never change positions, and the times it happens are few and far between. I have expressed my need for more intimacy, but he acts like I\'m being ridiculous, or says he can\'t make himself change something he\'s comfortable with. How else can I approach this situation without making him feel bad? I believe sex in a marriage is very important, and ours needs to change.','other');
classifier.addDocument('With online dating becoming popular with older people, I have a question. Most of us who were married for a number of years and had a good mate learned a lot about how to make life exciting and are experienced about sex. When we meet someone online and start to become involved, how and when would it be the right time to bring up the subject of sex? For those of us in our later years, sex is usually different than when we were 35. Then there\'s the subject of STDs. Can we bring that up? In rural and small towns, older women, unlike younger women, are shy about talking about sex. When we start to get serious with someone, shouldn\'t we find out what they are willing to do and what they won\'t?','other');
classifier.addDocument('My 11-year-old daughter, "Gwen," just started middle school. She makes good grades, but she\'s strong-willed. Do kids grow up instantly when they start middle school? She wants to know if she can have a boyfriend. I told her not until she\'s 15. Now she\'s flirting with girls who ask her out. I told her to stay away from them, not because they are lesbians but because they are not good girls. They are always in trouble. Gwen says I\'m too strict, and if I don\'t stop, she will run away. I adopted her at birth (it was an open adoption), and she recently asked me if I am going to place her for adoption. She was worried that I would. I am very concerned that she is hanging out with the wrong crowd. Any advice?','other');
classifier.train();
console.log(classifier.classify('i think my wife is cheating on me'));
console.log(classifier.classify('My wife is fantastic. I want to do something to show her how much she means to me. What should I do?'));
console.log(classifier.classify('I\'m worried about my friend, I think she is hurting herself. What can I do?'));