Skip to content

Commit

Permalink
Version 1.0 as described in MUHAI deliverable
Browse files Browse the repository at this point in the history
  • Loading branch information
remivantrijp committed Apr 26, 2022
1 parent 1a75db0 commit 7db6326
Show file tree
Hide file tree
Showing 20 changed files with 894 additions and 33 deletions.
3 changes: 2 additions & 1 deletion configuration-and-utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

(defun convert-ica-string-to-ica-list (string)
"Converts a string representing a constituent analysis into a list representation."
(loop for pair in '(("." "\\.")
(loop for pair in '((":" "\\:")
("." "\\.")
("," "\\,")
("''" "PARENTH")
("``" "PARENTH")
Expand Down
3 changes: 2 additions & 1 deletion fcg-categories.lisp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

;; Copyright 2019 Sony Computer Science Laboratories Paris
;; Remi van Trijp (http://www.remivantrijp.eu)

Expand All @@ -18,7 +19,7 @@

;;; Definition of an FCG-CATEGORY.
;;; ------------------------------------------------------------------------------
;;; An FCG-category is a triplet of the form (category-name (parents) (fv-pairs)).
;;; An FCG-category is a triple of the form (category-name (parents) (fv-pairs)).
;;; The feature-value pairs of the fcg-category are meant to be the VALUE of a
;;; feature in the construction, such as SYN-CAT. Overwritting a value only goes
;;; one level deep.
Expand Down
12 changes: 8 additions & 4 deletions fcg-hybrids.asd
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@
(:file "pos-tags")
(:file "clear-dependency-specs")
(:file "represent-structures")
(:file "de-render")))))
(:file "de-render")
(:file "base-model")))
(:module "Italian"
:serial t
:components ((:file "categories")
(:file "de-render")
(:file "base-model")))))
(:file "examples"))
:description "Multilingual library for combining symbolic FCG-grammars with NLP tools. Currently, this is achieved by translating
output from the NLP-tools into transient structures, onto which FCG grammars can operate. In other words, this is
useful for integrating FCG as a step in an NLP-pipeline.")
:description "Multilingual library for combining symbolic FCG-grammars with NLP tools.")
260 changes: 260 additions & 0 deletions languages/English/base-model.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
;; Copyright Sony Computer Science Laboratories Paris
;; Author: Remi van Trijp (http://www.remivantrijp.eu)

;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at

;; http://www.apache.org/licenses/LICENSE-2.0

;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;;=========================================================================

(in-package :fcg)

(defparameter *fcg-english* nil "Parameter for the base model of English.")

(def-fcg-constructions english-base-model
:cxn-inventory *fcg-english*
:cxn-inventory-type hashed-fcg-construction-set
:feature-types ((fcg::constituents set)
(fcg::dependents set)
(fcg::footprints set)
(fcg::boundaries set-of-predicates)
(agreement sequence)
(args sequence)
(fcg::form set-of-predicates)
(fcg::meaning set-of-predicates))
:fcg-configurations (;; Form predicates
(:form-predicates meets)
;; ----------------------------------------------------------------------------------
;; Construction sets
;; ----------------------------------------------------------------------------------
(:parse-order structural hashed-string hashed-lex-id cxn)
(:hashed-labels hashed-string hashed-meaning hashed-lex-id)
;; ----------------------------------------------------------------------------------
;; Render and De-rendering
;; ----------------------------------------------------------------------------------
(:de-render-mode . :english-hybrid)
;; ----------------------------------------------------------------------------------
;; Node and Goal tests
;; ----------------------------------------------------------------------------------
(:node-tests :update-references
:check-duplicate :restrict-nr-of-nodes)
(:update-boundaries-feature . constituents)
(:parse-goal-tests :no-applicable-cxns)
(:production-goal-tests :no-applicable-cxns)
;; ----------------------------------------------------------------------------------
;; Construction Supplier
;; ----------------------------------------------------------------------------------
;;
;; For guiding search
;; ----------------------------------------------------------------------------------
(:queue-mode . :depth-first-avoid-duplicates)
(:max-search-depth . 100)
(:max-nr-of-nodes . 1500)
;; ----------------------------------------------------------------------------------
;; Miscellaneous
;; ----------------------------------------------------------------------------------
(:draw-meaning-as-network . t)
(:shuffle-cxns-before-application . nil)
;; For learning
(:consolidate-repairs . t))
:visualization-configurations ((:show-wiki-links-in-predicate-networks . nil)
(:show-constructional-dependencies . nil)
(:with-search-debug-data . t))
:hierarchy-features (constituents dependents))

;;; ;; S <- NP VP
;;; (def-fcg-cxn Subject-Predicate-cxn
;;; (
;;; <-
;;; (?clause
;;; (footprints (Subject-Predicate-cxn))
;;; (fields (subject-phrase ?subject-phrase)
;;; (verb-phrase ?verb-phrase))
;;; --
;;; (footprints (not Subject-Predicate-cxn))
;;; (syn-cat (clause-type ?clause-type))
;;; (constituents (?subject-phrase ?verb-phrase)))
;;; (?verb-phrase
;;; --
;;; (syn-cat (phrase-type verb-phrase)))
;;; (?subject-phrase
;;; --
;;; (syn-cat (phrase-type noun-phrase)))
;;; (root
;;; --
;;; (form ((meets ?subject-phrase ?verb-phrase ?clause)))))
;;; :disable-automatic-footprints t
;;; :cxn-set structural)

;;; ;; S <- NP WH-S
;;; (def-fcg-cxn Interrogative-Subject-Predicate-cxn
;;; (
;;; <-
;;; (?clause
;;; (footprints (interrogative-subject-predicate-cxn))
;;; (fields (subject-phrase ?subject-phrase)
;;; (verb-phrase ?verb-phrase))
;;; --
;;; (footprints (not interrogative-subject-predicate-cxn))
;;; (syn-cat (clause-type wh-interrogative))
;;; (constituents (?subject-phrase ?subordinate-clause)))
;;; (?subordinate-clause
;;; --
;;; (syn-cat (clause-type interrogative-without-wh-constituent))
;;; (constituents (?verb-phrase)))
;;; (?verb-phrase
;;; --
;;; (syn-cat (phrase-type verb-phrase)))
;;; (?subject-phrase
;;; --
;;; (syn-cat (phrase-type noun-phrase)))
;;; (root
;;; --
;;; (form ((meets ?subject-phrase ?verb-phrase ?clause)))))
;;; :disable-automatic-footprints t
;;; :cxn-set structural)

;;; ;; VP <- V NP
;;; (def-fcg-cxn VP-Object-cxn
;;; (<-
;;; (?clause
;;; (fields (object-phrase ?object-phrase))
;;; --
;;; (fields (verb-phrase ?verb-phrase)))
;;; (?verb-phrase
;;; (footprints (VP-Object-cxn))
;;; --
;;; (footprints (not VP-Object-cxn))
;;; (syn-cat (phrase-type verb-phrase))
;;; (constituents (?main-verb ?object-phrase)))
;;; (?main-verb
;;; --
;;; (syn-cat (lex-class verb)))
;;; (?object-phrase
;;; --
;;; (syn-cat (phrase-type noun-phrase))))
;;; :disable-automatic-footprints t
;;; :cxn-set structural)

;;; ;; S <- NP S'
;;; (def-fcg-cxn Topical-Object-cxn
;;; (<-
;;; (?clause
;;; --
;;; (syn-cat (clause-type wh-interrogative))
;;; (constituents (?object-phrase ?subclause)))
;;; (?subclause
;;; (fields (object-phrase ?object-phrase))
;;; --
;;; (syn-cat (clause-type interrogative-without-wh-constituent)
;;; (is-matrix-clause -))
;;; (fields (subject-phrase ?subject-phrase)
;;; (verb-phrase ?verb-phrase))
;;; (constituents (?subject-phrase ?verb-phrase)))
;;; (?object-phrase
;;; --
;;; (syn-cat (phrase-type noun-phrase)))
;;; (root
;;; --
;;; (form ((meets ?object-phrase ?subclause ?clause)))))
;;; :cxn-set structural
;;; :cxn-inventory *fcg-english*)

;;; (def-fcg-cxn clausal-noun-phrase-cxn
;;; (<-
;;; (?clausal-noun-phrase
;;; (syn-cat (clause-type simple-declarative)
;;; (is-matrix-clause -))
;;; --
;;; (syn-cat (phrase-type noun-phrase))
;;; (constituents (?noun-phrase ?verb-phrase)))
;;; (?noun-phrase
;;; --
;;; (syn-cat (phrase-type noun-phrase)))
;;; (?verb-phrase
;;; --
;;; (syn-cat (phrase-type verb-phrase)))
;;; (root
;;; --
;;; (form ((meets ?noun-phrase ?verb-phrase ?clausal-noun-phrase)))))
;;; :cxn-set structural
;;; :cxn-inventory *fcg-english*)

;;; ;; Reify-Object-Phrase
;;; (def-fcg-cxn Reify-Object-Phrase-cxn
;;; (<-
;;; (?clause
;;; (fields (object-phrase ?subordinate-clause))
;;; --
;;; (fields (verb-phrase ?verb-phrase)))
;;; (?verb-phrase
;;; (footprints (reify-object-phrase-cxn))
;;; --
;;; (footprints (not reify-object-phrase-cxn))
;;; (syn-cat (phrase-type verb-phrase))
;;; (constituents (?main-verb ?subordinate-clause)))
;;; (?main-verb
;;; --
;;; (syn-cat (lex-class verb)))
;;; (?subordinate-clause
;;; (syn-cat (phrase-type noun-phrase))
;;; --
;;; (syn-cat (clause-type ?clause-type)
;;; (is-matrix-clause -))))
;;; :disable-automatic-footprints t
;;; :cxn-set structural
;;; :cxn-inventory *fcg-english*))


#|
(ql:quickload :fcg-hybrids)
(comprehend "The boy kicked the ball" :cxn-inventory *fcg-english*)
(comprehend "Severe weather sweeping parts of the US continues to bring record breaking cold temperatures to the Pacific northwest."
:cxn-inventory *fcg-english*)
; and heavy snow to mountains in northern California and Nevada
(comprehend "Emergency warming shelters were opened throughout Oregon and western Washington as temperatures plunged into the teens (below zero in centigrade) and forecasters said an Arctic blast would last for several days."
:cxn-inventory *fcg-english*)
(comprehend "Sunday's snow showers blew into the Pacific northwest from the Gulf of Alaska, dumping up to six in (15 cm) across the Seattle area."
:cxn-inventory *fcg-english*)
(comprehend "The National Weather Service said Seattle's low on Sunday was cold, breaking a mark set in 1948."
:cxn-inventory *fcg-english*)
;; Corrective Constructions
;; ------------------------
(def-fcg-cxn V-to-V-cxn
(<-
(?verb1
--
(parent ?verb-phrase)
(syn-cat (lex-class verb)))
(?verb2
--
(syn-cat (lex-class verb)))
(root
--
(form ((string ?to "to")
(meets ?verb1 ?to ?unitx)
(meets ?to ?verb2 ?unity)))))
:attributes (:label :hashed-string :string "corrective-cxn"
:repair #'make-complex-verb)
:cxn-inventory *fcg-english*))
|#
5 changes: 3 additions & 2 deletions languages/English/categories.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; Copyright 2019 Sony Computer Science Laboratories Paris
;; Remi van Trijp (http://www.remivantrijp.eu)
;; Copyright 2021 Sony Computer Science Laboratories Paris
;; Author Remi van Trijp (http://www.remivantrijp.eu)

;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -82,6 +82,7 @@
(verb-base-form (verb))
(verb-past (verb)
(syn-cat ((verb-form ed-form))))
(verb-past-participle (verb-past))
(verb-ing-form (verb)
(syn-cat ((verb-form ing-form))))
(verb-3sg (verb))
Expand Down
11 changes: 5 additions & 6 deletions languages/English/clear-dependency-specs.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
;; Copyright 2019-present
;; Sony Computer Science Laboratories Paris
;; Remi van Trijp (http://www.remivantrijp.eu)
;; Copyright Sony Computer Science Laboratories Paris
;; Author Remi van Trijp (http://www.remivantrijp.eu)

;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,13 +45,13 @@
:keywords '(core-argument functional nominal subject)
:description "Nominal Subject")
(make-dependency-spec :label "nsubjpass"
:keywords '(core-argument functional nominal subject)
:keywords '(core-argument functional nominal passive subject)
:description "Nominal Passive Subject")
(make-dependency-spec :label "csubj"
:keywords '(core-argument functional clausal-subject subject)
:description "Clausal subject.")
(make-dependency-spec :label "csubjpass"
:keywords '(core-argument functional clausal-subject subject)
:keywords '(core-argument functional clausal-subject passive subject)
:description "Clausal passive subject.")
(make-dependency-spec :label "expl"
:keywords '(core-argument functional nominal subject)
Expand Down Expand Up @@ -87,7 +86,7 @@
:keywords '(functional adjectival complement)
:description "Adjectival complement.")
(make-dependency-spec :label "ccomp"
:keywords '(functional clausal complement)
:keywords '(core-argument functional clausal complement)
:description "Clausal complement.")
(make-dependency-spec :label "xcomp"
:keywords '(functional clausal complement)
Expand Down
6 changes: 4 additions & 2 deletions languages/English/de-render.lisp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

;; Copyright 2019-present
;; Sony Computer Science Laboratories Paris
;; Remi van Trijp (http://www.remivantrijp.eu)
Expand All @@ -22,7 +23,7 @@
(declare (ignorable mode cxn-inventory))
; Step 1: Get the dependency and constituent analysis:
(multiple-value-bind (dependency-tree constituent-tree)
(get-english-sentence-analysis utterance)
(nlp-tools::get-english-sentence-analysis utterance)
(let* (; Step 2: Use the dependency tree for segmenting the utterance into a list of strings:
(utterance-as-list (nlp-tools::dp-build-utterance-as-list-from-dependency-tree dependency-tree))
;; Step 3: Use the list of strings for building a basic transient structure:
Expand All @@ -34,4 +35,5 @@
;; Step 5: Expand the transient structure with information from the constituent tree:
(setf basic-transient-structure
(represent-constituent-structure constituent-tree basic-transient-structure key cxn-inventory))
basic-transient-structure)))
;; Step 6: Use constructional information to correct the constituent tree:
basic-transient-structure)))
Loading

0 comments on commit 7db6326

Please sign in to comment.