### Configure RWordNet to Use a Custom WordNet Database Path in Ruby Source: https://github.com/doches/rwordnet/blob/master/README.markdown This Ruby snippet illustrates how to configure RWordNet to use a custom WordNet database installation. By setting the WordNet::DB.path class variable, users can direct the library to their specific WordNet database files, allowing flexibility in WordNet installation locations. This is useful for users who have pre-existing or custom-marked WordNet databases. ```Ruby require 'rwordnet' WordNet::DB.path = "/path/to/WordNet-3.0" lemmas = WordNet::Lemma.find_all("fruit") ``` -------------------------------- ### Configure Custom WordNet Path in rwordnet Source: https://context7.com/doches/rwordnet/llms.txt Demonstrates how to set a custom path for the WordNet database in rwordnet. This is useful when not using the bundled database. Ensure the specified path points to a valid WordNet installation. ```ruby require 'rwordnet' # Use a custom WordNet installation WordNet::DB.path = "/usr/local/WordNet-3.1" # All subsequent queries will use the custom database lemma = WordNet::Lemma.find("computer", :noun) lemma.synsets.each { |s| puts s.gloss } # Reset to bundled WordNet (if needed) WordNet::DB.path = File.expand_path("../WordNet-3.0/", __dir__) ``` -------------------------------- ### Get Full Taxonomy Path with Expanded Hypernyms Source: https://context7.com/doches/rwordnet/llms.txt Retrieves the complete path of hypernyms from a synset up to the root of the WordNet taxonomy. This helps in understanding the broader categories a concept belongs to. Requires 'rwordnet'. ```ruby require 'rwordnet' lemma = WordNet::Lemma.find("dog", :noun) synset = lemma.synsets[0] # Get the full hypernym tree from dog to entity puts "Taxonomy for 'dog':" synset.expanded_hypernyms.each { |ancestor| puts " -> #{ancestor}" } # Output: # -> (n) canine, canid (any of various fissiped mammals...) # -> (n) carnivore (a terrestrial or aquatic flesh-eating mammal) # -> (n) placental, placental mammal, eutherian, eutherian mammal (...) # -> (n) mammal, mammalian (warm-blooded vertebrate...) # -> (n) vertebrate, craniate (animals having a bony or cartilaginous skeleton) # -> (n) chordate (any animal of the phylum Chordata...) # -> (n) animal, animate being, beast, brute, creature, fauna (...) # -> (n) organism, being (a living thing...) # -> (n) living thing, animate thing (a living entity) # -> (n) whole, unit (an assemblage of parts...) # -> (n) object, physical object (a tangible and visible entity) # -> (n) physical entity (an entity that has physical existence) # -> (n) entity (that which is perceived or known...) ``` -------------------------------- ### Find All Glosses for a Word in Ruby Source: https://github.com/doches/rwordnet/blob/master/README.markdown This Ruby code snippet shows how to retrieve all glosses associated with a word, regardless of its part of speech. It uses WordNet::Lemma.find_all to get all lemmas for a word, then maps them to their synsets, flattens the array, and prints the gloss for each word. This functionality is part of the RWordNet gem. ```Ruby require 'rwordnet' lemmas = WordNet::Lemma.find_all("fruit") synsets = lemmas.map { |lemma| lemma.synsets } words = synsets.flatten words.each { |word| puts word.gloss } ``` -------------------------------- ### Build Command-Line Dictionary Tool with rwordnet Source: https://context7.com/doches/rwordnet/llms.txt A complete Ruby script to create a command-line dictionary lookup tool. It finds definitions for a given word, handles inflected forms using morphological analysis, and displays synonyms. ```ruby #!/usr/bin/env ruby require 'rwordnet' word = ARGV[0] || "example" # Find all lemmas for the word across all parts of speech lemmas = WordNet::Lemma.find_all(word) if lemmas.empty? # Try morphological analysis for inflected forms base_forms = WordNet::Synset.morphy_all(word) if base_forms.any? puts "Did you mean: #{base_forms.join(', ')}?" lemmas = base_forms.flat_map { |form| WordNet::Lemma.find_all(form) } else puts "Word '#{word}' not found in WordNet." exit 1 end end # Print each lemma with its definitions lemmas.each do |lemma| puts "\n#{lemma.word} (#{lemma.pos})" puts "-" * 40 lemma.synsets.each_with_index do |synset, i| puts " #{i + 1}. #{synset.gloss}" puts " Synonyms: #{synset.words.map { |w| w.tr('_', ' ') }.join(', ')}" end end # Example output for "run": # run (noun) # ---------------------------------------- # 1. a score in baseball made by a runner touching all four bases safely # Synonyms: run, tally # 2. the act of testing something # Synonyms: test, trial, run # ... # run (verb) # ---------------------------------------- # 1. move fast by using one's feet... # Synonyms: run # ... ``` -------------------------------- ### Find Noun Glosses for a Word in Ruby Source: https://github.com/doches/rwordnet/blob/master/README.markdown This snippet demonstrates how to find all noun glosses for a given word using the RWordNet gem. It requires the 'rwordnet' library and uses the WordNet::Lemma.find method to locate the lemma and then iterates through its synsets to print the glosses. No external dependencies are needed beyond the gem itself. ```Ruby require 'rwordnet' lemma = WordNet::Lemma.find("fruit", :noun) lemma.synsets.each { |synset| puts synset.gloss } ``` -------------------------------- ### Navigate Taxonomy with Hypernyms and Hyponyms Source: https://context7.com/doches/rwordnet/llms.txt Explores the hierarchical structure of WordNet by retrieving parent concepts (hypernyms) and child concepts (hyponyms) for a given synset. Requires the 'rwordnet' gem. ```ruby require 'rwordnet' lemma = WordNet::Lemma.find("dog", :noun) synset = lemma.synsets[0] # Get the immediate parent concept parent = synset.hypernym puts parent # => "(n) canine, canid (any of various fissiped mammals...)" # Get all immediate parent concepts (some synsets have multiple parents) parents = synset.hypernyms parents.each { |p| puts p } # Get all immediate child concepts (more specific types) children = synset.hyponyms children.each { |child| puts child } # => "(n) puppy (a young dog)" # => "(n) pooch, doggie, doggy, barker, bow-wow (informal terms for dogs)" # ... additional child concepts ``` -------------------------------- ### Intelligent Word Lookup with Morphology - WordNet::Synset.find/find_all (Ruby) Source: https://context7.com/doches/rwordnet/llms.txt Finds synsets for a word, intelligently handling inflected forms (plurals, verb conjugations, comparatives) by using morphological analysis. This allows lookup for words like "dogs" or "running" by mapping them to their base forms. It supports finding synsets for specific parts of speech or across all parts of speech. ```ruby require 'rwordnet' # Find synsets for an inflected form synsets = WordNet::Synset.find("dogs", "noun") synsets.each { |s| puts s } # Output: # (n) dog, domestic dog, Canis familiaris (a member of the genus Canis...) # (n) frump, dog (a dull unattractive unpleasant girl or woman) # ... additional meanings # Find all synsets across all parts of speech all_synsets = WordNet::Synset.find_all("running") all_synsets.each { |s| puts s } # Finds noun, verb, and adjective senses of "running" # Morphy handles verb conjugations verb_synsets = WordNet::Synset.find("went", "verb") verb_synsets.each { |s| puts s } # Maps "went" to "go" and returns its synsets ``` -------------------------------- ### Find Opposite Meanings with Antonyms Source: https://context7.com/doches/rwordnet/llms.txt Identifies synsets that represent antonyms (opposite meanings) for a given synset. This relationship is most common for adjectives and verbs. Requires 'rwordnet'. ```ruby require 'rwordnet' # Find antonyms for "good" (adjective) lemma = WordNet::Lemma.find("good", :adj) synset = lemma.synsets[0] antonyms = synset.antonyms antonyms.each { |ant| puts ant } # => "(a) bad (having undesirable or negative qualities...)" # Find antonyms for a verb lemma = WordNet::Lemma.find("rise", :verb) synset = lemma.synsets[0] synset.antonyms.each { |ant| puts ant } # => "(v) fall, descend, go down, come down (move downward and lower...)" ``` -------------------------------- ### Find Base Forms with Morphy All Source: https://context7.com/doches/rwordnet/llms.txt Retrieves all possible base forms (lemmas) for a given word across different parts of speech. This is useful for understanding the morphological variations of a word. ```ruby require 'rwordnet' puts WordNet::Synset.morphy_all("hiking") # => ["hiking", "hike"] (noun form exists, verb base is "hike") ``` -------------------------------- ### Work with Synonym Sets - WordNet::Synset (Ruby) Source: https://context7.com/doches/rwordnet/llms.txt Represents a group of synonymous words with a shared meaning in WordNet. A Synset object provides access to its definition (gloss), the words it contains, the word count, its part of speech, and a human-readable string representation. Synsets can be accessed via Lemma objects or found directly. ```ruby require 'rwordnet' # Get synsets from a lemma lemma = WordNet::Lemma.find("dog", :noun) synset = lemma.synsets[0] # Basic synset information puts synset.gloss # => "a member of the genus Canis (probably combined from the common wolf)..." puts synset.words # => ["dog", "domestic_dog", "Canis_familiaris"] puts synset.word_count # => 3 puts synset.pos # => "n" # Human-readable string representation puts synset.to_s # => "(n) dog, domestic dog, Canis familiaris (a member of the genus Canis...)" ``` -------------------------------- ### Retrieve All Descendants with Expanded Hyponyms Source: https://context7.com/doches/rwordnet/llms.txt Recursively fetches all descendant synsets (hyponyms) for a given synset. This is useful for finding all more specific terms within a concept. Requires 'rwordnet'. ```ruby require 'rwordnet' # Find all specific types of "fruit" lemma = WordNet::Lemma.find("edible_fruit", :noun) synset = lemma.synsets[0] # Get all child concepts recursively children = synset.expanded_hyponyms puts "Found #{children.count} types of edible fruit" # Print first 10 examples children.first(10).each { |child| puts " - #{child.words.first}" } ``` -------------------------------- ### Generic Relationship Lookup with Synset#relation Source: https://context7.com/doches/rwordnet/llms.txt Performs a generic lookup of any relationship type using WordNet's pointer symbols. Supports various relations like meronyms, holonyms, and derivationally related forms. Requires 'rwordnet'. ```ruby require 'rwordnet' # Include the pointer constants include WordNet lemma = WordNet::Lemma.find("car", :noun) synset = lemma.synsets[0] # Find part meronyms (parts of a car) parts = synset.relation(PART_MERONYM) puts "Parts of a car:" parts.each { |part| puts " - #{part.words.first}" } # => Parts of a car: # => - accelerator # => - air_bag # => - auto_accessory # => - ... # Find member holonyms (what groups contain this) lemma = WordNet::Lemma.find("tree", :noun) synset = lemma.synsets[0] groups = synset.relation(MEMBER_HOLONYM) groups.each { |g| puts g } # Shows collections/groups that trees belong to # Available pointer symbols include: # HYPERNYM ("@"), HYPONYM ("~"), ANTONYM ("!") # PART_MERONYM ("%p"), PART_HOLONYM ("#p") # SUBSTANCE_MERONYM ("%s"), SUBSTANCE_HOLONYM ("#s") # MEMBER_MERONYM ("%m"), MEMBER_HOLONYM ("#m") # DERIVATIONALLY_RELATED_FORM ("+"), SIMILAR_TO ("&") # CAUSE (">"), ENTAILMENT ("*"), VERB_GROUP ("$") ``` -------------------------------- ### Find Word Across All Parts of Speech - WordNet::Lemma.find_all (Ruby) Source: https://context7.com/doches/rwordnet/llms.txt Searches for a word across all available parts of speech (noun, verb, adjective, adverb) in WordNet and returns an array of matching Lemma objects. This is useful for identifying all grammatical uses of a word. The function can also be used to retrieve all synsets for a given word across all its forms. ```ruby require 'rwordnet' # Find all lemmas for "fall" across all parts of speech lemmas = WordNet::Lemma.find_all("fall") lemmas.each do |lemma| puts "#{lemma.word} (#{lemma.pos}): #{lemma.synsets.count} meanings" end # Output: # fall (noun): 12 meanings # fall (verb): 41 meanings # Get all glosses for all meanings of a word synsets = lemmas.flat_map { |lemma| lemma.synsets } synsets.each { |synset| puts synset.gloss } ``` -------------------------------- ### Find Word by Part of Speech - WordNet::Lemma.find (Ruby) Source: https://context7.com/doches/rwordnet/llms.txt Finds a specific word in WordNet for a given part of speech and returns a Lemma object. Supports parts of speech like :noun, :verb, :adj, :adv and their shorthands. Returns nil if the word is not found. It can retrieve word details, part of speech, and the count of its associated synsets. ```ruby require 'rwordnet' # Find the noun form of "fruit" lemma = WordNet::Lemma.find("fruit", :noun) puts lemma.word # => "fruit" puts lemma.pos # => "noun" puts lemma.tagsense_count # => 3 # Get all synsets (different meanings) for this lemma lemma.synsets.each_with_index do |synset, i| puts "#{i + 1}) #{synset.gloss}" end # Output: # 1) the ripened reproductive body of a seed plant # 2) an amount of a product # 3) the consequence of some effort or action; "he lived long enough to see the fruit of his policies" # Using shorthand part of speech verb_lemma = WordNet::Lemma.find("run", :v) puts verb_lemma.synsets.count # => 41 ``` -------------------------------- ### Morphological Analysis - WordNet::Synset.morphy (Ruby) Source: https://context7.com/doches/rwordnet/llms.txt Applies morphological rules to transform inflected word forms into their base forms that exist in WordNet. It handles plurals, verb tenses, and adjective/adverb forms, returning an array of possible base forms. This is crucial for accurate WordNet lookups when dealing with non-lemma words. ```ruby require 'rwordnet' # Get base forms for a plural noun puts WordNet::Synset.morphy("dogs", "noun") # => ["dog"] # Handle verb conjugations puts WordNet::Synset.morphy("running", "verb") # => ["run"] puts WordNet::Synset.morphy("went", "verb") # => ["go"] # Adjective forms puts WordNet::Synset.morphy("better", "adj") # => ["good"] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.