Package: chatdb
ChatDB for NLPChatDB is a toolkit to easily store the conversation such as chat messages in a database. You can use ChatDB as a way of storing text in a stage of collecting data for NLP.DBMS:Neo4jInstallationYou can choose either A or B.A. The case to use Neo4j DesktopIf you will work on a host OS and use Neo4j Desktop, it is recommended to install ChatDB from the PyPI:pipinstallchatdbDownload Neo4j Desktop from the following:https://neo4j.com/download/B. The case to use Neo4j on a Docker containerYou can use Git to clone the repository from GitHub:gitclonehttps://github.com/A03ki/chatdb.gitcdchatdbIf you will work on a host OS:pipinstall-e.
docker-composeup-ddbIf you will work on a docker container:docker-composeup-d
docker-composeexecapp/bin/sh-c"[ -e /bin/bash ] && /bin/bash || /bin/sh"UsageFirst, store the text data in a database.fromchatdbimportGraph,Status# Create Statuss1=Status(text="How are you today?")s2=Status(text="I’m okay, thanks. And you?")s3=Status(text="I’m awesome.")# Construct a relationship between Statusess1.reply_from(s2)# s2.reply_to(s1)s2.reply_from(s3)# s3.reply_to(s2)# Create the handler for Neo4j# Work on a docker containergraph=Graph("bolt://db:7687",password="your_password")# Work on a host OS# graph = Graph("bolt://localhost:7687", password="your_password")# Store datagraph.merge(s2)Next, extract the text from a database.fromchatdbimportGraph,TextOutputer,Statusgraph=Graph("bolt://db:7687",password="your_password")# graph = Graph("bolt://localhost:7687", password="your_password")outputer=TextOutputer(graph)print(outputer.match([Status]).extract_text())print(outputer.match([Status]*2).extract_text())print(outputer.match([Status]*3).extract_text())Output:[['I’m okay, thanks. And you?'], ['How are you today?'], ['I’m awesome.']]
[['I’m okay, thanks. And you?', 'I’m awesome.'], ['How are you today?', 'I’m okay, thanks. And you?']]
[['How are you today?', 'I’m okay, thanks. And you?', 'I’m awesome.']]You can also use the Neo4j Browser to check data.Try to go tohttp://localhost:7474in your web browser and run the query which isMATCH (n:Status) RETURN n.https://raw.githubusercontent.com/optuna/optuna/master/How to delete all data:MATCH (n:Status) DETACH DELETE nFor more information on how to use Neo4j Browser, seehttps://neo4j.com/developer/neo4j-browser/.Support for collecting Tweet datapipinstalltweepyThis example will store the timeline of Twitter, Inc and the tweet which this account are replying to.importtweepyfromchatdbimportGraph,SimpleTweetStatusfromchatdb.toolsimportTweetArchiverauth=tweepy.OAuthHandler(consumer_key,consumer_secret)auth.set_access_token(access_token,access_token_secret)api=tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)graph=Graph("bolt://db:7687",password="your_password")# graph = Graph("bolt://localhost:7687", password="your_password")archiver=TweetArchiver(graph,SimpleTweetStatus)statuses=api.user_timeline(screen_name="Twitter")forstatusinstatuses:in_reply_to_status_id_str=status.in_reply_to_status_id_strifin_reply_to_status_id_str:in_reply_to_status=api.get_status(in_reply_to_status_id_str)archiver.add_status(**in_reply_to_status._json)archiver.add_status(**status._json)For more information on how to use Tweepy, seeTweepy Documentation.