Search keyword(s) that matches data in MySQL (on level) - mysql

Recently I started a project, but now i have a little problem.. I need to make a point system:
When user write a post(like blog post), his post is analyzed by a script( using keyword from database).
The problem is that my keyword have to be on 10 levels.
For ex:
Keyword Level 1 = angry
Keyword Level 2 = be happy
Ok.. when i write :" I'm so angry today" I need to receive level 1(but just in background to use that result for arrange the sentence "I'm so angry today" to his level.
Can somebody help me? (MySql)
Have a nice day!

Related

New Item not displaying properly in-game

I've created my first weapon (item ID: 90000 | display ID: 42070) using Keira. I restarted the DB and clear the cache on the client. I spawned the weapon onto my character, but I get a question mark in the inventory. When I equip the weapon and the character is attacking I can see the weapon , but when it is sheath I can't see the weapon.
I've looked at several conversations that speak about patching the client, but its way over my current pay grade. I need to learn how to do this if I want to continue to create content. Where can I go to learn the skills that I am missing? or who can teach me how to fish so that I can fish for myself? Please advise...
~ tinywolf
You can do a workaround on this by changing a weapon that is already in the game in Keira3
Unless u have created a completely new model u maybe just wanna change another that already has the look

solr highlighting not working for long words

I am using Solr 6.2. I want to get the matched words by using highlight option.
When I search with the word "miss" I can get the highlights. But I cant get results for the word "missing".
For Example:
when I search with "miss" I can get the below results:
http://localhost:8983/solr/logbook1/select?debugQuery=on&defType=dismax&defType=edismax&hl.fl=*&hl=on&indent=on&q=miss&rows=5&wt=json
highlighting":{
"3246a347-874a-44e2-bb3d-949a358f435d":{
"String1":["IN REFERENCE CABIN LOG PAGE 22838. TWO EXTENSION SEAT BELT <em>MISS</em> ING"]},
"46a340f8-949f-41fe-b2ee-c1936bfc6b4f":{
"String1":["IN REFERENCE CABIN LOG PAGE 22838. TWO EXTENSION SEAT BELT <em>MISS</em> ING"]},
"df6eef1c-971d-48f7-a93a-07874011ae5b":{
"String1":["ACCESS PANEL 343EB ON R/H HORIZONTAL STAB FOUND WITH SCREW <em>MISS</em> ING AND LOOSE"]},
"9a124f6d-f32b-4e24-beb2-11f7aa22894d":{
"String1":["AFT GALLEY # 4 COFFEE MAKER SHIELDS ON COMPT 419 - 420 ARE <em>MISS</em> ING."]}},
When I search with missing, I am getting no result as below:
http://localhost:8983/solr/logbook1/select?debugQuery=on&defType=dismax&defType=edismax&hl.fl=*&hl=on&indent=on&q=missing&rows=5&wt=json
"highlighting":{
"0d2963a7-adea-40ab-af0a-bb8fe069c4d9":{},
"9f23f4c0-6989-471d-8c61-4016a8e38813":{},
"c77b6be1-547c-43fe-94f0-ae5c0849eab4":{},
"f5792594-7fd2-42b5-92c4-03257c05adba":{},
"68d9251a-74d9-409e-84ec-a67a0eb94866":{}},
I have checked the fragsize options. Please guide is there anything to configure.
1) So i assume you already of lowercase filter on your index field as it will fetch upper and lower case results.
2) And have you added extra space between miss + ing ? if yes you need to remove that and have a try.
3) Please check stop word dictionary if you haven't accidentally added missing there as they get ignored in searching.
4)Try Analyzer from solr to see how to transforms your search term, analyzer is available in solrconsole.
Have you set indexed and stored to true?
For me it looks like, that there are probably different setting for token-handling on indexing and search time. Take a look at your schema.xml an try to work with same settings for indexing and searching.

Unable to get json into an array

I have this data in a file named books.json that I am trying to get into an array.
{
"date_reviewed":"08/Jan/16",
"fname":"John",
"mname":"",
"lname":"Locke",
"email":"",
"title":"Boxed In!",
"imagelocation":"img\book_covers\BoxedIn.jpg",
"series_name":"Dr. Gideon Box",
"sellerssite":"https://www.amazon.com/Boxed-Gideon-Donovan-Creed-Novel-ebook/dp/B019HANKW8",
"genre":"Thriller,Suspence",
"authorsite":"https://johnlockeauthor.wordpress.com/",
"facebook":"https://www.facebook.com/john.locke.395669?fref=ts",
"fbid":"John Locke",
"twitter":"https://twitter.com/DonovanCreed",
"twitterid":"#DonovanCreed",
"review":"A series you have to be sick to love. I guess that's telling as I do love the series.
The latest in a series from an author that also has a number of other series that I have been devouring for the last couple of years. What makes these series unique is that they are all tied together by the characters that star in each series. So, if you're a fan of one and have not branched out into the others then it is time to go to his author page and start the reading adventure that will take you into the minds of a lethal assassin, a gunfighter and reluctant sheriff, and a private detective made famous by escaping from a deranged kidnapper.
Dr. Box may be brilliant when it comes to saving the life of children written off as lost causes but his activities outside the operating room have left any that know him with a strong desire to see him thrown into the bowels of hell as he surely is the very epitome of demon walking the earth. Good thing that he's the only one in the world that can save a life that others deem impossible. Just pray that if you've ever slighted him that you never show up in his hospital under his care. It will be an encounter you never live to regret.
In this tale Dr. Box is visited by the only man that causes true fear in a doctor who's moral compass was broken at birth. Donovan Creed. An assassin that you do not want to owe a favor to.
Donovan comes to collect. He has the plan to kill a terrorist and in the process save thousands of lives. The only problem, what he wants is the one thing Dr. Box cannot do.
Painted into a box (pun intended) he has no choice but to call on the one person that even Donovan is afraid of. Rose.
Together they come up with a full proof plan. Too bad that Donovan is already two steps ahead and the consequences for Dr. Box are steep and his life may never be the same.
As a fan, I say you have to add this to your library.",
"rating":"5"
}
I then retrieve then encode the data to escape the special characters in the data.
<?php
//Get data from existing json file
$jsondata = file_get_contents("books.json");;
$arr_data = json_encode($jsondata, true);
?>
I tried to then place that in an array but that failed so I thought maybe I had to decode it and place it into the array so I tried this code.
$Adata = json_decode($arr_data, true);
echo $Adata['fname'];
So putting that all together you have the following that produces and error "Warning: Illegal string offset 'fname'"
<?php
//Get data from existing json file
$jsondata = file_get_contents("books.json");;
$arr_data = json_encode($jsondata, true);
$Adata = json_decode($arr_data, true);
echo $Adata['fname'];
?>
I would appreciate any help. My ultimate goal is to get the data into an array so I can feed it to my code to instert it into my DB.
you code edit to this:
$jsondata = file_get_contents("books.json");
$arr_data = json_decode($jsondata, true);
echo $arr_data['fname']; //shoud print out: John

Banned words checking algo

I am building a text chat system. I want to add the ability to check for banned words/phrases.
The only technique I can think of, and can't believe it could possibly be the best approach is to do a FOR loop through all the words and search for matches in the text. This seems like it would be unbelievably slow once lots of words are added.
I'm using AS3, but an answer in most any language would probably be useful.
take care,
lee
use an AS3 dictionary or a dict in python and just check if the word is in the dict. there is no way I can see to not go over all the words.
Consider concatenating all the entries in your Dictionary into a single RegExp, with which you have to parse the text only once. I've done some testing, and it's going to be way faster than replacing word for word.
function censorWithDictionary ( dict:Dictionary, text:String ) : String {
var reg : String = "";
for (var key:Object in dict)
{
reg += reg=="" ? "" : "|"; // add an "or" for multiple search words
reg += "\\b"+dict[key]+"\\b"; // only whole words
}
var regExp : RegExp = new RegExp ( reg, "gi" );
return text.replace ( regExp, "----" );
}
I had a similar problem - we run a gaming site and wanted to introduce a chat system which was not manually moderated. We went the "banned word" route and it's working really well.
I just counted them and we now have a list of (just) 79 banned words which originated from something I found on-line to which we have added words over time when chat messages crept through.
The way we check things is that we concatenate an entire chat message by removing all spaces and none alpha characters and then search for banned words in what's left.
The key decisions we made are:
Don't tell people why you rejected their messages
Don't let people post chat until you trust them a bit (on our site they have
to have played 3 games)
5 "Bad" messages and we automatically block you
We email a report out daily with all the chat which got through which we scan through
We allow other users to complain about posted messages - if that happens the message is automatically removed so we can check it later.
1+3+5 Hardly ever happen now and it works wonderfully even though - sometimes messages like
"I wish it was hot!"
Are rejected (the clue is the "sh" part of wish and "it") but even that doesn't happen often.
This is more a comment than an answer, but comments are limited in length and there're big issues here.
I believe you are fundamentally asking the wrong question!
Certainly dictionaries and blacklist would highlight words or phrases that you want to ban but would that list be acceptable to users of your system? Would there be text that users of your system find offensive but you do not. Who decides?
For example, would people living here have trouble or indeed people living here. What if you supported this football/soccer team. This person probably never visits the UK.
Then you get into the issue of anagrams and slang. FCUK is a high street brand in the UK (and elsewhere I'm sure). And then there's pr0n (no link!) or NAMBLA.
The real question is - How do I stop people using the system from using language that is generally unacceptable? And that's more a design / social engineering problem than a programming problem. I don't think this site has word / phrase filtering and yet there's nothing here that would cause offense to anyone.
Here's an idea - let your users decide what is acceptable! Use a reputation based system. Allow users to vote up users who behave and vote down users that cause offense (with the option of allowing users to give feedback on the vote to give them a chance to mend their ways) and then have an option to filter out users with low / negative reputations.

How can I program a simple chat bot AI?

I want to build a bot that asks someone a few simple questions and branches based on the answer. I realize parsing meaning from the human responses will be challenging, but how do you setup the program to deal with the "state" of the conversation?
It will be a one-to-one conversation between a human and the bot.
You probably want to look into Markov Chains as the basics for the bot AI. I wrote something a long time ago (the code to which I'm not proud of at all, and needs some mods to run on Python > 1.5) that may be a useful starting place for you: http://sourceforge.net/projects/benzo/
EDIT: Here's a minimal example in Python of a Markov Chain that accepts input from stdin and outputs text based on the probabilities of words succeeding one another in the input. It's optimized for IRC-style chat logs, but running any decent-sized text through it should demonstrate the concepts:
import random, sys
NONWORD = "\n"
STARTKEY = NONWORD, NONWORD
MAXGEN=1000
class MarkovChainer(object):
def __init__(self):
self.state = dict()
def input(self, input):
word1, word2 = STARTKEY
for word3 in input.split():
self.state.setdefault((word1, word2), list()).append(word3)
word1, word2 = word2, word3
self.state.setdefault((word1, word2), list()).append(NONWORD)
def output(self):
output = list()
word1, word2 = STARTKEY
for i in range(MAXGEN):
word3 = random.choice(self.state[(word1,word2)])
if word3 == NONWORD: break
output.append(word3)
word1, word2 = word2, word3
return " ".join(output)
if __name__ == "__main__":
c = MarkovChainer()
c.input(sys.stdin.read())
print c.output()
It's pretty easy from here to plug in persistence and an IRC library and have the basis of the type of bot you're talking about.
Folks have mentioned already that statefulness isn't a big component of typical chatbots:
a pure Markov implementations may express a very loose sort of state if it is growing its lexicon and table in real time—earlier utterances by the human interlocutor may get regurgitated by chance later in the conversation—but the Markov model doesn't have any inherent mechanism for selecting or producing such responses.
a parsing-based bot (e.g. ELIZA) generally attempts to respond to (some of the) semantic content of the most recent input from the user without significant regard for prior exchanges.
That said, you certainly can add some amount of state to a chatbot, regardless of the input-parsing and statement-synthesis model you're using. How to do that depends a lot on what you want to accomplish with your statefulness, and that's not really clear from your question. A couple general ideas, however:
Create a keyword stack. As your human offers input, parse out keywords from their statements/questions and throw those keywords onto a stack of some sort. When your chatbot fails to come up with something compelling to respond to in the most recent input—or, perhaps, just at random, to mix things up—go back to your stack, grab a previous keyword, and use that to seed your next synthesis. For bonus points, have the bot explicitly acknowledge that it's going back to a previous subject, e.g. "Wait, HUMAN, earlier you mentioned foo. [Sentence seeded by foo]".
Build RPG-like dialogue logic into the bot. As your parsing human input, toggle flags for specific conversational prompts or content from the user and conditionally alter what the chatbot can talk about, or how it communicates. For example, a chatbot bristling (or scolding, or laughing) at foul language is fairly common; a chatbot that will get het up, and conditionally remain so until apologized to, would be an interesting stateful variation on this. Switch output to ALL CAPS, throw in confrontational rhetoric or demands or sobbing, etc.
Can you clarify a little what you want the state to help you accomplish?
Imagine a neural network with parsing capabilities in each node or neuron. Depending on rules and parsing results, neurons fire. If certain neurons fire, you get a good idea about topic and semantic of the question and therefore can give a good answer.
Memory is done by keeping topics talked about in a session, adding to the firing for the next question, and therefore guiding the selection process of possible answers at the end.
Keep your rules and patterns in a knowledge base, but compile them into memory at start time, with a neuron per rule. You can engineer synapses using something like listeners or event functions.
I think you can look at the code for Kooky, and IIRC it also uses Markov Chains.
Also check out the kooky quotes, they were featured on Coding Horror not long ago and some are hilarious.
I think to start this project, it would be good to have a database with questions (organized as a tree. In every node one or more questions).
These questions sould be answered with "yes " or "no".
If the bot starts to question, it can start with any question from yuor database of questions marked as a start-question. The answer is the way to the next node in the tree.
Edit: Here is a somple one written in ruby you can start with: rubyBOT
naive chatbot program. No parsing, no cleverness, just a training file and output.
It first trains itself on a text and then later uses the data from that training to generate responses to the interlocutor’s input. The training process creates a dictionary where each key is a word and the value is a list of all the words that follow that word sequentially anywhere in the training text. If a word features more than once in this list then that reflects and it is more likely to be chosen by the bot, no need for probabilistic stuff just do it with a list.
The bot chooses a random word from your input and generates a response by choosing another random word that has been seen to be a successor to its held word. It then repeats the process by finding a successor to that word in turn and carrying on iteratively until it thinks it’s said enough. It reaches that conclusion by stopping at a word that was prior to a punctuation mark in the training text. It then returns to input mode again to let you respond, and so on.
It isn’t very realistic but I hereby challenge anyone to do better in 71 lines of code !! This is a great challenge for any budding Pythonists, and I just wish I could open the challenge to a wider audience than the small number of visitors I get to this blog. To code a bot that is always guaranteed to be grammatical must surely be closer to several hundred lines, I simplified hugely by just trying to think of the simplest rule to give the computer a mere stab at having something to say.
Its responses are rather impressionistic to say the least ! Also you have to put what you say in single quotes.
I used War and Peace for my “corpus” which took a couple of hours for the training run, use a shorter file if you are impatient…
here is the trainer
#lukebot-trainer.py
import pickle
b=open('war&peace.txt')
text=[]
for line in b:
for word in line.split():
text.append (word)
b.close()
textset=list(set(text))
follow={}
for l in range(len(textset)):
working=[]
check=textset[l]
for w in range(len(text)-1):
if check==text[w] and text[w][-1] not in '(),.?!':
working.append(str(text[w+1]))
follow[check]=working
a=open('lexicon-luke','wb')
pickle.dump(follow,a,2)
a.close()
here is the bot
#lukebot.py
import pickle,random
a=open('lexicon-luke','rb')
successorlist=pickle.load(a)
a.close()
def nextword(a):
if a in successorlist:
return random.choice(successorlist[a])
else:
return 'the'
speech=''
while speech!='quit':
speech=raw_input('>')
s=random.choice(speech.split())
response=''
while True:
neword=nextword(s)
response+=' '+neword
s=neword
if neword[-1] in ',?!.':
break
print response
You tend to get an uncanny feeling when it says something that seems partially to make sense.
I would suggest looking at Bayesian probabilities. Then just monitor the chat room for a period of time to create your probability tree.
I'm not sure this is what you're looking for, but there's an old program called ELIZA which could hold a conversation by taking what you said and spitting it back at you after performing some simple textual transformations.
If I remember correctly, many people were convinced that they were "talking" to a real person and had long elaborate conversations with it.
If you're just dabbling, I believe Pidgin allows you to script chat style behavior. Part of the framework probably tacks the state of who sent the message when, and you'd want to keep a log of your bot's internal state for each of the last N messages. Future state decisions could be hardcoded based on inspection of previous states and the content of the most recent few messages. Or you could do something like the Markov chains discussed and use it both for parsing and generating.
If you do not require a learning bot, using AIML (http://www.aiml.net/) will most likely produce the result you want, at least with respect to the bot parsing input and answering based on it.
You would reuse or create "brains" made of XML (in the AIML-format) and parse/run them in a program (parser). There are parsers made in several different languages to choose from, and as far as I can tell the code seems to be open source in most cases.
You can use "ChatterBot", and host it locally using - 'flask-chatterbot-master"
Links:
[ChatterBot Installation]
https://chatterbot.readthedocs.io/en/stable/setup.html
[Host Locally using - flask-chatterbot-master]: https://github.com/chamkank/flask-chatterbot
Cheers,
Ratnakar