Skip to content

Commit

Permalink
Unit tests for spans and some consistency changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander K. Hudek committed Mar 14, 2013
1 parent a93b248 commit ff87ef8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/opennlp/span.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
(defn merge-spans
"Given two overlapping spans where the first comes before the second, return a
merged span with the type of the first."
[A B] (assoc A :end (:end B)))
[A B]
(assoc A :end (:end B)))

(defn span-disjoint?
"Return true of A does not overlap B."
Expand All @@ -42,13 +43,14 @@

(defn span-overlaps?
"Return true if A overlaps B."
[A B] (not (span-disjoint? A B)))
[A B]
(not (span-disjoint? A B)))

(defn intersection-span
"Return the intersection of two spans as a span."
"Return the intersection of two spans as a span. Type of new span is :intersection."
[A B]
{:pre [(not (span-disjoint? A B))]}
(make-span (max (:start A) (:start B)) (min (:end A) (:end B)) nil))
(->Span (max (:start A) (:start B)) (min (:end A) (:end B)) :intersection))

(defn span-length
"Return the length of the span."
Expand All @@ -63,11 +65,10 @@
(defn shift-span
"Shift a span by i positions."
[span i]
(make-span (+ (:start span) i) (+ (:end span) i) (:type span)))
(->Span (+ (:start span) i) (+ (:end span) i) (:type span)))

(defn between-span
"Return a span of the area between two spans A and B. Precondition: (:end A)
< (:start B)."
"Return a span of the area between two spans A and B. Type of new span is :between."
[a b]
{:pre [(< (:end a) (:start b))]}
(make-span (:end a) (:start b) :between))
{:pre [(<= (:end a) (:start b))]}
(->Span (:end a) (:start b) :between))

0 comments on commit ff87ef8

Please sign in to comment.