List of greetings phrases in english for NLP task? - machine-learning

I want lists of greetings phrases in English for natural language processing tasks, so I wonder where can I find something like that ?

Hopefully it helps!
["hi", "hello", "hey", "helloo", "hellooo", "g morining", "gmorning", "good morning", "morning", "good day", "good afternoon", "good evening", "greetings", "greeting", "good to see you", "its good seeing you", "how are you", "how're you", "how are you doing", "how ya doin'", "how ya doin", "how is everything", "how is everything going", "how's everything going", "how is you", "how's you", "how are things", "how're things", "how is it going", "how's it going", "how's it goin'", "how's it goin", "how is life been treating you", "how's life been treating you", "how have you been", "how've you been", "what is up", "what's up", "what is cracking", "what's cracking", "what is good", "what's good", "what is happening", "what's happening", "what is new", "what's new", "what is neww", "g’day", "howdy"]
Save this as a txt file and load it later.
import json
greeting_words = json.loads(open('greetings.txt', 'r').read())
print(greeting_words)
>> ["hi", "hello", "hey", "helloo", "hellooo", "g morining", "gmorning", "good morning", "morning", "good day", "good afternoon", "good evening", "greetings", "greeting", "good to see you", "its good seeing you", "how are you", "how're you", "how are you doing", "how ya doin'", "how ya doin", "how is everything", "how is everything going", "how's everything going", "how is you", "how's you", "how are things", "how're things", "how is it going", "how's it going", "how's it goin'", "how's it goin", "how is life been treating you", "how's life been treating you", "how have you been", "how've you been", "what is up", "what's up", "what is cracking", "what's cracking", "what is good", "what's good", "what is happening", "what's happening", "what is new", "what's new", "what is neww", "g’day", "howdy"]

I don't think you can find a premade list of greeting phrases. However, there are certain websites where you can scrape data from and generate a list of phrases and then use it for your NLP task.
Example Websites:
https://www.fluentu.com/blog/english/basic-english-phrases/
https://reallifeglobal.com/23-different-ways-greet-someone-english/
Just google and you'd find plenty of useful links. Write a quick parser in Python and get your work done.

Related

RoR. Count the numbers of "No", "Yes" and "Does not apply" in an object in rails

I have a form with a checklist for a vehicle (tires ok?, lights ok?, etc)
As an Answer they only have 3 options "Yes","No" and "Does not apply", I need to count the number of "Yes", the number of "No" and the number of "Does not apply" in the object and display in the show
In the show if I put <%= #equipo %> i got <Equipo:0x00007f96922c1160>
in the controller if i put
#test = Equipo.where(created_at: #equipo.created_at).map { |e| e }
and in the show <%= #test %> give me something like this
[#<Equipo id: 1, nombre: "OL09", c1: "No", c2: "No", c3: "Yes", c4: "Yes", c5: "Does not apply", comments: "adsljadl", created_at: "2020-07-24 18:41:58", updated_at: "2020-07-24 18:41:58">]
If i put map directly in #equipo give me no method error
You can select only those columns that can take the three mentioned values and return an array with their values. You can flatten that and count the number of occurrences in the array:
Equipo
.where(created_at: #equipo.created_at)
.pluck(:c1, :c2, :c3, :c4, :c5)
.flatten
.group_by(&:itself)
.transform_values(&:count)
# {"No"=>2, "Yes"=>2, "Does not apply"=>1}
There are different ways to count the elements in an array, if your Ruby version allows you, you can use Enumerable#tally.

Rails - select_tag form helper is not working properly

I just recently started working in rails forms, and though I have scoured the api docs many times, I have not been able to figure out how to use it properly.
Basically, in my app I have a form to place a manual order (shipping). I would like there to be a select tag for specifying the state to be shipped to. I am working with an pre-existing SQLServer database, and the column I would want to display, and edit is :SHIPTOSTATE . However, when I go to edit an instance of an order, the form always shows "AL" and changing the state does not actually update the shipping state in my form. Can someone point out what I am doing wrong here?
The rest of my form is working beautifully, as the form is mostly text-fields at this point. The text-fields update just fine, but the select_tag is still troublesome.
Here is a snippet of the code in question:
<%= select_tag :SHIPTOSTATE, options_for_select(["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]) %>
Did you add :SHIPTOSTATE to permit method inside controller?
select_tag on it's own does not know which object you are attaching to. You need to provide a current value. You can do that with adding a second parameter to the options_for_select call.
options_for_select(["AL","AK"...], "Current State")
Then you have to explicitly look at the params[:SHIPTOSTATE] in your controller method.
You might also be using form_for. In that case you would want to use something like f.select and not use select_tag at all:
<%= form_for #your_object do |f| %>
# ...
<%= f.select :SHIPTOSTATE, ["AL","AK"...]
# ...
<%= f.submit %>
<% end %>
When you're dealing with a model, using the conventions in Rails, it's rare that you'd use the select_tag helper - you'd usually use the select helper, something like this:
= f.select :SHIPTOSTATE, %w[AL AK AZ AR ..etc]
If changing to using that helper doesn't work for you then you'll need to show us your controller, and perhaps your model schema, so we can see what else might be wrong here.

Joining an array of words / phrases with Ruby

irb(main):001:0> a = ["global climate change", "calamity", "glaciers", "new york times"]
=> ["global climate change", "calamity", "glaciers", "new york times"]
irb(main):002:0> a.join(', ')
=> "global climate change, calamity, glaciers, new york times"
I need the result to be
=> "global climate change", "calamity", "glaciers", "new york times"
Ideas? A one-liner would be ideal.
The correct way to pass arrays of options to a query via ActiveRecord is just to use query parameters:
a = ["global climate change", "calamity", "glaciers", "new york times"]
Category.where("name IN (?)", a)
# Generated query:
# Category Load (0.4ms) SELECT `categories`.* FROM `categories` WHERE (name in ('global climate change','calamity','glaciers','new york times'))
You don't have to do anything special to transform it into a valid SQL fragment. You should specifically avoid formatting strings as SQL fragments, as without careful sanitization, you may open up SQL injection vulnerabilities in your application.
Using arrays in a query is very simple:
arr = ["global climate change", "calamity", "glaciers", "new york times"]
Category.where(:name => arr)
There is absolutely no need to generate some weird string ;)
array = ['bob', 'bill']
new_array_string = array.map { |name| "'#{name}'" }.join(',')
=> "'bob', 'bill'"
User.where("name IN (#{new_array_string})")
a = ["global climate change", "calamity", "glaciers", "new york times"]
=> ["global climate change", "calamity", "glaciers", "new york times"]
%Q!"#{a.join('", "')}"!
=> "\"global climate change\", \"calamity\", \"glaciers\", \"new york times\""
a.map{|e| "\"#{e}\""}.join(', ')
=> "\"global climate change\", \"calamity\", \"glaciers\", \"new york times\""

Rails 12 hour AM/PM range for a day

This is a really simple question, and it's probably been asked and answered before, but I haven't been able to find anything.
Anyway, I need a range/array for 12 hour time, so like 12AM - 11AM, 12PM - 11PM. You probably get the gist of it. Right now I'm trying to do an absurdly complicated method involving mapping AM onto one array, PM onto another one, and then joining the two arrays together. There has to be an easier way to do this.
I know about Rails time_select, but I need a different format than what it provides. Any suggestions?
Clarification: So what I'm looking for is the 12-hour clock, with AM and PM. If I wanted a 24-hour clock, I could just do (0..24), and be done. But the 12-hour clock goes from 12-11 AM, and then goes from 12-11 PM. I'm pretty sure someone has done this before.
I agree with #MrYoshi's comment, the easiest way of formatting a date is .strftime(),
see RubyDoc for all possible options
Example:
Time.now.strftime("%I:%M %p")
output: HH:MM AM
Or what you literally asked for:
Time.now.strftime("%I:00")
output: HH:00
As you mentioned time_select I assume you want to offer time as a user selectable range, so try these options for time_select(more options):
time_select 'game', 'game_time', {:minute_step => 60, :ampm => true}
also this previous question: Time select form helper with 12 hour format for Rails 3?
Rails does this built in
<%= f.time_select :start, {ampm: true} %>
http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-time_select
I know this has already been answered awhile ago with the built in. But I needed a custom function to get these values and wrote this:
times = {"12 AM" => 0}.merge!(1.upto(11).collect { |n| {"#{n} AM" => n} }.reduce(Hash.new, :merge)).merge!({"12 PM" => 12}).merge!(1.upto(11).collect { |n| {"#{n} PM" => n + 12} }.reduce(Hash.new, :merge))
This yields:
{"12 AM"=>0, "1 AM"=>1, "2 AM"=>2, "3 AM"=>3, "4 AM"=>4, "5 AM"=>5, "6 AM"=>6, "7 AM"=>7, "8 AM"=>8, "9 AM"=>9, "10 AM"=>10, "11 AM"=>11, "12 PM"=>12, "1 PM"=>13, "2 PM"=>14, "3 PM"=>15, "4 PM"=>16, "5 PM"=>17, "6 PM"=>18, "7 PM"=>19, "8 PM"=>20, "9 PM"=>21, "10 PM"=>22, "11 PM"=>23}

SAX parsing a bunch of dead presidents with Nokogiri HTML parser?

I would like to parse USA presidents on the "List of Presidents of the United States" wiki page.
I can do this with a bunch of XPath and loops. But SAx parsing is so fast and I would like to learn how to implement that.
The Nokogiri document gave me an HTML SAX parsing example:
class MyDoc < Nokogiri::XML::SAX::Document
def start_element name, attributes = []
puts "found a #{name}"
end
end
parser = Nokogiri::HTML::SAX::Parser.new(MyDoc.new)
parser.parse(File.read(ARGV[0], 'rb'))
But which methods do I use to define all the HTML elements and their content that I want to grab?
With SAX, you have to define callback methods in your parser for each 'event'. You have to keep track of state yourself. It is very crude. For example, to get president names from the page, you can do this:
class MyDoc < Nokogiri::XML::SAX::Document
def start_element name, attributes = []
if name == "li"
#inside_li = true
end
end
def characters(chars)
if #inside_li
puts "found an <li> containing the string '#{chars}'"
end
end
def end_element name
if name == "li"
puts "ending #{name}"
#inside_li = false
end
end
end
The above can be thought of as the rough equivalent of the statement:
doc.xpath('//li').map(&:text)
Which starts with the following output:
ending li
found an <li> containing the string 'Grover Cleveland'
ending li
found an <li> containing the string 'William McKinley'
ending li
found an <li> containing the string 'Theodore Roosevelt'
So far so good, However, it also outputs a lot of cruft, ending with:
found an <li> containing the string 'Disclaimers'
ending li
found an <li> containing the string 'Mobile view'
ending li
found an <li> containing the string '
'
found an <li> containing the string '
'
ending li
found an <li> containing the string '
'
found an <li> containing the string '
'
ending li
So to make this more precise and not get the li elements you don't care about, you'd have to keep track of which container elements you are in by adding more if clauses to start_element, characters, etc. And if you have nested elements of the same name, you'll have to keep track of counters yourself, or implement a stack to push and pop the elements you see. It gets VERY messy very fast.
SAX is best for filters where you don't care about the DOM, you're just doing some basic transformations.
Instead, consider using a single XPath statement, such as
doc.xpath("//table[contains(.//div, 'Presidents of the United States')]//ol/li").map(&:text)
This says "Find the table which contains a div with the words 'Presidents of the United States' and return the text from all the ordered list items within it". This can be done in SAX, but it would be a lot of messy code.
Output of the above XPath:
["George Washington", "John Adams", "Thomas Jefferson", "James Madison", "James Monroe", "John Quincy Adams", "Andrew Jackson", "Martin Van Buren", "William Henry Harrison", "John Tyler", "James K. Polk", "Zachary Taylor", "Millard Fillmore", "Franklin Pierce", "James Buchanan", "Abraham Lincoln", "Andrew Johnson", "Ulysses S. Grant", "Rutherford B. Hayes", "James A. Garfield", "Chester A. Arthur", "Grover Cleveland", "Benjamin Harrison", "Grover Cleveland", "William McKinley", "Theodore Roosevelt", "William Howard Taft", "Woodrow Wilson", "Warren G. Harding", "Calvin Coolidge", "Herbert Hoover", "Franklin D. Roosevelt", "Harry S. Truman", "Dwight D. Eisenhower", "John F. Kennedy", "Lyndon B. Johnson", "Richard Nixon", "Gerald Ford", "Jimmy Carter", "Ronald Reagan", "George H. W. Bush", "Bill Clinton", "George W. Bush", "Barack Obama"]

Resources