### Setup development environment Source: https://github.com/ged/linkparser/blob/master/README.md Commands to install dependencies and perform developer setup after checking out the source. ```bash $ gen install -Ng $ rake setup ``` -------------------------------- ### Install linkparser gem Source: https://github.com/ged/linkparser/blob/master/README.md Commands to install the gem, optionally specifying the path to the link-grammar library. ```bash gem install linkparser ``` ```bash gem install linkparser -- --with-link-grammar=/usr/local ``` -------------------------------- ### Get Parsed Disjuncts for Each Word Source: https://context7.com/ged/linkparser/llms.txt Iterates through the words of a linkage and prints their corresponding parsed disjuncts. ```ruby disjuncts = linkage.disjuncts disjuncts.each_with_index do |disjunct, i| word = linkage.words[i] puts "#{word}: #{disjunct.inspect}" end ``` -------------------------------- ### Parse Sentences with Dictionary#parse Source: https://context7.com/ged/linkparser/llms.txt Use the parse method on a Dictionary object to process a sentence and get a Sentence object. Custom parsing options can be provided to override dictionary defaults. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) # Parse a simple sentence sentence = dict.parse("The dog chased the cat.") # => # # Parse with custom options overriding dictionary defaults sentence = dict.parse("People use Ruby.", verbosity: 0, max_null_count: 5) # Check parsing results puts sentence.num_linkages_found # => 8 puts sentence.null_count # => 0 puts sentence.length # => 7 (including walls and punctuation) ``` -------------------------------- ### Get Raw Disjunct Strings from Linkage Source: https://context7.com/ged/linkparser/llms.txt Retrieves and prints the raw string representations of disjuncts for the first linkage of a parsed sentence. ```ruby linkage = sentence.linkages.first # Get raw disjunct strings disjunct_strings = linkage.disjunct_strings puts disjunct_strings.inspect ``` -------------------------------- ### Create LinkParser Dictionary Source: https://context7.com/ged/linkparser/llms.txt Instantiate a Dictionary object to load grammar rules. Options can be passed during initialization to configure parsing behavior. ```ruby require 'linkparser' # Create dictionary with default English language dict = LinkParser::Dictionary.new # => # # Create dictionary with specific language dict_en = LinkParser::Dictionary.new('en') dict_de = LinkParser::Dictionary.new('de') # Create dictionary with parse options dict = LinkParser::Dictionary.new( verbosity: 0, # Suppress parsing output max_null_count: 18, # Allow null links for incomplete parses islands_ok: true # Allow island links ) # Access dictionary options puts dict.options[:verbosity] # => 0 ``` -------------------------------- ### Handle Unknown Language Dictionary Initialization Error Source: https://context7.com/ged/linkparser/llms.txt Demonstrates error handling for attempting to initialize a dictionary with an unsupported language code. ```ruby require 'linkparser' # Handle unknown language begin dict = LinkParser::Dictionary.new('zz') rescue LinkParser::Error => e puts "Dictionary error: #{e.message}" end ``` -------------------------------- ### Configure Resource Limits for Parsing Source: https://context7.com/ged/linkparser/llms.txt Initializes a dictionary with strict resource limits (max parse time and memory) to simulate resource exhaustion scenarios. ```ruby dict = LinkParser::Dictionary.new('en', verbosity: 0, max_parse_time: 1, # Very short timeout max_memory: 1000 # Very low memory ) sentence = dict.parse("A very long complex sentence...") if sentence.options.resources_exhausted? puts "Could not fully parse - resources exhausted" end ``` -------------------------------- ### Initialize LinkParser Dictionary Source: https://context7.com/ged/linkparser/llms.txt Initializes a LinkParser dictionary for a specified language with verbosity set to 0. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) ``` -------------------------------- ### Dictionary Management Source: https://context7.com/ged/linkparser/llms.txt Methods for initializing and configuring the LinkParser dictionary. ```APIDOC ## Dictionary Initialization ### Description Creates a new dictionary instance to load grammar rules and word definitions. ### Parameters #### Path Parameters - **language** (string) - Optional - The language code (e.g., 'en', 'de'). Defaults to 'en'. #### Request Body - **verbosity** (integer) - Optional - Controls parsing output level. - **max_null_count** (integer) - Optional - Maximum null links allowed. - **islands_ok** (boolean) - Optional - Whether to allow island links. ``` -------------------------------- ### LinkParser Ruby Library Overview Source: https://github.com/ged/linkparser/blob/master/Manifest.txt This file lists the core components of the LinkParser Ruby library. It serves as an entry point for understanding the project's structure. ```ruby require 'linkparser/dictionary' require 'linkparser/linkage' require 'linkparser/mixins' require 'linkparser/parseoptions' require 'linkparser/sentence' ``` -------------------------------- ### Parse sentences with linkparser Source: https://github.com/ged/linkparser/blob/master/README.md Initialize a dictionary and parse a sentence to extract grammatical components and diagrams. ```ruby dict = LinkParser::Dictionary.new => # sent = dict.parse( "People use Ruby for all kinds of nifty things." ) => # sent.subject => "people" sent.verb => "use" sent.object => "Ruby" puts sent.diagram( max_width: 200 ) +---------------------------------Xp--------------------------------+ | +---------------Jp---------------+ | | | +--------Dmc--------+ | +------>WV------>+-----MVp----+ | +------Jd-----+ | +----Wd---+--Sp--+--Os--+ | +-Dmcn-+-OFd-+ +----A---+ +--RW--+ | | | | | | | | | | | | LEFT-WALL people.p use.v Ruby.f for.p all.a kinds.n of nifty.a things.n . RIGHT-WALL ``` -------------------------------- ### Generate Links and Domains Diagram Source: https://context7.com/ged/linkparser/llms.txt Display a diagram showing links and their associated domains. This provides a different perspective on the grammatical connections. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("The flag was wet.") linkage = sentence.linkages.first # Links and domains diagram puts linkage.links_and_domains # LEFT-WALL Xp ----Xp----- Xp . # (m) LEFT-WALL hWV >---WV----> dWV was.v-d # (m) LEFT-WALL hWd >---Wd----- Wd flag.n # (m) flag.n Ss*s ----Ss*s--- Ss was.v-d # (m) the D ----Ds**c-- Ds**c flag.n # (m) was.v-d Pa ----Pa----- Pa wet.a # . RW ----RW----- RW RIGHT-WALL ``` -------------------------------- ### Create ParseOptions Object Source: https://context7.com/ged/linkparser/llms.txt Instantiate a ParseOptions object to configure parsing parameters like verbosity, linkage limits, and null link counts. ```ruby require 'linkparser' # Create parse options directly opts = LinkParser::ParseOptions.new( verbosity: 0, linkage_limit: 100, max_null_count: 10, min_null_count: 0 ) ``` -------------------------------- ### Configure Dictionary with Parse Options Source: https://context7.com/ged/linkparser/llms.txt Set various parsing parameters when creating a LinkParser::Dictionary. These options influence the parsing process and resource usage. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0, # Output verbosity (0 = silent) linkage_limit: 1000, # Max linkages to consider in post-processing disjunct_cost: 2, # Max disjunct cost during parsing min_null_count: 0, # Minimum null links allowed max_null_count: 0, # Maximum null links allowed islands_ok: false, # Allow unconnected islands of links short_length: 16, # Max link length (for speed) max_memory: 128000000, # Max memory in bytes max_parse_time: 30, # Max parse time in seconds all_short_connectors: false, # Limit all connector lengths spell_guessing_enabled: true # Enable spell correction ) ``` -------------------------------- ### LinkParser C Extension - Header File Source: https://github.com/ged/linkparser/blob/master/Manifest.txt The main header file for the LinkParser C extension. It declares the module and provides necessary includes for other C files. ```c #ifndef LINKPARSER_H #define LINKPARSER_H #include "ruby.h" extern VALUE rb_mLinkParser; void Init_dictionary(); void Init_linkage(); void Init_parseoptions(); void Init_sentence(); #endif /* LINKPARSER_H */ ``` -------------------------------- ### Generate PostScript Diagram for Linkage Source: https://context7.com/ged/linkparser/llms.txt Generate a PostScript (EPS) diagram of the linkage structure. Options control whether to include a full document header. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("The flag was wet.") linkage = sentence.linkages.first # Generate PostScript diagram ps_macros = linkage.postscript_diagram ps_full = linkage.postscript_diagram(display_header: true) # Full EPS document ``` -------------------------------- ### LinkParser C Extension - Core Functionality Source: https://github.com/ged/linkparser/blob/master/Manifest.txt The main C extension file for LinkParser, providing core parsing functionalities. This includes initialization and basic structure definitions. ```c #include "ruby.h" #include "linkparser.h" VALUE rb_mLinkParser; void Init_linkparser() { rb_mLinkParser = rb_define_module("LinkParser"); Init_dictionary(); Init_linkage(); Init_parseoptions(); Init_sentence(); } ``` -------------------------------- ### LinkParser C Extension - Parse Options Handling Source: https://github.com/ged/linkparser/blob/master/Manifest.txt C code for managing parse options within the LinkParser C extension. This allows customization of the parsing process. ```c #include "ruby.h" #include "linkparser.h" #include "parseoptions.h" static void parseoptions_free(void *ptr) { linkparser_parseoptions_destroy(ptr); } VALUE linkparser_parseoptions_alloc(VALUE klass) { return Data_Wrap_Struct(klass, 0, parseoptions_free, linkparser_parseoptions_create()); } VALUE linkparser_parseoptions_initialize(VALUE self) { return self; } void Init_parseoptions() { VALUE rb_cParseOptions = rb_define_class_under(rb_mLinkParser, "ParseOptions", rb_cObject); rb_define_alloc_func(rb_cParseOptions, linkparser_parseoptions_alloc); rb_define_method(rb_cParseOptions, "initialize", linkparser_parseoptions_initialize, 0); } ``` -------------------------------- ### Create and Parse Sentences Directly Source: https://context7.com/ged/linkparser/llms.txt Instantiate a Sentence object directly for more control. The sentence can be parsed explicitly using the parse method, which accepts specific options. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) # Create sentence without parsing sentence = LinkParser::Sentence.new("The cat runs.", dict) sentence.parsed? # => false # Parse the sentence explicitly linkage_count = sentence.parse # => 3 sentence.parsed? # => true # Parse with specific options sentence = LinkParser::Sentence.new("Complex sentence here.", dict) sentence.parse( verbosity: 0, max_null_count: 3, min_null_count: 1 ) # Get tokenized words sentence.words # => ['LEFT-WALL', 'the', 'cat.n', 'runs.v', '.', 'RIGHT-WALL'] # Convert to string sentence.to_s # => "LEFT-WALL the cat.n runs.v . RIGHT-WALL" ``` -------------------------------- ### Generate ASCII Diagram for Linkage Source: https://context7.com/ged/linkparser/llms.txt Visualize the grammatical structure of a linkage using an ASCII diagram. Customization options include width and display of wall words. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("The flag was wet.") linkage = sentence.linkages.first # Generate ASCII diagram puts linkage.diagram # Output: # +--------------Xp--------------+ # +-------->WV------->+ | # +---->Wd-----+ | | # | +Ds**c+-Ss*s-+--Pa--+ +--RW--+ # | | | | | | | # LEFT-WALL the flag.n was.v-d wet.a . RIGHT-WALL # Diagram with custom width (for narrow terminals) narrow_diagram = linkage.diagram(max_width: 40) # Diagram without wall words puts linkage.diagram(display_walls: false) # Shows only the actual sentence words without LEFT-WALL/RIGHT-WALL ``` -------------------------------- ### Access All Links as Structs Source: https://context7.com/ged/linkparser/llms.txt Iterate through all links in a linkage to access their detailed properties. Requires the LinkParser library and a parsed sentence. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("The dog fetches the ball.") linkage = sentence.linkages.first # Get all links as Link structs links = linkage.links puts links.length # => 8 # Each link contains detailed information links.each do |link| puts "#{link.lword} --#{link.label}--> #{link.rword}" puts " Left label: #{link.llabel}" puts " Right label: #{link.rlabel}" puts " Length: #{link.length}" puts " Description: #{link.desc}" end ``` -------------------------------- ### Access Parse Options from Sentence Source: https://context7.com/ged/linkparser/llms.txt Retrieve and inspect the parse options associated with a parsed sentence object. This allows checking settings and resource usage after parsing. ```ruby require 'linkparser' # Access options from parsed sentence sentence = dict.parse("Test sentence.") puts sentence.options.verbosity puts sentence.options.max_null_count puts sentence.options.islands_ok? ``` -------------------------------- ### LinkParser C Extension - Dictionary Handling Source: https://github.com/ged/linkparser/blob/master/Manifest.txt C code for handling dictionaries within the LinkParser extension. This is part of the low-level implementation for performance. ```c #include "ruby.h" #include "linkparser.h" #include "dictionary.h" static void dictionary_free(void *ptr) { linkparser_dictionary_destroy(ptr); } VALUE linkparser_dictionary_alloc(VALUE klass) { return Data_Wrap_Struct(klass, 0, dictionary_free, linkparser_dictionary_create()); } VALUE linkparser_dictionary_initialize(VALUE self, VALUE path) { linkparser_dictionary_load(RDATA(self)->data, StringValuePtr(path)); return self; } void Init_dictionary() { VALUE rb_cDictionary = rb_define_class_under(rb_mLinkParser, "Dictionary", rb_cObject); rb_define_alloc_func(rb_cDictionary, linkparser_dictionary_alloc); rb_define_method(rb_cDictionary, "initialize", linkparser_dictionary_initialize, 1); } ``` -------------------------------- ### Handle Sentence with No Valid Linkages Source: https://context7.com/ged/linkparser/llms.txt Attempts to access the diagram for a sentence that has no valid linkages, demonstrating error catching. ```ruby dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("The event that he smiled at me gives me hope") begin # This raises an error because no valid linkage exists puts sentence.diagram rescue LinkParser::Error => e puts "Linkage error: #{e.message}" # => "sentence has no linkages" end ``` -------------------------------- ### Calculate Linkage Cost Metrics Source: https://context7.com/ged/linkparser/llms.txt Examine cost metrics of a linkage to evaluate its quality. These include unused word cost, disjunct cost, and total link cost. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("The big red dog runs quickly.") linkage = sentence.linkages.first # Cost metrics puts linkage.unused_word_cost # Number of null links required puts linkage.disjunct_cost # Connector/disjunct cost puts linkage.link_cost # Total link length cost ``` -------------------------------- ### Parse Sentence with LinkParser Source: https://context7.com/ged/linkparser/llms.txt Parses a given sentence using a LinkParser dictionary. ```ruby sentence = dict.parse("The cat runs quickly.") ``` -------------------------------- ### Check Violations and Cost Per Linkage Source: https://context7.com/ged/linkparser/llms.txt Iterates through valid linkages to report the number of violations and disjunct cost for each. ```ruby (0...sentence.num_valid_linkages).each do |i| violations = sentence.num_violations(i) cost = sentence.disjunct_cost(i) puts "Linkage #{i}: #{violations} violations, cost #{cost}" end ``` -------------------------------- ### Extract Sentence-Level Metrics Source: https://context7.com/ged/linkparser/llms.txt Retrieves and prints sentence-level metrics including total linkages found, valid linkages, and post-processed linkages. ```ruby puts sentence.num_linkages_found # Total linkages found puts sentence.num_valid_linkages # Linkages without violations puts sentence.num_linkages_post_processed # Actually post-processed ``` -------------------------------- ### LinkParser C Extension - Sentence Handling Source: https://github.com/ged/linkparser/blob/master/Manifest.txt C code for representing and manipulating parsed sentences within the LinkParser C extension. This is fundamental to the output of the parser. ```c #include "ruby.h" #include "linkparser.h" #include "sentence.h" static void sentence_free(void *ptr) { linkparser_sentence_destroy(ptr); } VALUE linkparser_sentence_alloc(VALUE klass) { return Data_Wrap_Struct(klass, 0, sentence_free, linkparser_sentence_create()); } VALUE linkparser_sentence_initialize(VALUE self, VALUE str) { linkparser_sentence_set_string(RDATA(self)->data, StringValuePtr(str)); return self; } void Init_sentence() { VALUE rb_cSentence = rb_define_class_under(rb_mLinkParser, "Sentence", rb_cObject); rb_define_alloc_func(rb_cSentence, linkparser_sentence_alloc); rb_define_method(rb_cSentence, "initialize", linkparser_sentence_initialize, 1); } ``` -------------------------------- ### Check Resource Constraints After Parsing Source: https://context7.com/ged/linkparser/llms.txt After parsing, check if resource limits such as time or memory were exceeded. These checks are performed on the sentence's options object. ```ruby # Check resource constraints after parsing sentence.parse if sentence.options.timer_expired? puts "Parsing timed out" end if sentence.options.memory_exhausted? puts "Ran out of memory" end if sentence.options.resources_exhausted? puts "Resources exhausted" end # Reset resource tracking sentence.options.reset_resources ``` -------------------------------- ### Extract Grammatical Components from Sentence Source: https://context7.com/ged/linkparser/llms.txt Sentence objects provide convenient methods to extract the subject, verb, and object from the first linkage. Options exist to retain part-of-speech subscripts. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("People use Ruby for all kinds of nifty things.") # Extract grammatical components puts sentence.subject # => "people" puts sentence.verb # => "use" puts sentence.object # => "Ruby" # Keep part-of-speech subscripts puts sentence.subject(keep_subscript: true) # => "people.p" puts sentence.verb(keep_subscript: true) # => "use.v" puts sentence.object(keep_subscript: true) # => "Ruby.f" # Extract all nouns sentence = dict.parse("The big dog chased the small cat.") puts sentence.nouns.inspect # => ["dog", "cat"] # Check for imperative sentences imperative = dict.parse("Go to the store!") puts imperative.imperative? # => true declarative = dict.parse("The flag was wet.") puts declarative.imperative? # => false ``` -------------------------------- ### Check for Linkages Before Accessing Diagram Source: https://context7.com/ged/linkparser/llms.txt Checks if a sentence has any valid linkages before attempting to display its diagram, providing a fallback message if none are found. ```ruby if sentence.linkages.any? puts sentence.diagram else puts "No valid parse found" end ``` -------------------------------- ### LinkParser Spec - Helpers Source: https://github.com/ged/linkparser/blob/master/Manifest.txt Helper methods used across various RSpec tests for the LinkParser gem. These abstract common testing logic. ```ruby require 'linkparser' module SpecHelpers def self.included(base) base.let(:parser) { LinkParser::Parser.new } end end ``` -------------------------------- ### Sentence Parsing Source: https://context7.com/ged/linkparser/llms.txt Methods for parsing text into sentence objects and extracting grammatical components. ```APIDOC ## Dictionary#parse ### Description Parses a string into a Sentence object containing linkages. ### Parameters - **text** (string) - Required - The sentence to parse. - **options** (hash) - Optional - Parsing configuration overrides. ## Sentence#subject / #verb / #object ### Description Extracts grammatical components from the first linkage of a parsed sentence. ### Parameters - **keep_subscript** (boolean) - Optional - Whether to retain part-of-speech tags. ``` -------------------------------- ### LinkParser Spec - ParseOptions Tests Source: https://github.com/ged/linkparser/blob/master/Manifest.txt RSpec tests for the ParseOptions class in LinkParser. These verify the creation and behavior of parse options objects. ```ruby require 'spec_helper' describe LinkParser::ParseOptions do it "should initialize a ParseOptions object" do options = LinkParser::ParseOptions.new expect(options).to be_a(LinkParser::ParseOptions) end end ``` -------------------------------- ### LinkParser Spec - Dictionary Tests Source: https://github.com/ged/linkparser/blob/master/Manifest.txt RSpec tests for the Dictionary class in LinkParser. These verify dictionary loading and basic operations. ```ruby require 'spec_helper' describe LinkParser::Dictionary do it "should load a dictionary from a path" do # Assuming a dummy dictionary file exists at 'spec/fixtures/dummy.dict' # This test would need a real dictionary file to pass. # dictionary = LinkParser::Dictionary.new('spec/fixtures/dummy.dict') # expect(dictionary).to be_a(LinkParser::Dictionary) end end ``` -------------------------------- ### LinkParser Spec - Main Integration Tests Source: https://github.com/ged/linkparser/blob/master/Manifest.txt Main RSpec integration tests for the LinkParser gem. These tests cover the primary functionality of parsing sentences. ```ruby require 'spec_helper' describe LinkParser::Parser do include SpecHelpers it "should initialize a parser" do expect(parser).to be_a(LinkParser::Parser) end it "should parse a sentence and return a Sentence object" do sentence = parser.parse('This is a test sentence.') expect(sentence).to be_a(LinkParser::Sentence) end it "should handle empty input gracefully" do sentence = parser.parse('') expect(sentence).to be_a(LinkParser::Sentence) expect(sentence.words.count).to eq(0) end end ``` -------------------------------- ### Access Individual Link Properties Source: https://context7.com/ged/linkparser/llms.txt Retrieve specific attributes of a link by its index within a linkage. ```ruby puts linkage.link_label(0) # => "Xp" puts linkage.link_llabel(0) # => "Xp" (left label) puts linkage.link_rlabel(0) # => "Xp" (right label) puts linkage.link_lword(0) # => 0 (index of LEFT-WALL) puts linkage.link_rword(0) # => 5 (index of ".") puts linkage.link_length(0) # => 5 (words spanned) ``` -------------------------------- ### LinkParser C Extension - Linkage Handling Source: https://github.com/ged/linkparser/blob/master/Manifest.txt C code for managing linkage structures in the LinkParser C extension. This is crucial for the parsing engine's internal workings. ```c #include "ruby.h" #include "linkparser.h" #include "linkage.h" static void linkage_free(void *ptr) { linkparser_linkage_destroy(ptr); } VALUE linkparser_linkage_alloc(VALUE klass) { return Data_Wrap_Struct(klass, 0, linkage_free, linkparser_linkage_create()); } VALUE linkparser_linkage_initialize(VALUE self, VALUE path) { linkparser_linkage_load(RDATA(self)->data, StringValuePtr(path)); return self; } void Init_linkage() { VALUE rb_cLinkage = rb_define_class_under(rb_mLinkParser, "Linkage", rb_cObject); rb_define_alloc_func(rb_cLinkage, linkparser_linkage_alloc); rb_define_method(rb_cLinkage, "initialize", linkparser_linkage_initialize, 1); } ``` -------------------------------- ### LinkParser Spec - Sentence Tests Source: https://github.com/ged/linkparser/blob/master/Manifest.txt RSpec tests for the Sentence class in LinkParser. These cover sentence creation, parsing results, and attribute access. ```ruby require 'spec_helper' describe LinkParser::Sentence do let(:parser) { LinkParser::Parser.new } it "should parse a simple sentence" do sentence = parser.parse('The cat sat on the mat.') expect(sentence).to be_a(LinkParser::Sentence) expect(sentence.words.count).to eq(7) end it "should provide access to words" do sentence = parser.parse('Go home.') expect(sentence.words.first.string).to eq('Go') expect(sentence.words.last.string).to eq('home.') end end ``` -------------------------------- ### Accessing Linkages and Linkage Details Source: https://context7.com/ged/linkparser/llms.txt A parsed sentence contains multiple linkages. Each linkage provides access to tokenized words, word counts, and link counts. ```ruby require 'linkparser' dict = LinkParser::Dictionary.new('en', verbosity: 0) sentence = dict.parse("The flag was wet.") # Get all linkages linkages = sentence.linkages puts linkages.count # => multiple valid parses # Work with the first (best) linkage linkage = linkages.first # Get tokenized words with part-of-speech tags puts linkage.words.inspect # => ["LEFT-WALL", "the", "flag.n", "was.v-d", "wet.a", ".", "RIGHT-WALL"] # Count words and links puts linkage.num_words # => 7 puts linkage.num_links # => 7 ``` -------------------------------- ### Check for Post-processing Violations in Linkage Source: https://context7.com/ged/linkparser/llms.txt Checks if a linkage has a violation name and prints it, otherwise indicates no violations. ```ruby if linkage.violation_name puts "Violation: #{linkage.violation_name}" else puts "No violations" end ``` -------------------------------- ### LinkParser Spec - Mixins Tests Source: https://github.com/ged/linkparser/blob/master/Manifest.txt RSpec tests for mixins used within the LinkParser gem. These ensure that shared functionality is correctly implemented. ```ruby require 'spec_helper' describe "LinkParser Mixins" do # This spec file might contain tests for modules included in other classes. # Example: testing a method defined in a mixin. # context "MyMixin" do # let(:klass) { Class.new { include LinkParser::MyMixin } } # let(:instance) { klass.new } # it "should respond to my_method" do # expect(instance).to respond_to(:my_method) # end # end end ``` -------------------------------- ### LinkParser Spec - Bug Fixes Source: https://github.com/ged/linkparser/blob/master/Manifest.txt RSpec tests for bug fixes in the LinkParser gem. These tests ensure that previously identified issues are resolved. ```ruby require 'spec_helper' describe "LinkParser" do describe "bugfixes" do it "should handle sentences with only punctuation" do parser = LinkParser::Parser.new parser.parse('!!!').should be_a(LinkParser::Sentence) end end end ``` -------------------------------- ### LinkParser Spec - Linkage Tests Source: https://github.com/ged/linkparser/blob/master/Manifest.txt RSpec tests for the Linkage class in LinkParser. These focus on the loading and internal representation of linkage data. ```ruby require 'spec_helper' describe LinkParser::Linkage do it "should load linkage from a path" do # Assuming a dummy linkage file exists at 'spec/fixtures/dummy.linkage' # This test would need a real linkage file to pass. # linkage = LinkParser::Linkage.new('spec/fixtures/dummy.linkage') # expect(linkage).to be_a(LinkParser::Linkage) end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.