Created
January 17, 2013 17:37
-
-
Save instanceofme/4557820 to your computer and use it in GitHub Desktop.
REL sample for legal citation Sample for http://stackoverflow.com/questions/7054764/regular-expression-for-legal-citation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in './' | |
organization := "com.stackoverflow" | |
name := "legal" | |
version := "0.1" | |
scalaVersion := "2.9.1" | |
resolvers += "Imaginatio" at "https://github.com/Imaginatio/Maven-repository/raw/master" | |
libraryDependencies += "fr.splayce" %% "rel" % "0.2.3" | |
libraryDependencies += "org.specs2" %% "specs2" % "1.10" % "test" | |
scalacOptions ++= Seq("-deprecation", "-unchecked", "-encoding", "UTF8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in './src/main/scala' | |
package com.stackoverflow.legal | |
import fr.splayce.rel._ | |
import Symbols._ | |
import Implicits._ | |
object Legal { | |
val NAME = α+ | |
val VS = """v\.?""" ~ """s\.?""".? | |
val CASE = NAME("name1") ~ " " ~ VS ~ " " ~ NAME("name2") | |
val NUM = ß ~ (δ+) ~ ß | |
val US = """U\.? ?S\.? """ | |
val YEAR = ( ("1[7-9]" | "20") ~ δ{2} )("year") | |
val REF = CASE ~ ", " ~ // "Doe v. Smith, " | |
(NUM ~ " ").? ~ // "123 " (optional) | |
US ~ NUM ~ // "U.S. 456" | |
(", " ~ NUM).* ~ // ", 678" 0 to N times | |
" \\(" ~ YEAR ~ "\\)" // "(1999)" | |
} | |
object Output extends App { | |
println(Legal.REF) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in './src/test/scala/' | |
package com.stackoverflow.legal | |
import fr.splayce.rel.Implicits.RE2Regex | |
import org.specs2.mutable._ | |
class LegalSpec extends Specification { | |
import Legal._ | |
"NAME" should { | |
"Match plain names" in { | |
"Doe" must be matching(NAME) | |
"Smith" must be matching(NAME) | |
} | |
"Not match composed names" in { | |
"Doe-Smith" must not be matching(NAME) | |
} | |
"Not match diacritics" in { | |
"Doë" must not be matching(NAME) | |
} | |
} | |
"CASE" should { | |
"Match 'vs' form" in { "Doe vs Smith" must be matching(CASE) } | |
"Match 'v.s' form" in { "Doe v.s Smith" must be matching(CASE) } | |
"Match 'v.s.' form" in { "Doe v.s. Smith" must be matching(CASE) } | |
"Match 'v' form" in { "Doe v Smith" must be matching(CASE) } | |
"Match 'v.' form" in { "Doe v. Smith" must be matching(CASE) } | |
} | |
"NUM" should { | |
"Match 1+ digits" in { | |
"1" must be matching(NUM) | |
"12" must be matching(NUM) | |
"123" must be matching(NUM) | |
"1234" must be matching(NUM) | |
"12345" must be matching(NUM) | |
"123456" must be matching(NUM) | |
} | |
"Match only standalone digits" in { | |
NUM.findFirstIn(" 123 ") must beSome("123") | |
NUM.findFirstIn(" n123 ") must beNone | |
} | |
} | |
"US" should { | |
"Match 'US ' form" in { "US " must be matching(US) } | |
"Match 'U.S. ' form" in { "U.S. " must be matching(US) } | |
"Match 'U. S. ' form" in { "U. S. " must be matching(US) } | |
} | |
"YEAR" should { | |
"Not match 1600s" in { | |
"1699" must not be matching(YEAR) | |
} | |
"Match 1700s to 1900s" in { | |
"1700" must be matching(YEAR) | |
"1799" must be matching(YEAR) | |
"1800" must be matching(YEAR) | |
"1899" must be matching(YEAR) | |
"1900" must be matching(YEAR) | |
"1999" must be matching(YEAR) | |
} | |
"Match 2000s" in { | |
"2000" must be matching(YEAR) | |
"2099" must be matching(YEAR) | |
} | |
"Not match 2100s" in { | |
"2100" must not be matching(YEAR) | |
} | |
} | |
"REF" should { | |
"Match the full form" in { | |
"Doe v. Smith, U.S. 456 (2003)" must be matching(REF) | |
"Doe v. Smith, 123 U.S. 456 (2003)" must be matching(REF) | |
"Doe v. Smith, 123 U.S. 456, 789 (2003)" must be matching(REF) | |
"Doe v.s. Smith, 123 US 456 (2003)" must be matching(REF) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment