<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Codeco: A Grammar Notation for Controlled Natural Language in Predictive Editors</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Tobias Kuhn</string-name>
          <email>kuhntobias@gmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Informatics &amp; Institute of Computational Linguistics, University of Zurich</institution>
          ,
          <country country="CH">Switzerland</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Existing grammar frameworks do not work out particularly well for controlled natural languages (CNL), especially if they are to be used in predictive editors. I introduce in this paper a new grammar notation, called Codeco, which is designed speci cally for CNLs and predictive editors. Two di erent parsers have been implemented and a large subset of Attempto Controlled English (ACE) has been represented in Codeco. The results show that Codeco is practical, adequate and e cient.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Controlled natural languages (CNL) like Attempto Controlled English (ACE) [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]
and others have been proposed to make knowledge representation systems more
user-friendly [
        <xref ref-type="bibr" rid="ref10 ref5">10, 5</xref>
        ]. It can be very di cult, however, for users to write
statements that comply with the restrictions of CNLs. Three approaches have been
proposed so far to solve this problem: error messages [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], language generation
[
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], and predictive editors [
        <xref ref-type="bibr" rid="ref11 ref5">11, 5</xref>
        ]. Each of the approaches has its own advantages
and drawbacks. In my view, the predictive editor approach | where the editor
shows all possible continuations of a partial sentence | is the most elegant one.
However, implementing lookahead features (i.e. retrieving the possible
continuations for a given partial sentence on the basis of a given grammar) is not a
trivial task, especially if the grammar describes complex nonlocal structures like
anaphoric references. Furthermore, good tool integration is crucial for CNLs,
no matter which approach is followed. For this reason, it is desirable to have a
simple grammar notation that is fully declarative and can easily be implemented
in di erent kinds of programming languages.
      </p>
      <p>
        These requirements are not satis ed by existing grammar frameworks.
Natural language grammar frameworks like Head-driven Phrase Structure Grammars
(HPSG) [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] are unnecessarily complex for CNLs and do not allow for the
implementation of e cient and reliable lookahead features. Grammar frameworks for
formal languages | called parser generators | like Yacc [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] do not allow for
the declarative de nition of complex (i.e. context-sensitive) structures. De nite
clause grammars (DCG) [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] are a good candidate but they have the problem
that they are hard to implement in programming languages that are not
logicbased. Furthermore, all these grammar frameworks have no special support for
the deterministic resolution of anaphoric references, as required by languages like
ACE. The Grammatical Framework (GF) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] is a recent grammar framework in
competition with the approach to be presented here. It allows for declarative
de nition of grammar rules and can be used in predictive editors, but it lacks
support for anaphoric references.
      </p>
      <p>The following example illustrates the di culty of lookahead in the case of
complex nonlocal structures like anaphoric references. The partial ACE sentence
\every man protects a house from every enemy and does not destroy ..." can be
continued by several anaphoric structures referring to earlier objects in the
sentence: \the man" or \himself" can be used to refer to \man"; \the house" or \it"
can be used to refer to \house". It is not possible, however, to refer to \enemy",
because it is under the scope of the quanti er \every" and such references from
outside the scope of a quanti ed entity do not make sense logically.1 Thus, a
predictive editor should in this case propose \the man" and \the house" as possible
continuations of the given partial sentence, but not \the enemy".
2</p>
    </sec>
    <sec id="sec-2">
      <title>Codeco</title>
      <p>In order to solve the problems sketched above, I created a new grammar notation
called Codeco, which stands for \concrete and declarative grammar notation for
controlled natural languages". This grammar notation is designed speci cally
for CNLs to be used in predictive editors. Below is a brief description of the
most important features of Codeco.</p>
      <p>In a nutshell, grammar rules in Codeco consist of grammatical categories with
at feature structures2. One of the important features of Codeco is that
anaphoric references and their potential antecedents can be represented by special
categories for backward references \&lt;" and forward references \&gt;", respectively.
These special categories establish nonlocal dependencies across the syntax tree in
the sense that each backward reference needs a matching (i.e. uni able) forward
reference somewhere in the preceding text.</p>
      <p>
        Furthermore, scopes can be de ned that make the contained forward
references inaccessible from the outside. In Codeco, scopes are opened by the special
category \ " and are closed by the use of scope-closing rules \ !". In contrast
to normal rules \ !:", scope-closing rules close at their end all scopes that have
1 The di erence between \every man" and \every enemy" in the given example is not
obvious. The scope that is opened by the quanti er \every" of \every enemy" closes
after \enemy", because the verb phrase ends there. In ACE, verb phrases | but not
only verb phrases | close at their end all scopes that are opened within (which is,
in general, also true for full natural English). Since \every man" is not part of that
verb phrase, the scope for \every man" is still open at the end of the partial sentence.
This is why \man" is accessible for anaphoric references, but \enemy" is not. See
also Fig. 1.
2 The restriction to at feature structures (instead of general ones) restricts the
expressive power of Codeco while making it easier to process and implement. The
results suggest that Codeco is su ciently expressive for common CNLs.
been opened by one of their child categories. In this way, Codeco allows us to
de ne the positions where scopes open and close in a simple and fully
declarative way. Other extensions that are not discussed here are needed to handle
pronouns, variables, and references to proper names in the desired way. See [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]
for the details.
      </p>
      <p>The following grammar rules are examples that show how the special
structures of Codeco are used:
np
:
!
det exist: +</p>
      <p>noun text: Noun
:
!
ref
[ the ] noun text: Noun</p>
      <p>&gt; tnyopuen::nNoouunn
&lt; tnyopuen::nNoouunn
det exist: {
:
!</p>
      <p>[ every ]
vp num: Num
!
v tnyupme:: tNrum
np case: acc
pp
The rst rule represents existentially quanti ed noun phrases like \a house" and
establishes a forward reference to de ne its status as a potential antecedent
for subsequent anaphoric references. The second rule describes a de nite noun
phrase like \the house" and declares its anaphoric property by a backward
reference. The third rule describes the determiner \every" opening a scope through
the use of the scope opener category. The last rule describes a verb phrase and
is scope-closing, which means that the end of such a verb phrase also marks the
end of all scopes that have been opened within.</p>
      <p>Codeco grammars allow for the correct and e cient implementation of
lookahead features. Figure 1 shows a possible syntax tree of the example above and
visualizes how the possible anaphoric references can be found.</p>
      <p>
        Two independent parsers have been implemented for Codeco: one that
executes Codeco grammars as Prolog DCGs and another one that is a chart parser
implemented in Java. These two implementations have been shown to be
equivalent and e cient [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. The chart parser for Codeco is used in the predictive editors
of AceWiki [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] and the ACE Editor3. The DCG parser is used for regression and
ambiguity tests for the grammars of both tools.
      </p>
      <p>The Codeco grammar that is used in the ACE Editor consists of 164 grammar
rules and describes a large subset of ACE covering nouns, proper names,
intransitive and transitive verbs, adjectives, adverbs, prepositions, variables, plurals,
negation, prepositional phrases, relative clauses, modality, numerical quanti ers,
various kinds of coordination, conditional sentences, questions, anaphoric
pronouns, and more. Currently unsupported ACE features are mass nouns,
measurement nouns, ditransitive verbs, numbers and strings as noun phrases,
sentences as verb phrase complements, saxon genitive, possessive pronouns, noun
phrase coordination, and commands. Nevertheless, this subset of ACE is | to
3 http://attempto.ifi.uzh.ch/webapps/aceeditor/
det
noun &gt;
v
tv
vp
np
det noun &gt; prep
vp</p>
      <p>conj
pp
det
np
noun &gt;
aux
v
vp
tv
np
ref
&lt;
( Every man
protects a house</p>
      <p>from ( every enemy ) and ( does not destroy ...
my knowledge | the broadest subset of English that has ever been de ned in a
formal and fully declarative way and that includes complex issues like anaphoric
references.</p>
      <p>Codeco grammars can be checked for syntactic ambiguity by exhaustive
language generation up to a certain sentence length. Due to combinatorial explosion,
it is advisable not to check the complete language but to de ne a core subset
thereof. Such a core subset should use a minimal lexicon and should have a
reduced number of grammar rules, in a way that language structures that could
possibly lead to complex cases of ambiguity are retained. For the ACE Codeco
grammar introduced above, such a core subset has been de ned, consisting of 97
of the altogether 164 grammar rules. Exhaustive language generation of this core
subset up to ten tokens leads to 2'250'869 sentences, which are all di erent. Since
syntactically ambiguous sentences would be generated more than once (because
they have more than one syntax tree), this proves that at least the core of the
ACE Codeco grammar is unambiguous, at least for sentences up to ten tokens.
In the same way, it can be proven that the core of the ACE Codeco grammar is
indeed a subset of ACE.</p>
      <p>
        See my thesis [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] for the complete description of Codeco, the full ACE Codeco
grammar, complexity considerations, the details and results of the performed
tests and the involved algorithms.
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Conclusions</title>
      <p>In summary, the Codeco notation allows us to de ne controlled subsets of natural
languages in an adequate way. The resulting grammars are fully declarative, can
be e ciently interpreted in di erent kinds of programming languages, and allow
for lookahead features, which is needed for predictive editors. Furthermore, it
allows for di erent kinds of automatic tests, which is very important for the
development of reliable practical applications.</p>
      <p>Codeco is a proposal for a general CNL grammar notation. It cannot be
excluded that extensions become necessary to express the syntax of other CNLs,
but Codeco has been shown to work very well for a large subset of ACE, which
is one of the most advanced CNLs to date.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>Krasimir</given-names>
            <surname>Angelov</surname>
          </string-name>
          and
          <string-name>
            <given-names>Aarne</given-names>
            <surname>Ranta</surname>
          </string-name>
          .
          <article-title>Implementing controlled languages in GF</article-title>
          .
          <source>In Proceedings of the Workshop on Controlled Natural Language (CNL</source>
          <year>2009</year>
          ), volume
          <volume>5972</volume>
          of Lecture Notes in Computer Science, pages
          <volume>82</volume>
          {
          <fpage>101</fpage>
          . Springer,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>Peter</given-names>
            <surname>Clark</surname>
          </string-name>
          ,
          <string-name>
            <surname>Shaw-Yi</surname>
            <given-names>Chaw</given-names>
          </string-name>
          , Ken Barker, Vinay Chaudhri, Phil Harrison, James Fan,
          <string-name>
            <surname>Bonnie John</surname>
          </string-name>
          , Bruce Porter,
          <string-name>
            <given-names>Aaron</given-names>
            <surname>Spaulding</surname>
          </string-name>
          , John Thompson, and
          <string-name>
            <given-names>Peter</given-names>
            <surname>Yeh</surname>
          </string-name>
          .
          <article-title>Capturing and answering questions posed to a knowledge-based system</article-title>
          .
          <source>In K-CAP '07: Proceedings of the 4th International Conference on Knowledge Capture</source>
          , pages
          <volume>63</volume>
          {
          <fpage>70</fpage>
          . ACM,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Juri Luca De Coi</surname>
            , Norbert E. Fuchs, Kaarel Kaljurand, and
            <given-names>Tobias</given-names>
          </string-name>
          <string-name>
            <surname>Kuhn</surname>
          </string-name>
          .
          <article-title>Controlled English for reasoning on the Semantic Web. In Semantic Techniques for the Web | The REWERSE Perspective</article-title>
          , volume
          <volume>5500</volume>
          of Lecture Notes in Computer Science, pages
          <volume>276</volume>
          {
          <fpage>308</fpage>
          . Springer,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Stephen</surname>
            <given-names>C.</given-names>
          </string-name>
          <string-name>
            <surname>Johnson</surname>
          </string-name>
          . Yacc:
          <article-title>Yet another compiler-compiler</article-title>
          .
          <source>Computer Science Technical Report 32</source>
          ,
          <string-name>
            <surname>Bell</surname>
            <given-names>Laboratories</given-names>
          </string-name>
          , Murray Hill, NJ, USA,
          <year>July 1975</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>Tobias</given-names>
            <surname>Kuhn</surname>
          </string-name>
          .
          <article-title>How controlled English can improve semantic wikis</article-title>
          .
          <source>In Proceedings of the Forth Semantic Wiki Workshop (SemWiki</source>
          <year>2009</year>
          ), volume
          <volume>464</volume>
          <source>of CEUR Workshop Proceedings. CEUR-WS</source>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>Tobias</given-names>
            <surname>Kuhn</surname>
          </string-name>
          .
          <article-title>Controlled English for Knowledge Representation</article-title>
          .
          <source>Doctoral thesis</source>
          , Faculty of Economics, Business Administration and Information Technology of the University of Zurich, Switzerland, to appear.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>Fernando</given-names>
            <surname>Pereira</surname>
          </string-name>
          and
          <string-name>
            <surname>David H. D. Warren</surname>
          </string-name>
          .
          <article-title>De nite clause grammars for language analysis</article-title>
          .
          <source>In Readings in Natural Language Processing</source>
          , pages
          <volume>101</volume>
          {
          <fpage>124</fpage>
          . Morgan Kaufmann Publishers,
          <year>1986</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>Carl</given-names>
            <surname>Pollard</surname>
          </string-name>
          and
          <string-name>
            <given-names>Ivan</given-names>
            <surname>Sag</surname>
          </string-name>
          .
          <article-title>Head-Driven Phrase Structure Grammar</article-title>
          .
          <article-title>Studies in Contemporary Linguistics</article-title>
          . Chicago University Press,
          <year>1994</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9. Richard Power, Robert Stevens,
          <string-name>
            <given-names>Donia</given-names>
            <surname>Scott</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Alan</given-names>
            <surname>Rector</surname>
          </string-name>
          .
          <article-title>Editing OWL through generated CNL</article-title>
          .
          <source>In Pre-Proceedings of the Workshop on Controlled Natural Language (CNL</source>
          <year>2009</year>
          ), volume
          <volume>448</volume>
          <source>of CEUR Workshop Proceedings. CEUR-WS</source>
          ,
          <year>April 2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Rolf</surname>
            <given-names>Schwitter</given-names>
          </string-name>
          , Kaarel Kaljurand, Anne Cregan, Catherine Dolbear, and
          <string-name>
            <given-names>Glen</given-names>
            <surname>Hart</surname>
          </string-name>
          .
          <article-title>A comparison of three controlled natural languages for OWL 1.1</article-title>
          .
          <source>In Proceedings of the Fourth OWLED Workshop on OWL: Experiences and Directions</source>
          , volume
          <volume>496</volume>
          <source>of CEUR Workshop Proceedings. CEUR-WS</source>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Rolf</surname>
            <given-names>Schwitter</given-names>
          </string-name>
          , Anna Ljungberg, and David Hood.
          <article-title>ECOLE | a look-ahead editor for a controlled language</article-title>
          .
          <source>In Controlled Translation | Proceedings of the Joint Conference combining the 8th International Workshop of the European Association for Machine Translation and the 4th Controlled Language Application Workshop (EAMT-CLAW03)</source>
          , pages
          <fpage>141</fpage>
          {
          <fpage>150</fpage>
          ,
          <string-name>
            <surname>Ireland</surname>
          </string-name>
          ,
          <year>2003</year>
          . Dublin City University.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>