<commit_before>package net.lemonmodel.patterns

import java.net.URI
import scala.xml._
import net.lemonmodel.rdfutil.RDFUtil._
        
/**
 * A noun
 */
trait Noun extends Pattern {
  def makeWithForm(form : Form) : Noun
  protected def senseXML(namer : URINamer) : NodeSeq
  protected def isProper = false
  def withPlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"))))
  def withAccusative(form : String) = makeWithForm(Form(form,Map(lexinfo("case")->lexinfo("accusativeCase"))))
  def withDative(form : String) = makeWithForm(Form(form,Map(lexinfo("case")->lexinfo("dativeCase"))))
  def withGenitive(form : String) = makeWithForm(Form(form,Map(lexinfo("case")->lexinfo("genitiveCase"))))
  def withNominativeSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("nominativeCase"))))
  def withAccusativeSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("accusativeCase"))))
  def withGenitiveSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("genitiveCase"))))
  def withDativeSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("dativeCase"))))
  def withNominativePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("nominativeCase"))))
  def withAccusativePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("accusativeCase"))))
  def withGenitivePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("genitiveCase"))))
  def withDativePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("dativeCase"))))
  def withGender(gender : Gender) : Noun
  def masculine = withGender(Masculine)
  def feminine = withGender(Feminine)
  def neuter = withGender(Neuter)
  def commonGender = withGender(CommonGender)
  def otherGender = withGender(OtherGender)
  def gender : Option[Gender]
  def lemma : NounPhrase
  def forms : Seq[Form]
  def toXML(namer : URINamer, lang : String) = <lemon:LexicalEntry rdf:about={namer("noun",lemma.toString())}>
      <lemon:canonicalForm>
        <lemon:LexicalForm rdf:about={namer("noun",lemma.toString(),Some("canonicalForm"))}>
          <lemon:writtenRep xml:lang={lang}>{lemma.toString()}</lemon:writtenRep>
        </lemon:LexicalForm>
      </lemon:canonicalForm>
      {gender match {
        case Some(g) => <lexinfo:gender rdf:resource={lexinfo(g.toString()).toString()}/>
        case None => 
        }
      }
      { lemma.toXML(namer,lang) }
      {
        for(form <- forms) yield {
          <lemon:otherForm>
            <lemon:LexicalForm rdf:about={namer("noun",lemma.toString(),Some("form"))}>
              <lemon:writtenRep xml:lang={lang}>{form.writtenRep}</lemon:writtenRep>
              {
                for((prop,propVal) <- form.props) yield {
                  val (prefixUri,prefix,suffix) = prefixURI(prop)
                  <lingonto:prop rdf:resource={propVal}/>.copy(prefix=prefix, label=suffix) %
                    Attribute("","xmlns:"+prefix,prefixUri,Null)
                }
              }
            </lemon:LexicalForm>
          </lemon:otherForm>
        }   
      }
      {senseXML(namer)}
    </lemon:LexicalEntry>
}   

sealed trait Gender

object Masculine extends Gender { override def toString = "masculine" }
object Feminine extends Gender { override def toString = "feminine" }
object Neuter extends Gender { override def toString = "neuter" }
object CommonGender extends Gender { override def toString = "commonGender" }
object OtherGender extends Gender { override def toString = "otherGender" }

/**
* A name (proper noun) associated to a named individual in the ontology
* @param lemma The canonical form of the name (required)
* @param sense The URI of the associated named individual
* @param forms The set of other forms
*/
case class Name(val lemma : PNP, 
                val sense : URI = null, 
                val forms : Seq[Form] = Nil,
                val gender : Option[Gender] = None) extends Noun {
  def makeWithForm(form : Form) = Name(lemma,sense, forms :+ form,gender)
  def withGender(gender : Gender) = Name(lemma,sense,forms,Some(gender))
  protected def senseXML(namer : URINamer) = <lemon:sense>
       <lemon:LexicalSense rdf:about={namer("noun",lemma.toString(),Some("sense"))}>
         <lemon:reference>
           <owl:NamedIndividual rdf:about={sense}/>
         </lemon:reference>
       </lemon:LexicalSense>
    </lemon:sense>
   protected override def isProper = true
}

/**
* A noun representing a genus of object associated with an ontology class
* @param form The canonical form of the noun (required)
* @param sense The URI to be associated with
* @param forms The set of other forms
*/
case class ClassNoun(val lemma : NP, 
                     val sense : URI = null, 
                     val forms : Seq[Form] = Nil,
                     val gender : Option[Gender] = None) extends Noun {
  def makeWithForm(form : Form) = ClassNoun(lemma,sense,forms :+ form,gender)
  def withGender(gender : Gender) = ClassNoun(lemma,sense,forms,Some(gender))
  def senseXML(namer : URINamer) = {
  val subjURI = namer("noun",lemma.toString(),Some("subject"))
    <lemon:sense>
      <lemon:LexicalSense rdf:about={namer("noun",lemma.toString(),Some("sense"))}>
         <lemon:reference>
           <owl:Class rdf:about={sense}/>
         </lemon:reference>
         <lemon:isA>
            <lemon:Argument rdf:about={subjURI}/>
         </lemon:isA>
       </lemon:LexicalSense>
    </lemon:sense> :+
    <lemon:synBehavior>
      <lemon:Frame rdf:about={namer("noun",lemma.toString(),Some("frame"))}>
        <rdf:type rdf:resource={lexinfo("NounPredicativeFrame")}/>
        <lexinfo:subject rdf:resource={subjURI}/>
      </lemon:Frame>
    </lemon:synBehavior>
  }
}

/**
 * A noun representing a bivalent relationship associated with an object property
 * in the ontology
 * @param form The canonical form of the noun (required)
 * @param sense The URI to be associated with
 * @param propSubj Indicates the argument that fills the subject (domain) of the object property
 * @param propObj Indicates the argument that fills the object (range) of the object property (required)
 * @param forms The set of other forms
 */
case class RelationalNoun(val lemma : NP, 
                          val sense : URI = null, 
                          val propSubj : Arg = CopulativeArg, 
                          val propObj : Arg, 
                          val forms : Seq[Form] = Nil,
                          val gender : Option[Gender] = None) extends Noun {
   def makeWithForm(inflForm : Form) = RelationalNoun(lemma,sense,propSubj,propObj,forms :+ inflForm,gender)
   def withGender(gender : Gender) = RelationalNoun(lemma,sense,propSubj,propObj,forms,Some(gender))
   protected def senseXML(namer : URINamer) = {
     val subjURI = namer("noun",lemma.toString(),Some("subject"))
     val objURI = namer("noun",lemma.toString(),Some("adpositionalObject"))
     <lemon:sense>
      <lemon:LexicalSense rdf:about={namer("noun",lemma.toString(),Some("sense"))}>
         <lemon:reference>
           <rdf:Property rdf:about={sense}/>
         </lemon:reference>
         <lemon:subjOfProp>
            <lemon:Argument rdf:about={subjURI}/>
         </lemon:subjOfProp>
         <lemon:objOfProp>
            <lemon:Argument rdf:about={objURI}/>
         </lemon:objOfProp>
        { 
          if(propSubj.restriction != None) {
            <lemon:propertyDomain rdf:resource={propSubj.restriction.get}/>
          }
        }
        { 
          if(propObj.restriction != None) {
            <lemon:propertyRange rdf:resource={propObj.restriction.get}/>
          }
        }
       </lemon:LexicalSense>
    </lemon:sense> :+
    <lemon:synBehavior>
      <lemon:Frame rdf:about={namer("noun",lemma.toString(),Some("frame"))}>
        { (propSubj,propObj) match {
          case (ArgImpl(_,_,"subject"),PrepositionalObject(_,_,_)) => <rdf:type rdf:resource={lexinfo("NounPPFrame")}/>
            case (PrepositionalObject(_,_,_),ArgImpl(_,_,"subject")) => <rdf:type rdf:resource={lexinfo("NounPPFrame")}/><commit_msg>Subject of relational noun fix<commit_after>package net.lemonmodel.patterns

import java.net.URI
import scala.xml._
import net.lemonmodel.rdfutil.RDFUtil._
        
/**
 * A noun
 */
trait Noun extends Pattern {
  def makeWithForm(form : Form) : Noun
  protected def senseXML(namer : URINamer) : NodeSeq
  protected def isProper = false
  def withPlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"))))
  def withAccusative(form : String) = makeWithForm(Form(form,Map(lexinfo("case")->lexinfo("accusativeCase"))))
  def withDative(form : String) = makeWithForm(Form(form,Map(lexinfo("case")->lexinfo("dativeCase"))))
  def withGenitive(form : String) = makeWithForm(Form(form,Map(lexinfo("case")->lexinfo("genitiveCase"))))
  def withNominativeSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("nominativeCase"))))
  def withAccusativeSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("accusativeCase"))))
  def withGenitiveSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("genitiveCase"))))
  def withDativeSingular(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("singular"),lexinfo("case")->lexinfo("dativeCase"))))
  def withNominativePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("nominativeCase"))))
  def withAccusativePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("accusativeCase"))))
  def withGenitivePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("genitiveCase"))))
  def withDativePlural(form : String) = makeWithForm(Form(form,Map(lexinfo("number")->lexinfo("plural"),lexinfo("case")->lexinfo("dativeCase"))))
  def withGender(gender : Gender) : Noun
  def masculine = withGender(Masculine)
  def feminine = withGender(Feminine)
  def neuter = withGender(Neuter)
  def commonGender = withGender(CommonGender)
  def otherGender = withGender(OtherGender)
  def gender : Option[Gender]
  def lemma : NounPhrase
  def forms : Seq[Form]
  def toXML(namer : URINamer, lang : String) = <lemon:LexicalEntry rdf:about={namer("noun",lemma.toString())}>
      <lemon:canonicalForm>
        <lemon:LexicalForm rdf:about={namer("noun",lemma.toString(),Some("canonicalForm"))}>
          <lemon:writtenRep xml:lang={lang}>{lemma.toString()}</lemon:writtenRep>
        </lemon:LexicalForm>
      </lemon:canonicalForm>
      {gender match {
        case Some(g) => <lexinfo:gender rdf:resource={lexinfo(g.toString()).toString()}/>
        case None => 
        }
      }
      { lemma.toXML(namer,lang) }
      {
        for(form <- forms) yield {
          <lemon:otherForm>
            <lemon:LexicalForm rdf:about={namer("noun",lemma.toString(),Some("form"))}>
              <lemon:writtenRep xml:lang={lang}>{form.writtenRep}</lemon:writtenRep>
              {
                for((prop,propVal) <- form.props) yield {
                  val (prefixUri,prefix,suffix) = prefixURI(prop)
                  <lingonto:prop rdf:resource={propVal}/>.copy(prefix=prefix, label=suffix) %
                    Attribute("","xmlns:"+prefix,prefixUri,Null)
                }
              }
            </lemon:LexicalForm>
          </lemon:otherForm>
        }   
      }
      {senseXML(namer)}
    </lemon:LexicalEntry>
}   

sealed trait Gender

object Masculine extends Gender { override def toString = "masculine" }
object Feminine extends Gender { override def toString = "feminine" }
object Neuter extends Gender { override def toString = "neuter" }
object CommonGender extends Gender { override def toString = "commonGender" }
object OtherGender extends Gender { override def toString = "otherGender" }

/**
* A name (proper noun) associated to a named individual in the ontology
* @param lemma The canonical form of the name (required)
* @param sense The URI of the associated named individual
* @param forms The set of other forms
*/
case class Name(val lemma : PNP, 
                val sense : URI = null, 
                val forms : Seq[Form] = Nil,
                val gender : Option[Gender] = None) extends Noun {
  def makeWithForm(form : Form) = Name(lemma,sense, forms :+ form,gender)
  def withGender(gender : Gender) = Name(lemma,sense,forms,Some(gender))
  protected def senseXML(namer : URINamer) = <lemon:sense>
       <lemon:LexicalSense rdf:about={namer("noun",lemma.toString(),Some("sense"))}>
         <lemon:reference>
           <owl:NamedIndividual rdf:about={sense}/>
         </lemon:reference>
       </lemon:LexicalSense>
    </lemon:sense>
   protected override def isProper = true
}

/**
* A noun representing a genus of object associated with an ontology class
* @param form The canonical form of the noun (required)
* @param sense The URI to be associated with
* @param forms The set of other forms
*/
case class ClassNoun(val lemma : NP, 
                     val sense : URI = null, 
                     val forms : Seq[Form] = Nil,
                     val gender : Option[Gender] = None) extends Noun {
  def makeWithForm(form : Form) = ClassNoun(lemma,sense,forms :+ form,gender)
  def withGender(gender : Gender) = ClassNoun(lemma,sense,forms,Some(gender))
  def senseXML(namer : URINamer) = {
  val subjURI = namer("noun",lemma.toString(),Some("subject"))
    <lemon:sense>
      <lemon:LexicalSense rdf:about={namer("noun",lemma.toString(),Some("sense"))}>
         <lemon:reference>
           <owl:Class rdf:about={sense}/>
         </lemon:reference>
         <lemon:isA>
            <lemon:Argument rdf:about={subjURI}/>
         </lemon:isA>
       </lemon:LexicalSense>
    </lemon:sense> :+
    <lemon:synBehavior>
      <lemon:Frame rdf:about={namer("noun",lemma.toString(),Some("frame"))}>
        <rdf:type rdf:resource={lexinfo("NounPredicativeFrame")}/>
        <lexinfo:subject rdf:resource={subjURI}/>
      </lemon:Frame>
    </lemon:synBehavior>
  }
}

/**
 * A noun representing a bivalent relationship associated with an object property
 * in the ontology
 * @param form The canonical form of the noun (required)
 * @param sense The URI to be associated with
 * @param propSubj Indicates the argument that fills the subject (domain) of the object property
 * @param propObj Indicates the argument that fills the object (range) of the object property (required)
 * @param forms The set of other forms
 */
case class RelationalNoun(val lemma : NP, 
                          val sense : URI = null, 
                          val propSubj : Arg = CopulativeArg, 
                          val propObj : Arg, 
                          val forms : Seq[Form] = Nil,
                          val gender : Option[Gender] = None) extends Noun {
   def makeWithForm(inflForm : Form) = RelationalNoun(lemma,sense,propSubj,propObj,forms :+ inflForm,gender)
   def withGender(gender : Gender) = RelationalNoun(lemma,sense,propSubj,propObj,forms,Some(gender))
   protected def senseXML(namer : URINamer) = {
     val subjURI = namer("noun",lemma.toString(),Some("subject"))
     val objURI = namer("noun",lemma.toString(),Some("adpositionalObject"))
     <lemon:sense>
      <lemon:LexicalSense rdf:about={namer("noun",lemma.toString(),Some("sense"))}>
         <lemon:reference>
           <rdf:Property rdf:about={sense}/>
         </lemon:reference>
         <lemon:subjOfProp>
            <lemon:Argument rdf:about={subjURI}/>
         </lemon:subjOfProp>
         <lemon:objOfProp>
            <lemon:Argument rdf:about={objURI}/>
         </lemon:objOfProp>
        { 
          if(propSubj.restriction != None) {
            <lemon:propertyDomain rdf:resource={propSubj.restriction.get}/>
          }
        }
        { 
          if(propObj.restriction != None) {
            <lemon:propertyRange rdf:resource={propObj.restriction.get}/>
          }
        }
       </lemon:LexicalSense>
    </lemon:sense> :+
    <lemon:synBehavior>
      <lemon:Frame rdf:about={namer("noun",lemma.toString(),Some("frame"))}>
        { (propSubj,propObj) match {
          case (ArgImpl(_,_,"copulativeArg"),PrepositionalObject(_,_,_)) => <rdf:type rdf:resource={lexinfo("NounPPFrame")}/>
            case (PrepositionalObject(_,_,_),ArgImpl(_,_,"copulativeArg")) => <rdf:type rdf:resource={lexinfo("NounPPFrame")}/>
{'fraction_non_alphanumeric': 0.1441759275592403, 'fraction_numerical': 0.0, 'mean_word_length': 3.5585633878316805, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2236935', 'n_tokens_mistral': 5521, 'n_tokens_neox': 5265, 'n_words': 1037}