当前位置: 首页>>代码示例>>Scala>>正文


Scala Matcher类代码示例

本文整理汇总了Scala中java.util.regex.Matcher的典型用法代码示例。如果您正苦于以下问题:Scala Matcher类的具体用法?Scala Matcher怎么用?Scala Matcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Matcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: DoublePatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.Matcher

import org.opencompare.api.java.{Feature, Product, Value}

class DoublePatternInterpreter (
     validHeaders : List[String],
    regex : String,
    parameters : List[String],
    confident : Boolean)
    extends RegexPatternInterpreter(validHeaders, regex, parameters, confident) {

  override def createValue(s: String, matcher : Matcher, parameters : List[String], product : Product, feature : Feature) : Option[Value] = {
		  val value = factory.createRealValue()
		
		  value.setValue(try {
		    s.toDouble
		  } catch {
		    case e : NumberFormatException => Double.NaN
		    case e : NullPointerException => Double.NaN
		  })
		  
		  Some(value)
    
  }

} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:29,代码来源:DoublePatternInterpreter.scala

示例2: EmptyPatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.Matcher

import org.opencompare.api.java.{Feature, Product, Value}

class EmptyPatternInterpreter (
    validHeaders : List[String],
    regex : String,
    parameters : List[String],
    confident : Boolean)
    extends RegexPatternInterpreter(validHeaders, regex, parameters, confident) {

  override def createValue(s: String, matcher : Matcher, parameters : List[String], product : Product, feature : Feature) : Option[Value] = {
		  val value = factory.createNotAvailable()
		  Some(value)
  }

} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:20,代码来源:EmptyPatternInterpreter.scala

示例3: RegexPatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.{Matcher, Pattern}

import org.opencompare.api.java.{Value, Feature, Product}


abstract class RegexPatternInterpreter(initValidHeaders : List[String],
                              regex : String,
                              initParameters : List[String],
                              initConfident : Boolean) extends PatternInterpreter(initValidHeaders, initParameters, initConfident) {

  private val pattern : Pattern =  Pattern.compile(regex, Pattern.UNICODE_CHARACTER_CLASS |
    Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL)

  override def matchAndCreateValue(s: String, product: Product, feature: Feature): Option[Value] = {
    val matcher = pattern.matcher(s)
    if (matcher.matches()) {
      createValue(s, matcher, parameters, product, feature)
    } else {
      None
    }
  }

  def createValue(s : String, matcher : Matcher, parameters : List[String], product : Product, feature : Feature) : Option[Value]
} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:27,代码来源:RegexPatternInterpreter.scala

示例4: VariabilityConceptRefPatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.Matcher

import org.opencompare.api.java.{Feature, Product, Value}

class VariabilityConceptRefPatternInterpreter (
    validHeaders : List[String],
    regex : String,
    parameters : List[String],
    confident : Boolean)
    extends RegexPatternInterpreter(validHeaders, regex, parameters, confident) {

  override def createValue(s: String, matcher : Matcher, parameters : List[String], product : Product, feature : Feature) : Option[Value] = {
		val value = factory.createStringValue()
    value.setValue(s)
		Some(value)
  }
  
} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:21,代码来源:VariabilityConceptRefPatternInterpreter.scala

示例5: MultipleRegexPatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.Matcher

import org.opencompare.api.java.{Feature, Product, Value}

class MultipleRegexPatternInterpreter (
    validHeaders : List[String],
    regex : String,
    parameters : List[String],
    confident : Boolean)
    extends RegexPatternInterpreter(validHeaders, regex, parameters, confident) {

  override def createValue(s: String, matcher : Matcher, parameters : List[String], product : Product, feature : Feature) : Option[Value] = {
		  val value = parameters match { // TODO : support cardinality
//		    case "and" :: Nil => PcmmmFactory.eINSTANCE.createAnd()
//		    case "xor" :: Nil => PcmmmFactory.eINSTANCE.createXOr()
//		    case "or" :: Nil => PcmmmFactory.eINSTANCE.createOr()
		    case _ => factory.createMultiple()
		  }
		  var fullyInterpreted : Boolean = true

		  for (groupID <- 1 to matcher.groupCount()) {
			  val subConstraint = matcher.group(groupID)
			  if (subConstraint != null) {
				  lastCall = Some(s, product, feature)
				  val subCInterpretation = cellContentInterpreter.findInterpretation(subConstraint, product, feature)
				  if (subCInterpretation.isDefined) {
				    value.addSubValue(subCInterpretation.get)
				  } else {
				    fullyInterpreted = false
				  }
			  }

		  }
		  if (fullyInterpreted) {
			  Some(value)
		  } else {
			  None
		  }
  }

} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:44,代码来源:MultipleRegexPatternInterpreter.scala

示例6: InconsistentPatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.Matcher

import org.opencompare.api.java.{Feature, Product, Value}

class InconsistentPatternInterpreter (
    validHeaders : List[String],
    regex : String,
    parameters : List[String],
    confident : Boolean)
    extends RegexPatternInterpreter(validHeaders, regex, parameters, confident) {

  override def createValue(s: String, matcher : Matcher, parameters : List[String], product : Product, features : Feature) : Option[Value] = {
//		  val value = factory.create
//		  Some(value)
    None
  }

} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:21,代码来源:InconsistentPatternInterpreter.scala

示例7: UnknownPatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.Matcher

import org.opencompare.api.java.{Feature, Product, Value}

import scala.collection.immutable.List

class UnknownPatternInterpreter (
    validHeaders : List[String],
    regex : String,
    parameters : List[String],
    confident : Boolean)
    extends RegexPatternInterpreter(validHeaders, regex, parameters, confident) {

  override def createValue(s: String, matcher : Matcher, parameters : List[String], product : Product, feature : Feature) : Option[Value] = {
		 val value = factory.createNotAvailable()
		 Some(value)
  }

} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:22,代码来源:UnknownPatternInterpreter.scala

示例8: BooleanPatternInterpreter

//设置package包名称以及导入依赖的类
package org.opencompare.formalizer.interpreters

import java.util.regex.Matcher

import org.opencompare.api.java.{Feature, Product, Value}

class BooleanPatternInterpreter (
    validHeaders : List[String],
    regex : String,
    parameters : List[String],
    confident : Boolean)
    extends RegexPatternInterpreter(validHeaders, regex, parameters, confident) {
  
 
  override def createValue(s: String, matcher : Matcher, parameters : List[String], product : Product, feature : Feature) : Option[Value] = {
		  val value = factory.createBooleanValue();
		  if (!parameters.isEmpty) {
			  value.setValue(parameters.head.toBoolean)
		  } else {
			  value.setValue(false)
		  }
		  Some(value)
  }
    
} 
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:26,代码来源:BooleanPatternInterpreter.scala

示例9: message

//设置package包名称以及导入依赖的类
package com.wunder.pets.validations

import java.util.regex.{Matcher, Pattern}

import org.postgresql.util.PSQLException

trait ValidationError {
  def message: String
}

final class IsEmpty(val field: String) extends ValidationError {
  override def message: String = s"$field cannot be empty"
}

final class NotGreaterThan[T](val field: String, val lowerBound: T) extends ValidationError {
  def message: String = s"$field must be greater than $lowerBound"
}

final class NotLessThan[T](val field: String, val upperBound: T) extends ValidationError {
  def message: String = s"$field must be less than $upperBound"
}

final class DuplicateValue(val e: PSQLException) extends ValidationError {
  override def message: String = {
    val regex = "Key \\((.*)\\)=\\((.*)\\) already exists."
    val m: Matcher = Pattern.compile(regex).matcher(e.getServerErrorMessage.getDetail);
    if (m.matches) {
      s"${m.group(1)} has a duplicate value of ${m.group(2)}"
    } else {
      "Could not determine field and value."
    }
  }
}

final class GeneralError(val message: String) extends ValidationError 
开发者ID:wunderteam,项目名称:battle-pets-api,代码行数:36,代码来源:ValidationError.scala

示例10: AkkaConfigPropertySourceAdapterPatternSpec

//设置package包名称以及导入依赖的类
package com.github.scalaspring.akka.config

import java.util.regex.Matcher

import com.typesafe.scalalogging.StrictLogging
import org.scalatest.prop.TableDrivenPropertyChecks._
import org.scalatest.{FlatSpec, Matchers}

class AkkaConfigPropertySourceAdapterPatternSpec extends FlatSpec with Matchers with StrictLogging {

  val indexed = Table(
    ("name",                      "path",                 "index"),
    ("x[0]",                      "x",                    0),
    ("someProperty[0]",           "someProperty",         0),
    ("some_property[1]",          "some_property",        1),
    ("some.property[0]",          "some.property",        0),
    (" some.property[0] ",        "some.property",        0),
    ("some.other.property[893]",  "some.other.property",  893)
  )

  val nonIndexed = Table(
    ("name"),
    ("x"),
    ("someProperty"),
    ("some_property"),
    ("some.property"),
    ("some.other.property")
  )

  "Indexed property regular expression" should "match indexed property names" in {
    forAll (indexed) { (name: String, path: String, index: Int) =>
      val m: Matcher = AkkaConfigPropertySourceAdapter.INDEXED_PROPERTY_PATTERN.matcher(name)
      m.matches() shouldBe true
      m.group("path") shouldEqual path
      m.group("index") shouldEqual index.toString
    }
  }

  it should "not match non-indexed property names" in {
    forAll (nonIndexed) { (name: String) =>
      val m: Matcher = AkkaConfigPropertySourceAdapter.INDEXED_PROPERTY_PATTERN.matcher(name)
      m.matches() shouldBe false
    }
  }

} 
开发者ID:pspiegel,项目名称:akka-spring-boot,代码行数:47,代码来源:AkkaConfigPropertySourceAdapterPatternSpec.scala

示例11: Regexf

//设置package包名称以及导入依赖的类
package cas.utils

import java.util.regex.{Matcher, Pattern}

object Regexf {
  val wordsBound = "(\\b[^\\p{L}]+\\b)" // TODO: Care
  val allExceptText = "[^\\w\\s\\d\\p{L}]+"
  val upperCase = "[A-Z|\\p{Lu}]"
  val mainPunctuation = "[,\\.;!\"]+"

  def cleanAndSplit(str: String, byRegexp: String = wordsBound) = {
    val ptr = Pattern.compile(byRegexp)
    ptr.split(cleanToText(str))
  }

  def cleanToText(str: String) = {
    val sepsAndData: Pattern = Pattern.compile(allExceptText)
    val sepsAndDataM: Matcher = sepsAndData.matcher(str)
    sepsAndDataM.replaceAll("")
  }

  def countItems(str: String, regexp: String) = {
    val ptr = Pattern.compile(regexp)
    val matcher = ptr.matcher(str)
    var count = 0
    while (matcher.find) count += 1
    count
  }
} 
开发者ID:kell18,项目名称:CAS,代码行数:30,代码来源:Regexf.scala

示例12: LinkedRouteV2

//设置package包名称以及导入依赖的类
package webby.route.v2

import java.lang.reflect.{InvocationTargetException, Method}
import java.util.regex.{Matcher, Pattern}

import io.netty.handler.codec.http.HttpMethod
import webby.api.mvc.Handler
import webby.route.{DomainProvider, Var}

class LinkedRouteV2(val name: String,
                    val domainProvider: DomainProvider[_],
                    val method: HttpMethod,
                    val basePath: String,
                    val pattern: Pattern,
                    routeLinksForDomainData: (Any) => RouteHandlers,
                    val vars: Vector[Var[_]],
                    val varIndices: Vector[Int],
                    val linkMethod: Method) {
  require(!vars.contains(null), "All variables must be used in url. " + toString)
  require(varIndices.size == linkMethod.getParameterTypes.size, "Method argument count mismatch. Seems method with the same name already exists. You should rename it, or make it final. " + toString)

  def resolve(domain: Any, m: Matcher): Option[Handler] = {
    val routeLinks = routeLinksForDomainData(domain)
    var i: Int = 0
    val ln = varIndices.size
    val args = Array.ofDim[AnyRef](ln)
    while (i < ln) {
      val group: String = m.group(varIndices(i) + 1)
      val vr: Var[_] = vars(i)
      try {
        args(i) = vr.fromString(group).asInstanceOf[AnyRef]
      } catch {
        // ?????? ??? ???????? ???????? (??? ???????, ??? NumberFormatException, ????? ????? ??????? ??????? ??? int).
        case e: Throwable => return None
      }
      i += 1
    }
    try {
      Some(linkMethod.invoke(routeLinks, args: _*).asInstanceOf[Handler])
    } catch {
      case e: InvocationTargetException => throw e.getCause
    }
  }

  override def toString: String = method.name() + " (" + basePath + ") " + pattern + " - " + name
} 
开发者ID:citrum,项目名称:webby,代码行数:47,代码来源:LinkedRouteV2.scala

示例13: recognize

//设置package包名称以及导入依赖的类
package ner

import java.util.regex.{Matcher, Pattern}

import text.{StringNone, StringOption, StringSome}
import time.TimeTmp

import scala.collection.mutable.ListBuffer



trait NamedEntityRecognizer {
  protected type NEFile = String
  protected type NELine = String
  protected type MetaInfo = (NEFile, NELine)
  protected type NEText = String
  protected type NESynonyms = Seq[String]
  protected type NE = (NEText, MetaInfo, TimeTmp, NESynonyms)
  protected type NEList = List[NE]
  protected val recognizerName: String
  protected val entityList: NEList
  def recognize(textOpt: StringOption): Seq[NamedEntity] = {
    textOpt match {
      case StringSome(text) =>
        val buffer: ListBuffer[NamedEntity] = ListBuffer[NamedEntity]()
        entityList foreach {
          case (entity, (file, line), time, synonyms) if text contains entity =>
            val matcher: Matcher = Pattern.compile(Pattern.quote(entity)).matcher(text)
            while (matcher.find) {
              buffer += NamedEntity(
                StringOption(matcher.group),
                time,
                matcher.start until matcher.end,
                StringOption("%s:%s".format(file, line)),
                StringOption(recognizerName),
                synonyms
              )
            }
          case _ =>
          //Do nothing
        }
        buffer.result
      case StringNone =>
        Nil
    }
  }
  protected def initialize: NEList
} 
开发者ID:ktr-skmt,项目名称:FelisCatusZero,代码行数:49,代码来源:NamedEntityRecognizer.scala

示例14: extract

//设置package包名称以及导入依赖的类
package us.feliscat.ner

import java.util.regex.{Matcher, Pattern}

import us.feliscat.text.{StringNone, StringOption, StringSome}
import us.feliscat.time.TimeTmp

import scala.collection.mutable.ListBuffer



trait NamedEntityRecognizer {
  protected type NEFile = String
  protected type NELine = String
  protected type MetaInfo = (NEFile, NELine)
  protected type NEText = String
  protected type NESynonyms = Seq[String]
  protected type NE = (NEText, MetaInfo, TimeTmp, NESynonyms)
  protected type NEList = List[NE]
  protected val recognizerName: String
  protected val entityList: NEList
  protected def extract(sentence: StringOption): Seq[TimeTmp]
  def recognize(textOpt: StringOption): Seq[NamedEntity] = {
    textOpt match {
      case StringSome(text) =>
        val buffer = ListBuffer.empty[NamedEntity]
        entityList foreach {
          case (entity, (file, line), time, synonyms) if text contains entity =>
            val matcher: Matcher = Pattern.compile(Pattern.quote(entity)).matcher(text)
            while (matcher.find) {
              buffer += NamedEntity(
                StringOption(matcher.group),
                time,
                matcher.start until matcher.end,
                StringOption(s"$file:$line"),
                StringOption(recognizerName),
                synonyms
              )
            }
          case _ =>
          //Do nothing
        }
        buffer.result
      case StringNone =>
        Nil
    }
  }
  protected def initialize: NEList
} 
开发者ID:ktr-skmt,项目名称:FelisCatusZero-multilingual,代码行数:50,代码来源:NamedEntityRecognizer.scala

示例15: ssplit

//设置package包名称以及导入依赖的类
package uima.modules.common.ja

import java.util.regex.{Matcher, Pattern}

import uima.modules.common.MultiLingualDocumentAnnotator
import us.feliscat.sentence.ja.JapaneseSentenceSplitter
import us.feliscat.text.StringOption
import us.feliscat.time.TimeTmp
import us.feliscat.time.ja.JapaneseTimeExtractorForWorldHistory
import us.feliscat.types.TextAnnotation
import us.feliscat.types.ja.Morpheme
import us.feliscat.util.uima.fsList.FSListUtils

import scala.collection.mutable


trait JapaneseDocumentAnnotator extends MultiLingualDocumentAnnotator with JapaneseDocumentAnalyzer {
  override protected def ssplit(textOpt: StringOption): Seq[String] = {
    JapaneseSentenceSplitter.split(textOpt).map(_.text)
  }

  override protected def extractTime(sentenceOpt: StringOption): TimeTmp = {
    JapaneseTimeExtractorForWorldHistory.extractUnionTime(sentenceOpt)
  }

  override protected def correct(text: TextAnnotation, keywordSet: Seq[String]): Unit = {
    val builder = new mutable.StringBuilder(text.getText.length)
    text.getMorphemeList.toSeq.asInstanceOf[Seq[Morpheme]] foreach {
      morpheme: Morpheme =>
        if (!morpheme.getPos.startsWith("???")) {
          builder.append(morpheme.getOriginalText)
        }
    }
    text.setText(recursivelyRemoveNoise(builder.result, keywordSet, 0))
  }

  private def recursivelyRemoveNoise(text: String, keywordSet: Seq[String], index: Int): String = {
    val p: Pattern = Pattern.compile("""\([^\)]*\)""")
    val m: Matcher = p.matcher(text)
    if (m.find(index)) {
      if (keywordSet.contains(m.group)) {
        recursivelyRemoveNoise(
          text,
          keywordSet,
          m.end)
      } else {
        recursivelyRemoveNoise(
          text.substring(0, m.start) concat text.substring(m.end),
          keywordSet,
          m.start)
      }
    } else {
      text
    }
  }
} 
开发者ID:ktr-skmt,项目名称:FelisCatusZero-multilingual,代码行数:57,代码来源:JapaneseDocumentAnnotator.scala


注:本文中的java.util.regex.Matcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。