Class: LinkParser::Linkage
- Inherits:
-
Object
- Object
- LinkParser::Linkage
- Extended by:
- DeprecationUtilities
- Defined in:
- lib/linkparser/linkage.rb,
ext/linkage.c
Overview
Additional high-level functionality for LinkParser::Sentence objects.
Synopsis
Authors
-
Michael Granger <[email protected]>
Version
$Id: linkage.rb,v a5e7d9e3cf5c 2010/11/25 00:50:55 ged $
License
:include: LICENSE –
See the LICENSE file for copyright/licensing information.
Defined Under Namespace
Classes: Link
Constant Summary collapse
- LINK_TYPES =
Descriptions of the linkage types, keyed by linkage symbol
{ :A => %{connects pre-noun ("attributive") adjectives to following nouns: "The BIG DOG chased me", "The BIG BLACK UGLY DOG chased me".}, :AA => %{is used in the construction "How [adj] a [noun] was it?". It connects the adjective to the following "a".}, :AF => %{connects adjectives to verbs in cases where the adjective is fronted, such as questions and indirect questions: "How BIG IS it?"}, :AL => %{connects a few determiners like "all" or "both" to following determiners: "ALL THE people are here".}, :AM => %{connects "as" to "much" or "many": "I don't go out AS MUCH now".}, :AN => %{connects noun-modifiers to following nouns: "The TAX PROPOSAL was rejected".}, :AZ => %{connects the word "as" back to certain verbs that can take "[obj] as [adj]" as a complement: "He VIEWED him AS stupid".}, :B => %{serves various functions involving relative clauses and questions. It connects transitive verbs back to their objects in relative clauses, questions, and indirect questions ("The DOG we CHASED", "WHO did you SEE?"); it also connects the main noun to the finite verb in subject-type relative clauses ("The DOG who CHASED me was black").}, :BI => %{connects forms of the verb "be" to certain idiomatic expressions: for example, cases like "He IS PRESIDENT of the company".}, :BT => %{is used with time expressions acting as fronted objects: "How many YEARS did it LAST?".}, :BW => %{connects "what" to various verbs like "think", which are not really transitive but can connect back to "what" in questions: "WHAT do you THINK?"}, :C => %{links conjunctions to subjects of subordinate clauses ("He left WHEN HE saw me"). it also links certain verbs to subjects of embedded clauses ("He SAID HE was sorry").}, :CC => %{connects clauses to following coordinating conjunctions ("SHE left BUT we stayed").}, :CO => %{connects "openers" to subjects of clauses: "APPARENTLY / ON Tuesday , THEY went to a movie".}, :CP => %{connects paraphrasing or quoting verbs to the wall (and, indirectly, to the paraphrased expression): "///// That is untrue, the spokesman SAID."}, :CQ => %{connects to auxiliaries in comparative constructions involving s-v inversion: "SHE has more money THAN DOES Joe".}, :CX => %{is used in comparative constructions where the right half of the comparative contains only an auxiliary: "She has more money THAN he DOES".}, :D => %{connects determiners to nouns: "THE DOG chased A CAT and SOME BIRDS".}, :DD => %{connects definite determiners ("the", "his") to certain things like number expressions and adjectives acting as nouns: "THE POOR", "THE TWO he mentioned".}, :DG => %{connects the word "The" with proper nouns: "the Riviera", "the Mississippi".}, :DP => %{connects possessive determiners to gerunds: "YOUR TELLING John to leave was stupid".}, :DT => %{connects determiners to nouns in idiomatic time expressions: "NEXT WEEK", "NEXT THURSDAY".}, :E => %{is used for verb-modifying adverbs which precede the verb: "He is APPARENTLY LEAVING".}, :EA => %{connects adverbs to adjectives: "She is a VERY GOOD player".}, :EB => %{connects adverbs to forms of "be" before an object or prepositional phrase: "He IS APPARENTLY a good programmer".}, :EC => %{connects adverbs to comparative adjectives: "It is MUCH BIGGER"}, :EE => %{connects adverbs to other adverbs: "He ran VERY QUICKLY".}, :EF => %{connects the word "enough" to preceding adjectives and adverbs: "He didn't run QUICKLY ENOUGH".}, :EI => %{connects a few adverbs to "after" and "before": "I left SOON AFTER I saw you".}, :EL => %{connects certain words to the word "else": something / everything / anything / nothing , somewhere (etc.), and someone (etc.).}, :EN => %{connects certain adverbs to expressions of quantity: "The class has NEARLY FIFTY students".}, :ER => %{is used the expression "The x-er..., the y-er...". it connects the two halfs of the expression together, via the comparative words (e.g. "The FASTER it is, the MORE they will like it").}, :EZ => %{connects certain adverbs to the word "as", like "just" and "almost": "You're JUST AS good as he is."}, :FL => %{connects "for" to "long": "I didn't wait FOR LONG".}, :FM => %{connects the preposition "from" to various other prepositions: "We heard a scream FROM INSIDE the house".}, :G => %{connects proper noun words together in series: "GEORGE HERBERT WALKER BUSH is here."}, :GN => %{(stage 2 only) connects a proper noun to a preceding common noun which introduces it: "The ACTOR Eddie MURPHY attended the event".}, :H => %{connects "how" to "much" or "many": "HOW MUCH money do you have".}, :I => %{connects infinitive verb forms to certain words such as modal verbs and "to": "You MUST DO it", "I want TO DO it".}, :ID => %{is a special class of link-types generated by the parser, with arbitrary four-letter names (such as "IDBT"), to connect together words of idiomatic expressions such as "at_hand" and "head_of_state".}, :IN => %{connects the preposition "in" to certain time expressions: "We did it IN DECEMBER".}, :J => %{connects prepositions to their objects: "The man WITH the HAT is here".}, :JG => %{connects certain prepositions to proper-noun objects: "The Emir OF KUWAIT is here".}, :JQ => %{connects prepositions to question-word determiners in "prepositional questions": "IN WHICH room were you sleeping?"}, :JT => %{connects certain conjunctions to time-expressions like "last week": "UNTIL last WEEK, I thought she liked me".}, :K => %{connects certain verbs with particles like "in", "out", "up" and the like: "He STOOD UP and WALKED OUT".}, :L => %{connects certain determiners to superlative adjectives: "He has THE BIGGEST room".}, :LE => %{is used in comparative constructions to connect an adjective to the second half of the comparative expression beyond a complement phrase: "It is more LIKELY that Joe will go THAN that Fred will go".}, :LI => %{connects certain verbs to the preposition "like": "I FEEL LIKE a fool."}, :M => %{connects nouns to various kinds of post-noun modifiers: prepositional phrases ("The MAN WITH the hat"), participle modifiers ("The WOMAN CARRYING the box"), prepositional relatives ("The MAN TO whom I was speaking"), and other kinds.}, :MF => %{is used in the expression "Many people were injured, SOME OF THEM children".}, :MG => %{allows certain prepositions to modify proper nouns: "The EMIR OF Kuwait is here".}, :MV => %{connects verbs and adjectives to modifying phrases that follow, like adverbs ("The dog RAN QUICKLY"), prepositional phrases ("The dog RAN IN the yard"), subordinating conjunctions ("He LEFT WHEN he saw me"), comparatives, participle phrases with commas, and other things.}, :MX => %{connects modifying phrases with commas to preceding nouns: "The DOG, a POODLE, was black". "JOHN, IN a black suit, looked great".}, :N => %{connects the word "not" to preceding auxiliaries: "He DID NOT go".}, :ND => %{connects numbers with expressions that require numerical determiners: "I saw him THREE WEEKS ago".}, :NF => %{is used with NJ in idiomatic number expressions involving "of": "He lives two THIRDS OF a mile from here".}, :NI => %{is used in a few special idiomatic number phrases: "I have BETWEEN 5 AND 20 dogs".}, :NJ => %{is used with NF in idiomatic number expressions involving "of": "He lives two thirds OF a MILE from here".}, :NN => %{connects number words together in series: "FOUR HUNDRED THOUSAND people live here".}, :NO => %{is used on words which have no normal linkage requirement, but need to be included in the dictionary, such as "um" and "ah".}, :NR => %{connects fraction words with superlatives: "It is the THIRD BIGGEST city in China".}, :NS => %{connects singular numbers (one, 1, a) to idiomatic expressions requiring number determiners: "I saw him ONE WEEK ago".}, :NT => %{connects "not" to "to": "I told you NOT TO come".}, :NW => %{is used in idiomatic fraction expressions: "TWO THIRDS of the students were women".}, :O => %{connects transitive verbs to their objects, direct or indirect: "She SAW ME", "I GAVE HIM the BOOK".}, :OD => %{is used for verbs like "rise" and "fall" which can take expressions of distance as complements: "It FELL five FEET".}, :OF => %{connects certain verbs and adjectives to the word "of": "She ACCUSED him OF the crime", "I'm PROUD OF you".}, :ON => %{connectors the word "on" to dates or days of the week in time expressions: "We saw her again ON TUESDAY".}, :OT => %{is used for verbs like "last" which can take time expressions as objects: "It LASTED five HOURS".}, :OX => %{is an object connector, analogous to SF, used for special "filler" words like "it" and "there" when used as objects: "That MAKES IT unlikely that she will come".}, :P => %{connects forms of the verb "be" to various words that can be its complements: prepositions, adjectives, and passive and progressive participles: "He WAS [ ANGRY / IN the yard / CHOSEN / RUNNING ]".}, :PF => %{is used in certain questions with "be", when the complement need of "be" is satisfied by a preceding question word: "WHERE are you?", "WHEN will it BE?"}, :PP => %{connects forms of "have" with past participles: "He HAS GONE".}, :Q => %{is used in questions. It connects the wall to the auxiliary in simple yes-no questions ("///// DID you go?"); it connects the question word to the auxiliary in where-when-how questions ("WHERE DID you go").}, :QI => %{connects certain verbs and adjectives to question-words, forming indirect questions: "He WONDERED WHAT she would say".}, :R => %{connects nouns to relative clauses. In subject-type relatives, it connects to the relative pronoun ("The DOG WHO chased me was black"); in object-type relatives, it connects either to the relative pronoun or to the subject of the relative clause ("The DOG THAT we chased was black", "The DOG WE chased was black").}, :RS => %{is used in subject-type relative clauses to connect the relative pronoun to the verb: "The dog WHO CHASED me was black".}, :RW => %{connects the right-wall to the left-wall in cases where the right-wall is not needed for punctuation purposes.}, :S => %{connects subject nouns to finite verbs: "The DOG CHASED the cat": "The DOG [ IS chasing / HAS chased / WILL chase ] the cat".}, :SF => %{is a special connector used to connect "filler" subjects like "it" and "there" to finite verbs: "THERE IS a problem", "IT IS likely that he will go".}, :SFI => %{connects "filler" subjects like "it" and "there" to verbs in cases with subject-verb inversion: "IS THERE a problem?", "IS IT likely that he will go?"}, :SI => %{connects subject nouns to finite verbs in cases of subject-verb inversion: "IS JOHN coming?", "Who DID HE see?"}, :SX => %{connects "I" to special first-person verbs lke "was" and "am".}, :SXI => %{connects "I" to first-person verbs in cases of s-v inversion.}, :TA => %{is used to connect adjectives like "late" to month names: "We did it in LATE DECEMBER".}, :TD => %{connects day-of-the-week words to time expressions like "morning": "We'll do it MONDAY MORNING".}, :TH => %{connects words that take "that [clause]" complements with the word "that". These include verbs ("She TOLD him THAT..."), nouns ("The IDEA THAT..."), and adjectives ("We are CERTAIN THAT").}, :TI => %{is used for titles like "president", which can be used in certain cirumstances without a determiner: "AS PRESIDENT of the company, it is my decision".}, :TM => %{is used to connect month names to day numbers: "It happened on JANUARY 21".}, :TO => %{connects verbs and adjectives which take infinitival complements to the word "to": "We TRIED TO start the car", "We are EAGER TO do it".}, :TQ => %{is the determiner connector for time expressions acting as fronted objects: "How MANY YEARS did it last".}, :TS => %{connects certain verbs that can take subjunctive clauses as complements - "suggest", "require" - to the word that: "We SUGGESTED THAT he go".}, :TW => %{connects days of the week to dates in time expressions: "The meeting will be on MONDAY, JANUARY 21".}, :TY => %{is used for certain idiomatic usages of year numbers: "I saw him on January 21 , 1990 ". (In this case it connects the day number to the year number.)}, :U => %{is a special connector on nouns, which is disjoined with both the determiner and subject-object connectors. It is used in idiomatic expressions like "What KIND_OF DOG did you buy?"}, :UN => %{connects the words "until" and "since" to certain time phrases like "after [clause]": "You should wait UNTIL AFTER you talk to me".}, :V => %{connects various verbs to idiomatic expressions that may be non-adjacent: "We TOOK him FOR_GRANTED", "We HELD her RESPONSIBLE".}, :W => %{connects the subjects of main clauses to the wall, in ordinary declaratives, imperatives, and most questions (except yes-no questions). It also connects coordinating conjunctions to following clauses: "We left BUT SHE stayed".}, :WN => %{connects the word "when" to time nouns like "year": "The YEAR WHEN we lived in England was wonderful".}, :WR => %{connects the word "where" to a few verbs like "put" in questions like "WHERE did you PUT it?".}, :X => %{is used with punctuation, to connect punctuation symbols either to words or to each other. For example, in this case, POODLE connects to commas on either side: "The dog , a POODLE , was black."}, :Y => %{is used in certain idiomatic time and place expressions, to connect quantity expressions to the head word of the expression: "He left three HOURS AGO", "She lives three MILES FROM the station".}, :YP => %{connects plural noun forms ending in s to "'" in possessive constructions: "The STUDENTS ' rooms are large".}, :YS => %{connects nouns to the possessive suffix "'s": "JOHN 'S dog is black".}, :Z => %{connects the preposition "as" to certain verbs: "AS we EXPECTED, he was late".}, }
- CTree =
label, :children, :start, :end)
Struct that contains links of a constituent tree (
Instance Method Summary collapse
-
#and_cost ⇒ Fixnum
Returns the AND cost of the linkage, which is the difference in length between and-list elements.
-
#canonical? ⇒ Boolean
Returns
true
if the linkage is canonical. -
#compute_union ⇒ Boolean
If the linkage has a conjunction, combine all of the links occurring in all sublinkages together – in effect creating a “master” linkage (which may have crossing links).
-
#constituent_tree ⇒ Hash
Return the Linkage’s constituent tree as a Array of hierarchical “CTree” structs.
-
#constituent_tree_string(mode = 1) ⇒ String
Return the constituent tree as a printable string.
-
#current_sublinkage ⇒ Fixnum
Get the index of the current sublinkage.
-
#current_sublinkage=(index) ⇒ Boolean
After this call, all operations on the linkage will refer to the index-th sublinkage.
-
#diagram ⇒ String
Return a String containing a diagram of the linkage.
-
#disjunct_cost ⇒ Fixnum
Returns the connector or disjunct cost of the linkage.
-
#disjunct_strings ⇒ Object
disjunct_strings -> array.
-
#disjuncts ⇒ Object
Return an Array of parsed (well, just split on whitespace for now) disjunct strings for the linkage.
-
#has_conjunction? ⇒ Boolean
Returns
true
if the linkage has more than one sublinkage (i.e., the sentence has a conjunction). -
#has_inconsistent_domains? ⇒ Boolean
Returns
true
if the linkage has inconsistent domains. -
#imperative? ⇒ Boolean
Returns
true
if the linkage indicates the sentence is phrased in the imperative voice. -
#improper? ⇒ Boolean
Returns
true
if the linkage is “improper”. -
#new(index, sentence, options = {}) ⇒ LinkParser::Linkage
constructor
Create a new LinkParser::Linkage object out of the linkage indicated by
index
(a positive Integer) from the specified sentence (a LinkParser::Sentence). -
#inspect ⇒ Object
Return a human-readable representation of the Sentence object.
-
#link(index) ⇒ Object
Return the indexth link.
-
#link_cost ⇒ Fixnum
Returns the total (LEN) cost of the linkage, which is the total length of all links in the sentence minus the number of words – since the total link length is never less than the number of words.
-
#link_domain_names(index) ⇒ Array
Returns the names of the domains the index-th link belongs to.
-
#link_label(index) ⇒ Object
link_label( index ) -> str – The “intersection” of the left and right connectors that comprise the link.
-
#link_length(index) ⇒ Object
link_length( index ) – The number of words spanned by the index-th link of the current sublinkage.
-
#link_llabel(index) ⇒ Object
link_llabel -> str – The label on the left word of the index-th link of the current sublinkage.
-
#link_lword(index) ⇒ Object
link_lword( index ) – The number of the word on the left end of the index-th link of the current sublinkage.
-
#link_num_domains(index) ⇒ Fixnum
Returns the number of domains in the index-th link.
-
#link_rlabel(index) ⇒ Object
link_rlabel -> str – The label on the right word of the index-th link of the current sublinkage.
-
#link_rword(index) ⇒ Object
link_rword( index ) – The number of the word on the right end of the index-th link of the current sublinkage.
-
#links ⇒ Object
Return the Array of words in the sentence as tokenized by the parser.
-
#links_and_domains ⇒ String
Return a String containing a lists all of the links and domain names for the current sublinkage.
-
#nouns ⇒ Object
Return an Array of all the nouns in the linkage.
-
#num_links ⇒ Object
(also: #link_count)
num_links – The number of links used in the current sublinkage.
-
#num_sublinkages ⇒ Fixnum
Return the number of sublinkages for a linkage with conjunctions, 1 otherwise.
-
#num_words ⇒ Object
(also: #word_count)
num_words – The number of words in the sentence for which this is a linkage.
-
#object ⇒ Object
Return the object from the linkage.
-
#postscript_diagram(full_doc = false) ⇒ String
Returns the macros needed to print out the linkage in a postscript file.
-
#subject ⇒ Object
Return the subject from the linkage.
-
#unused_word_cost ⇒ Fixnum
Returns the unused word cost of the linkage, which corresponds to the number of null links that were required to parse it.
-
#verb ⇒ Object
Return the verb word from the linkage.
-
#violation_name ⇒ String
If the linkage violated any post-processing rules, this method returns the name of the violated rule in the post-process knowledge file.
-
#words ⇒ Array
Return the Array of word spellings or individual word spelling for the current sublinkage.
Methods included from DeprecationUtilities
Constructor Details
#new(index, sentence, options = {}) ⇒ LinkParser::Linkage
Create a new LinkParser::Linkage object out of the linkage indicated by index
(a positive Integer) from the specified sentence (a LinkParser::Sentence). The optional options hash can be used to override the parse options of the Sentence for the new linkage.
144 145 146 |
# File 'ext/linkage.c', line 144 static VALUE rlink_linkage_init( argc, argv, self ) int argc; |
Instance Method Details
#and_cost ⇒ Fixnum
Returns the AND cost of the linkage, which is the difference in length between and-list elements.
643 644 645 646 647 648 649 650 651 |
# File 'ext/linkage.c', line 643
static VALUE
rlink_linkage_and_cost( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval;
rval = linkage_and_cost( (Linkage)ptr->linkage );
return INT2FIX( rval );
}
|
#canonical? ⇒ Boolean
Returns true
if the linkage is canonical. The canonical linkage is the one in which the minimal disjunct that ever occurrs in a position is used in that position.
682 683 684 685 686 687 688 689 690 |
# File 'ext/linkage.c', line 682
static VALUE
rlink_linkage_canonical_p( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval = 0;
rval = linkage_is_canonical( (Linkage)ptr->linkage );
return rval ? Qtrue : Qfalse;
}
|
#compute_union ⇒ Boolean
If the linkage has a conjunction, combine all of the links occurring in all sublinkages together – in effect creating a “master” linkage (which may have crossing links). The union is created as another sublinkage, thus increasing the number of sublinkages by one, and is returned by this method. If the linkage has no conjunctions, computing its union has no effect. This method returns true if computing its union caused another sublinkage to be created.
585 586 587 588 589 590 591 592 593 594 595 |
# File 'ext/linkage.c', line 585
static VALUE
rlink_linkage_compute_union( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int before, after;
before = linkage_get_num_sublinkages( (Linkage)ptr->linkage );
linkage_compute_union( (Linkage)ptr->linkage );
after = linkage_get_num_sublinkages( (Linkage)ptr->linkage );
return (after > before) ? Qtrue : Qfalse;
}
|
#constituent_tree ⇒ Hash
Return the Linkage’s constituent tree as a Array of hierarchical “CTree” structs.
sent = dict.parse( "He is a big dog." )
link = sent.linkages.first
ctree = link.constituent_tree
# => [#<struct Struct::LinkParserLinkageCTree label="S",
children=[#<struct Struct::LinkParserLinkageCTree label="NP">, ...],
start=0, end=5>]
769 770 771 772 773 774 775 776 777 778 779 780 |
# File 'ext/linkage.c', line 769
static VALUE
rlink_linkage_constituent_tree( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
CNode *ctree = NULL;
VALUE rval = Qnil;
ctree = linkage_constituent_tree( (Linkage)ptr->linkage );
rval = rlink_linkage_make_cnode_array( ctree );
linkage_free_constituent_tree( ctree );
return rval;
}
|
#constituent_tree_string(mode = 1) ⇒ String
Return the constituent tree as a printable string.
Example:
sent = dict.parse( "He is a big dog." )
link = sent.linkages.first
link.constituent_tree_string
# ==> "(S (NP He)\n (VP is\n (NP a big dog))\n .)\n"
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'ext/linkage.c', line 834
static VALUE
rlink_linkage_constituent_tree_string( int argc, VALUE *argv, VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
char *ctree_string = NULL;
VALUE rval = Qnil, modenum = Qnil;
int mode;
if ( rb_scan_args(argc, argv, "01", &modenum) == 1 ) {
mode = NUM2INT( modenum );
} else {
mode = 1;
}
if ( mode < 1 || mode > 3 )
rb_raise( rb_eArgError, "Illegal mode %d specified.", mode );
ctree_string = linkage_print_constituent_tree( (Linkage)ptr->linkage, mode );
if ( ctree_string ) {
rval = rb_str_new2( ctree_string );
linkage_free_constituent_tree_str( ctree_string );
} else {
rval = Qnil;
}
return rval;
}
|
#current_sublinkage ⇒ Fixnum
Get the index of the current sublinkage.
325 326 327 328 329 330 331 332 333 |
# File 'ext/linkage.c', line 325
static VALUE
rlink_linkage_current_sublinkage( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval = 0;
rval = linkage_get_current_sublinkage( (Linkage)ptr->linkage );
return INT2FIX( rval );
}
|
#current_sublinkage=(index) ⇒ Boolean
After this call, all operations on the linkage will refer to the index-th sublinkage. In the case of a linkage without conjunctions, this has no effect.
308 309 310 311 312 313 314 315 316 |
# File 'ext/linkage.c', line 308
static VALUE
rlink_linkage_current_sublinkage_eq( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval = 0;
rval = linkage_set_current_sublinkage( (Linkage)ptr->linkage, NUM2INT(index) );
return INT2FIX( rval );
}
|
#diagram ⇒ String
Return a String containing a diagram of the linkage.
197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'ext/linkage.c', line 197
static VALUE
rlink_linkage_diagram( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
char *diagram_cstr;
VALUE diagram;
diagram_cstr = linkage_print_diagram( (Linkage)ptr->linkage );
diagram = rb_str_new2( diagram_cstr );
linkage_free_diagram( diagram_cstr );
return diagram;
}
|
#disjunct_cost ⇒ Fixnum
Returns the connector or disjunct cost of the linkage.
624 625 626 627 628 629 630 631 632 |
# File 'ext/linkage.c', line 624
static VALUE
rlink_linkage_disjunct_cost( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval;
rval = linkage_disjunct_cost( (Linkage)ptr->linkage );
return INT2FIX( rval );
}
|
#disjunct_strings ⇒ Object
disjunct_strings -> array
Return an Array of Strings showing the disjuncts that were actually used in association with each corresponding word in the current linkage. Each string shows the disjuncts in proper order; that is, left-to-right, in the order in which they link to other words. The returned strings can be thought of as a very precise part-of-speech-like label for each word, indicating how it was used in the given sentence; this can be useful for corpus statistics.
For a parsed version of the disjunct strings, call #disjuncts instead.
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'ext/linkage.c', line 472
static VALUE
rlink_linkage_get_disjunct_strings( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
const char *disjunct;
int count, i;
VALUE disjuncts_ary;
count = linkage_get_num_words( (Linkage)ptr->linkage );
disjuncts_ary = rb_ary_new2( count );
for ( i = 0; i < count; i++ ) {
#ifdef HAVE_LINKAGE_GET_DISJUNCT_STR
disjunct = linkage_get_disjunct_str( (Linkage)ptr->linkage, i );
#else
disjunct = linkage_get_disjunct( (Linkage)ptr->linkage, i );
#endif
if ( disjunct ) {
rb_ary_store( disjuncts_ary, i, rb_str_new2(disjunct) );
} else {
rb_ary_store( disjuncts_ary, i, Qnil );
}
}
return disjuncts_ary;
}
|
#disjuncts ⇒ Object
Return an Array of parsed (well, just split on whitespace for now) disjunct strings for the linkage.
207 208 209 210 211 212 213 214 215 |
# File 'lib/linkparser/linkage.rb', line 207 def disjuncts return self.disjunct_strings.collect do |dstr| if dstr.nil? nil else dstr.split end end end |
#has_conjunction? ⇒ Boolean
Returns true
if the linkage has more than one sublinkage (i.e., the sentence has a conjunction).
39 40 41 |
# File 'lib/linkparser/linkage.rb', line 39 def has_conjunction? return self.num_sublinkages > 1 end |
#has_inconsistent_domains? ⇒ Boolean
Returns true
if the linkage has inconsistent domains. – :FIXME: Find out what it means that a linkage has inconsistent domains.
722 723 724 725 726 727 728 729 730 |
# File 'ext/linkage.c', line 722
static VALUE
rlink_linkage_has_inconsistent_domains_p( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval = 0;
rval = linkage_has_inconsistent_domains( (Linkage)ptr->linkage );
return rval ? Qtrue : Qfalse;
}
|
#imperative? ⇒ Boolean
Returns true
if the linkage indicates the sentence is phrased in the imperative voice.
260 261 262 263 |
# File 'lib/linkparser/linkage.rb', line 260 def imperative? return self.links.find {|link| link.label == 'Wi' && link.rword =~ /\.v$/ } ? true : false end |
#improper? ⇒ Boolean
Returns true
if the linkage is “improper”. – :FIXME: Find out what an “improper fat linkage” is.
702 703 704 705 706 707 708 709 710 |
# File 'ext/linkage.c', line 702
static VALUE
rlink_linkage_improper_p( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval = 0;
rval = linkage_is_improper( (Linkage)ptr->linkage );
return rval ? Qtrue : Qfalse;
}
|
#inspect ⇒ Object
Return a human-readable representation of the Sentence object.
173 174 175 176 177 178 179 |
# File 'lib/linkparser/linkage.rb', line 173 def inspect return %{#<%s:0x%x: [%d links]>} % [ self.class.name, self.object_id / 2, self.num_links ] end |
#link(index) ⇒ Object
Return the indexth link.
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/linkparser/linkage.rb', line 183 def link( index ) Link.new( self.words[ self.link_lword(index) ], self.words[ self.link_rword(index) ], self.link_length(index), self.link_label(index), self.link_llabel(index), self.link_rlabel(index), LINK_TYPES[ self.link_label(index).gsub(/[^A-Z]+/, '').to_sym ] ) end |
#link_cost ⇒ Fixnum
Returns the total (LEN) cost of the linkage, which is the total length of all links in the sentence minus the number of words – since the total link length is never less than the number of words.
663 664 665 666 667 668 669 670 671 |
# File 'ext/linkage.c', line 663
static VALUE
rlink_linkage_link_cost( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval;
rval = linkage_link_cost( (Linkage)ptr->linkage );
return INT2FIX( rval );
}
|
#link_domain_names(index) ⇒ Array
Returns the names of the domains the index-th link belongs to.
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'ext/linkage.c', line 524
static VALUE
rlink_linkage_get_link_domain_names( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
const char **names;
int i = NUM2INT( index );
int count;
VALUE names_ary;
names = linkage_get_link_domain_names( (Linkage)ptr->linkage, i );
count = linkage_get_link_num_domains( (Linkage)ptr->linkage, i );
if ( count < 0 ) return rb_ary_new();
names_ary = rb_ary_new2( count );
for ( i = 0; i < count; i++ ) {
rb_ary_store( names_ary, i, rb_str_new2(names[i]) );
}
return names_ary;
}
|
#link_label(index) ⇒ Object
link_label( index ) -> str – The “intersection” of the left and right connectors that comprise the link.
411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/linkage.c', line 411
static VALUE
rlink_linkage_get_link_label( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int i = NUM2INT( index );
const char *label;
label = linkage_get_link_label( (Linkage)ptr->linkage, i );
if ( !label ) return Qnil;
return rb_str_new2( label );
}
|
#link_length(index) ⇒ Object
link_length( index ) – The number of words spanned by the index-th link of the current sublinkage.
397 398 399 400 401 402 403 |
# File 'ext/linkage.c', line 397
static VALUE
rlink_linkage_get_link_length( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int i = NUM2INT( index );
return INT2FIX( linkage_get_link_length((Linkage)ptr->linkage, i) );
}
|
#link_llabel(index) ⇒ Object
link_llabel -> str – The label on the left word of the index-th link of the current sublinkage.
429 430 431 432 433 434 435 436 437 438 439 |
# File 'ext/linkage.c', line 429
static VALUE
rlink_linkage_get_link_llabel( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int i = NUM2INT( index );
const char *label = NULL;
label = linkage_get_link_llabel( (Linkage)ptr->linkage, i );
if ( !label ) return Qnil;
return rb_str_new2( label );
}
|
#link_lword(index) ⇒ Object
link_lword( index ) – The number of the word on the left end of the index-th link of the current sublinkage.
368 369 370 371 372 373 374 |
# File 'ext/linkage.c', line 368
static VALUE
rlink_linkage_get_link_lword( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int i = NUM2INT( index );
return INT2FIX( linkage_get_link_lword((Linkage)ptr->linkage, i) );
}
|
#link_num_domains(index) ⇒ Fixnum
Returns the number of domains in the index-th link.
507 508 509 510 511 512 513 514 515 |
# File 'ext/linkage.c', line 507
static VALUE
rlink_linkage_get_link_num_domains( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int i = NUM2INT( index );
int count = 0;
count = linkage_get_link_num_domains( (Linkage)ptr->linkage, i );
return INT2FIX( count );
}
|
#link_rlabel(index) ⇒ Object
link_rlabel -> str – The label on the right word of the index-th link of the current sublinkage.
446 447 448 449 450 451 452 453 454 455 456 |
# File 'ext/linkage.c', line 446
static VALUE
rlink_linkage_get_link_rlabel( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int i = NUM2INT( index );
const char *label = NULL;
label = linkage_get_link_rlabel( (Linkage)ptr->linkage, i );
if ( !label ) return Qnil;
return rb_str_new2( label );
}
|
#link_rword(index) ⇒ Object
link_rword( index ) – The number of the word on the right end of the index-th link of the current sublinkage.
383 384 385 386 387 388 389 |
# File 'ext/linkage.c', line 383
static VALUE
rlink_linkage_get_link_rword( VALUE self, VALUE index ) {
struct rlink_linkage *ptr = get_linkage( self );
int i = NUM2INT( index );
return INT2FIX( linkage_get_link_rword((Linkage)ptr->linkage, i) );
}
|
#links ⇒ Object
Return the Array of words in the sentence as tokenized by the parser.
198 199 200 201 202 |
# File 'lib/linkparser/linkage.rb', line 198 def links return ( 0...self.link_count ).collect do |i| self.link( i ) end end |
#links_and_domains ⇒ String
Return a String containing a lists all of the links and domain names for the current sublinkage.
Example:
sent = dict.parse("I eat, therefore I think")
puts sent.linkages.first.links_and_domains
prints:
///// RW <---RW----> RW /////
(m) ///// Wd <---Wd----> Wd I.p
(m) I.p CC <---CC----> CC therefore
(m) I.p Sp*i <---Sp*i--> Sp eat
(m) , Xd <---Xd----> Xd therefore
(m) (m) therefore Wd <---Wd----> Wd I.p
(m) (m) I.p Sp*i <---Sp*i--> Sp think.v
256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'ext/linkage.c', line 256
static VALUE
rlink_linkage_links_and_domains( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
char *diagram_cstr;
VALUE diagram;
diagram_cstr = linkage_print_links_and_domains( (Linkage)ptr->linkage );
diagram = rb_str_new2( diagram_cstr );
linkage_free_links_and_domains( diagram_cstr );
return diagram;
}
|
#nouns ⇒ Object
Return an Array of all the nouns in the linkage.
247 248 249 250 251 252 253 254 255 |
# File 'lib/linkparser/linkage.rb', line 247 def nouns nouns = [] self.links.each do |link| nouns << $1 if link.lword =~ /^(.*)\.n(?:-\w)?$/ nouns << $1 if link.rword =~ /^(.*)\.n(?:-\w)?$/ end return nouns.uniq end |
#num_links ⇒ Object Also known as: link_count
num_links – The number of links used in the current sublinkage.
355 356 357 358 359 |
# File 'ext/linkage.c', line 355
static VALUE
rlink_linkage_get_num_links( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
return INT2FIX( linkage_get_num_links((Linkage)ptr->linkage) );
}
|
#num_sublinkages ⇒ Fixnum
Return the number of sublinkages for a linkage with conjunctions, 1 otherwise.
293 294 295 296 297 |
# File 'ext/linkage.c', line 293
static VALUE
rlink_linkage_num_sublinkages( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
return INT2FIX( linkage_get_num_sublinkages((Linkage)ptr->linkage) );
}
|
#num_words ⇒ Object Also known as: word_count
num_words – The number of words in the sentence for which this is a linkage. Note that this function does not return the number of words used in the current sublinkage.
343 344 345 346 347 |
# File 'ext/linkage.c', line 343
static VALUE
rlink_linkage_get_num_words( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
return INT2FIX( linkage_get_num_words((Linkage)ptr->linkage) );
}
|
#object ⇒ Object
Return the object from the linkage.
240 241 242 243 |
# File 'lib/linkparser/linkage.rb', line 240 def object link = self.links.find {|link| link.rlabel[0] == ?O } or return nil return link.rword.sub( /\.[np](?:-\w)?$/, '' ) end |
#postscript_diagram(full_doc = false) ⇒ String
Returns the macros needed to print out the linkage in a postscript file. By default, the output is just the set of postscript macros that describe the diagram. With full_doc=true a complete encapsulated postscript document is returned.
220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'ext/linkage.c', line 220
static VALUE
rlink_linkage_print_postscript( VALUE self, VALUE full_doc ) {
struct rlink_linkage *ptr = get_linkage( self );
char *diagram_cstr;
VALUE diagram;
diagram_cstr = linkage_print_postscript( (Linkage)ptr->linkage,
RTEST(full_doc) ? 1 : 0 );
diagram = rb_str_new2( diagram_cstr );
linkage_free_postscript( diagram_cstr );
return diagram;
}
|
#subject ⇒ Object
Return the subject from the linkage.
233 234 235 236 |
# File 'lib/linkparser/linkage.rb', line 233 def subject link = self.links.find {|link| link.llabel[0] == ?S } or return nil return link.lword.sub( /\.[np](?:-\w)?$/, '' ) end |
#unused_word_cost ⇒ Fixnum
Returns the unused word cost of the linkage, which corresponds to the number of null links that were required to parse it.
606 607 608 609 610 611 612 613 614 |
# File 'ext/linkage.c', line 606
static VALUE
rlink_linkage_unused_word_cost( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
int rval;
rval = linkage_unused_word_cost( (Linkage)ptr->linkage );
return INT2FIX( rval );
}
|
#verb ⇒ Object
Return the verb word from the linkage.
219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/linkparser/linkage.rb', line 219 def verb if link = self.links.find {|link| link.llabel =~ /^(O([DFNTX]?)|P|BI|K|LI|MV|Q)[a-z\*]*/ } # $deferr.puts "Picking %s: LL of %p is %s" % [ link.lword, link, link.llabel ] return link.lword.sub( /\.v(-d)?$/, '' ) elsif link = self.links.find {|link| link.rlabel =~ /^(SI|S|AF)[a-z\*]*/ } # $deferr.puts "Picking %s: RL of %p is %s" % [ link.rword, link, link.rlabel ] return link.rword.sub( /\.v(-d)?$/, '' ) else return nil end end |
#violation_name ⇒ String
If the linkage violated any post-processing rules, this method returns the name of the violated rule in the post-process knowledge file.
740 741 742 743 744 745 746 747 748 749 750 751 752 |
# File 'ext/linkage.c', line 740
static VALUE
rlink_linkage_get_violation_name( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
const char *violation_name = NULL;
violation_name = linkage_get_violation_name( (Linkage)ptr->linkage );
if ( violation_name ) {
return rb_str_new2( violation_name );
} else {
return Qnil;
}
}
|
#words ⇒ Array
Return the Array of word spellings or individual word spelling for the current sublinkage. These are the “inflected” spellings, such as “dog.n”. The original spellings can be obtained by calls to Sentence#words.
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
# File 'ext/linkage.c', line 554
static VALUE
rlink_linkage_get_words( VALUE self ) {
struct rlink_linkage *ptr = get_linkage( self );
const char **words;
int count, i;
VALUE words_ary;
count = linkage_get_num_words( (Linkage)ptr->linkage );
words = linkage_get_words( (Linkage)ptr->linkage );
words_ary = rb_ary_new2( count );
for ( i = 0; i < count; i++ ) {
rb_ary_store( words_ary, i, rb_str_new2(words[i]) );
}
return words_ary;
}
|