Skip to content

Commit

Permalink
Nouns as object properties
Browse files Browse the repository at this point in the history
If a tv-IRI is annotated with CN then rewrite the tokens
to use a relational noun construct.

Note that the CSV output is not affected.
  • Loading branch information
Kaljurand committed Sep 18, 2013
1 parent 791bc2a commit c6ab918
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 28 deletions.
73 changes: 59 additions & 14 deletions ace_niceace.pl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% This file is part of the OWL verbalizer.
% Copyright 2008-2011, Kaarel Kaljurand <kaljurand@gmail.com>.
% Copyright 2008-2013, Kaarel Kaljurand <kaljurand@gmail.com>.
%
% The OWL verbalizer is free software: you can redistribute it and/or modify it
% under the terms of the GNU Lesser General Public License as published by the
Expand Down Expand Up @@ -34,12 +34,17 @@
to perform these beautification transformations.
@author Kaarel Kaljurand
@version 2011-06-11
@version 2013-09-18
@bug this module calls the lexicon-module but does not explicitly import it.
*/

:- use_module(lexicon, [
iri_fragment/2,
get_lexicon_entry/3
]).

%% ace_niceace(+TokenListIn:list, -TokenListOut:list) is det.
%
% @param TokenListIn is a list of ACE tokens
Expand All @@ -51,7 +56,7 @@
ace_niceace(In, Out) :-
ace_merge(In, Prefix, Rest),
ace_niceace(Rest, RestOut),
simple_append(Prefix, RestOut, Out).
append(Prefix, RestOut, Out).


%% ace_merge(+TokenList:list, -Prefix:list, -NewTokenList:list) is nondet.
Expand All @@ -71,7 +76,13 @@

ace_merge([a, cn_sg(Iri) | Rest], [Article], [SurfaceForm | Rest]) :-
!,
lexicon:call(cn_sg(Iri), SurfaceForm),
(
lexicon:call(cn_sg(Iri), SurfaceForm)
->
true
;
lexicon:iri_fragment(Iri, SurfaceForm)
),
word_article(SurfaceForm, Article).

ace_merge([qs(Token) | Rest], [], [TokenQuotes | Rest]) :-
Expand All @@ -87,26 +98,60 @@
!,
my_concat_atom([Token, ','], TokenComma).

ace_merge([does, not, tv_pl(Iri) | Rest], [is, not, Article, SurfaceForm, of], Rest) :-
verb_as_noun(Iri, Article, SurfaceForm),
!.

ace_merge([do, not, tv_pl(Iri) | Rest], [are, not, Article, SurfaceForm, of], Rest) :-
verb_as_noun(Iri, Article, SurfaceForm),
!.

ace_merge([tv_sg(Iri) | Rest], [is, Article, SurfaceForm, of], Rest) :-
verb_as_noun(Iri, Article, SurfaceForm),
!.

ace_merge([tv_pl(Iri) | Rest], [are, Article, SurfaceForm, of], Rest) :-
verb_as_noun(Iri, Article, SurfaceForm),
!.

ace_merge([that, _, not, tv_vbg(Iri), by | Rest], [whose, SurfaceForm, is, not], Rest) :-
verb_as_noun(Iri, _Article, SurfaceForm),
!.

ace_merge([_, not, tv_vbg(Iri), by | Rest], ['\'s', SurfaceForm, is, not], Rest) :-
verb_as_noun(Iri, _Article, SurfaceForm),
!.

ace_merge([that, _, tv_vbg(Iri), by | Rest], [whose, SurfaceForm, is], Rest) :-
verb_as_noun(Iri, _Article, SurfaceForm),
!.

ace_merge([_, tv_vbg(Iri), by | Rest], ['\'s', SurfaceForm, is], Rest) :-
verb_as_noun(Iri, _Article, SurfaceForm),
!.

ace_merge([Token | Rest], [Token], Rest) :-
atomic(Token),
!.

ace_merge([Token | Rest], [SurfaceForm], Rest) :-
functor(Token, _, 1),
lexicon:call(Token, SurfaceForm).
lexicon:call(Token, SurfaceForm),
!.

ace_merge([Token | Rest], [SurfaceForm], Rest) :-
functor(Token, _, 1),
arg(1, Token, Iri),
lexicon:iri_fragment(Iri, SurfaceForm).

%% simple_append(?List1:list, ?List2:list, ?List3:list) is nondet.
%
% @param List1 is an empty list or a list of one element
% @param List2 is a list
% @param List3 is a list

%%
%
% This is a special case of append/2
%
simple_append([], List, List).
simple_append([X], List, [X | List]).

verb_as_noun(Iri, Article, SurfaceForm) :-
get_lexicon_entry('CN_sg', Iri, SurfaceForm),
!,
word_article(SurfaceForm, Article).

%% word_article(+Word:atom, -Article:atom) is det.
%
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
destfile="${dist}/owl_verbalizer-${build.time}.zip"
basedir="."
includes="**"
excludes="ontologies/**, dist/**, .hg/**, tools/**, hidden/**, run_tests.py, build.xml, test.sh, lexicon_with_assert.pl, *.exe"
excludes="ontologies/**, dist/**, .git/**, tools/**, hidden/**, run_tests.py, build.xml, test.sh, lexicon_with_assert.pl, *.exe"
/>
</target>

Expand Down
22 changes: 22 additions & 0 deletions examples/nouns.ace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Rex is not an eater of Mick.

No goat is an eater of something that is not a leaf.

Everything whose eater is a goat is a leaf.
Everything that is an eater of nothing but leaves is a goat.

Everything is an eater of at most 1 thing.

Everything 's eater is at most 1 thing.

If X is an eater of something that is an eater of Y then X is an eater of Y.

Everything that is an eater of something is an animal.

Everything whose eater is something is a food that is not an automobile.

If X is a hater of Y then Y is an eater of X.
If X is an eater of Y then Y is a hater of X.

If X is a hater of Y then it is false that X is an eater of Y.

149 changes: 149 additions & 0 deletions examples/nouns.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
ignored Prefix(story,http://www.example.org/story.owl#)

ignored Prefix(ace_lexicon,http://attempto.ifi.uzh.ch/ace_lexicon#)

ignored AnnotationAssertion(AnnotationProperty(http://attempto.ifi.uzh.ch/ace_lexicon#CN_sg),IRI(http://www.example.org/story.owl#eat),^^(eater,))

ignored AnnotationAssertion(AnnotationProperty(http://attempto.ifi.uzh.ch/ace_lexicon#CN_sg),IRI(http://www.example.org/story.owl#hate),^^(hater,))

ignored AnnotationAssertion(AnnotationProperty(http://attempto.ifi.uzh.ch/ace_lexicon#CN_pl),IRI(http://www.example.org/story.owl#leaf),^^(leaves,))

pn_sg http://owl.man.ac.uk/2005/07/sssw/people#Rex
f does
f not
tv_pl http://www.example.org/story.owl#eat
pn_sg http://owl.man.ac.uk/2005/07/sssw/people#Mick
f .

f No
cn_sg http://www.example.org/story.owl#goat
tv_sg http://www.example.org/story.owl#eat
f a
f thing
f that
f is
f not
f a
cn_sg http://www.example.org/story.owl#leaf
f .

f Every
f thing
f that
f is
tv_vbg http://www.example.org/story.owl#eat
f by
f a
cn_sg http://www.example.org/story.owl#goat
f is
f a
cn_sg http://www.example.org/story.owl#leaf
f .
f Every
f thing
f that
tv_sg http://www.example.org/story.owl#eat
f nothing
f but
cn_pl http://www.example.org/story.owl#leaf
f is
f a
cn_sg http://www.example.org/story.owl#goat
f .

f Every
f thing
tv_sg http://www.example.org/story.owl#eat
f at
f most
f 1
f thing
f .

f Every
f thing
f is
tv_vbg http://www.example.org/story.owl#eat
f by
f at
f most
f 1
f thing
f .

f If
f X
tv_sg http://www.example.org/story.owl#eat
f a
f thing
f that
tv_sg http://www.example.org/story.owl#eat
f Y
f then
f X
tv_sg http://www.example.org/story.owl#eat
f Y
f .

f Every
f thing
f that
tv_sg http://www.example.org/story.owl#eat
f a
f thing
f is
f a
cn_sg http://www.example.org/story.owl#animal
f .

f Every
f thing
f that
f is
tv_vbg http://www.example.org/story.owl#eat
f by
f a
f thing
f is
f a
cn_sg http://www.example.org/story.owl#food
f that
f is
f not
f a
cn_sg http://www.example.org/story.owl#automobile
f .

f If
f X
tv_sg http://www.example.org/story.owl#hate
f Y
f then
f Y
tv_sg http://www.example.org/story.owl#eat
f X
f .
f If
f X
tv_sg http://www.example.org/story.owl#eat
f Y
f then
f Y
tv_sg http://www.example.org/story.owl#hate
f X
f .

f If
f X
tv_sg http://www.example.org/story.owl#hate
f Y
f then
f it
f is
f false
f that
f X
tv_sg http://www.example.org/story.owl#eat
f Y
f .

78 changes: 78 additions & 0 deletions examples/nouns.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://org.semanticweb.ontologies/Ontology1256143016364769000"
xmlns:xml="http://www.w3.org/XML/1998/namespace">

<Prefix name="story" IRI="http://www.example.org/story.owl#"/>
<Prefix name="ace_lexicon" IRI="http://attempto.ifi.uzh.ch/ace_lexicon#"/>

<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="ace_lexicon:CN_sg"/>
<IRI>http://www.example.org/story.owl#eat</IRI>
<Literal>eater</Literal>
</AnnotationAssertion>

<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="ace_lexicon:CN_sg"/>
<IRI>http://www.example.org/story.owl#hate</IRI>
<Literal>hater</Literal>
</AnnotationAssertion>

<AnnotationAssertion>
<AnnotationProperty abbreviatedIRI="ace_lexicon:CN_pl"/>
<IRI>http://www.example.org/story.owl#leaf</IRI>
<Literal>leaves</Literal>
</AnnotationAssertion>

<NegativeObjectPropertyAssertion>
<ObjectProperty abbreviatedIRI="story:eat"/>
<NamedIndividual IRI="http://owl.man.ac.uk/2005/07/sssw/people#Rex"/>
<NamedIndividual IRI="http://owl.man.ac.uk/2005/07/sssw/people#Mick"/>
</NegativeObjectPropertyAssertion>
<DisjointClasses>
<Class abbreviatedIRI="story:goat"/>
<ObjectSomeValuesFrom>
<ObjectProperty abbreviatedIRI="story:eat"/>
<ObjectComplementOf>
<Class abbreviatedIRI="story:leaf"/>
</ObjectComplementOf>
</ObjectSomeValuesFrom>
</DisjointClasses>
<EquivalentClasses>
<Class abbreviatedIRI="story:goat"/>
<ObjectAllValuesFrom>
<ObjectProperty abbreviatedIRI="story:eat"/>
<Class abbreviatedIRI="story:leaf"/>
</ObjectAllValuesFrom>
</EquivalentClasses>
<FunctionalObjectProperty>
<ObjectProperty abbreviatedIRI="story:eat"/>
</FunctionalObjectProperty>
<InverseFunctionalObjectProperty>
<ObjectProperty abbreviatedIRI="story:eat"/>
</InverseFunctionalObjectProperty>
<TransitiveObjectProperty>
<ObjectProperty abbreviatedIRI="story:eat"/>
</TransitiveObjectProperty>
<ObjectPropertyDomain>
<ObjectProperty abbreviatedIRI="story:eat"/>
<Class abbreviatedIRI="story:animal"/>
</ObjectPropertyDomain>
<ObjectPropertyRange>
<ObjectProperty abbreviatedIRI="story:eat"/>
<ObjectIntersectionOf>
<Class abbreviatedIRI="story:food"/>
<ObjectComplementOf>
<Class abbreviatedIRI="story:automobile"/>
</ObjectComplementOf>
</ObjectIntersectionOf>
</ObjectPropertyRange>
<InverseObjectProperties>
<ObjectProperty abbreviatedIRI="story:hate"/>
<ObjectProperty abbreviatedIRI="story:eat"/>
</InverseObjectProperties>
<DisjointObjectProperties>
<ObjectProperty abbreviatedIRI="story:hate"/>
<ObjectProperty abbreviatedIRI="story:eat"/>
</DisjointObjectProperties>
</Ontology>
Loading

0 comments on commit c6ab918

Please sign in to comment.