├── project ├── build.properties └── plugins.sbt ├── src ├── test │ ├── resources │ │ ├── lexical │ │ │ ├── test.csv │ │ │ └── stopwords.csv │ │ ├── logback-test.xml │ │ └── text │ │ │ ├── summary1.txt │ │ │ └── 1.txt │ └── scala │ │ └── com │ │ └── summarizer │ │ ├── PingServerStartupTest.scala │ │ ├── domain │ │ └── LexicalTest.scala │ │ ├── services │ │ ├── CommonServices.scala │ │ ├── VerbServiceTest.scala │ │ ├── FileServiceTest.scala │ │ ├── NounServiceTest.scala │ │ ├── SummaryServiceTest.scala │ │ ├── ParagraphServiceTest.scala │ │ ├── SentenceServiceTest.scala │ │ ├── LexicalChainServiceTest.scala │ │ ├── ChainScoresServiceTest.scala │ │ ├── SemanticListParserServiceTest.scala │ │ ├── PreProcessServiceTest.scala │ │ └── ExtractSentenceServiceTest.scala │ │ ├── unit │ │ └── helper │ │ │ └── TwitterFutures.scala │ │ └── feature │ │ └── SummaryFeatureTest.scala └── main │ ├── scala │ └── com │ │ ├── summarizer │ │ ├── domain │ │ │ ├── http │ │ │ │ ├── PingResponse.scala │ │ │ │ ├── SummaryPostResponse.scala │ │ │ │ └── SummaryPostRequest.scala │ │ │ ├── ErrorMessages.scala │ │ │ ├── Lexical.scala │ │ │ ├── Summary.scala │ │ │ ├── CorsFilter.scala │ │ │ └── Chain.scala │ │ ├── swagger │ │ │ └── SummarySwaggerDocument.scala │ │ ├── controllers │ │ │ ├── DefaultController.scala │ │ │ ├── PingController.scala │ │ │ └── SummaryController.scala │ │ ├── warmup │ │ │ └── WarmupHandler.scala │ │ ├── services │ │ │ ├── ParagraphService.scala │ │ │ ├── TurkishParser.scala │ │ │ ├── FileService.scala │ │ │ ├── SentenceService.scala │ │ │ ├── SemanticListParserService.scala │ │ │ ├── VerbService.scala │ │ │ ├── NounService.scala │ │ │ ├── LexicalChainService.scala │ │ │ ├── SummaryService.scala │ │ │ ├── PreProcessService.scala │ │ │ ├── ChainScoresService.scala │ │ │ └── ExtractSentenceService.scala │ │ ├── modules │ │ │ ├── CustomJacksonModule.scala │ │ │ ├── TurkishParserModule.scala │ │ │ ├── SummaryModule.scala │ │ │ ├── DatabaseModule.scala │ │ │ └── TurkishLanguageToolsModule.scala │ │ ├── repositories │ │ │ └── SummaryRepository.scala │ │ └── SummaryServer.scala │ │ └── scalaza │ │ └── raven │ │ └── future │ │ ├── Conversions.scala │ │ └── Converter.scala │ └── resources │ ├── application.conf │ ├── lexical │ ├── helperWords.csv │ └── stopwords.csv │ └── logback.xml ├── mongo-seed ├── Dockerfile └── init.json ├── docker-compose.yml ├── docker-compose.armhf.yml ├── .gitignore ├── ornek-api-kullanim └── ornek.html ├── Readme.md └── LICENSE /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 1.1.2 -------------------------------------------------------------------------------- /src/test/resources/lexical/test.csv: -------------------------------------------------------------------------------- 1 | ab:synonymy:su 2 | 3d yazıcı:related_with:donanım -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3") 2 | addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.4") -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/http/PingResponse.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain.http 2 | 3 | case class PingResponse(message: String) 4 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/http/SummaryPostResponse.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain.http 2 | 3 | case class SummaryPostResponse(result: Option[String]) -------------------------------------------------------------------------------- /mongo-seed/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mongo 2 | 3 | COPY init.json /init.json 4 | CMD mongoimport --host mongo --db summarydb --collection summary --type json --file /init.json --jsonArray -------------------------------------------------------------------------------- /src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | mongo { 2 | database = "summarydb" 3 | //uri = "mongodb://:@:/"${mongo.database} 4 | uri = "mongodb://mongo:27017" 5 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/swagger/SummarySwaggerDocument.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.swagger 2 | 3 | import io.swagger.models.Swagger 4 | 5 | object SummarySwaggerDocument extends Swagger 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/ErrorMessages.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain 2 | 3 | object ErrorMessages { 4 | val emptyContext = "Empty field not allowed. Please enter text for summarization." 5 | } 6 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | turkce-metin-ozetleme-scala: 4 | build: target/docker/stage 5 | ports: 6 | - "9999:9999" 7 | mem_limit: 2000m 8 | restart: always -------------------------------------------------------------------------------- /docker-compose.armhf.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | turkce-metin-ozetleme-scala: 4 | build: target/docker/stage 5 | ports: 6 | - "9999:9999" 7 | restart: always 8 | mem_limit: 1024m -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/http/SummaryPostRequest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain.http 2 | 3 | import com.twitter.finatra.validation.NotEmpty 4 | 5 | case class SummaryPostRequest(@NotEmpty contextOfText: String) { 6 | def toDomain = this.contextOfText 7 | } 8 | -------------------------------------------------------------------------------- /mongo-seed/init.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "contextOfText": "test", 4 | "summaryOfText": "test", 5 | "wordChain": "test", 6 | "filename": "test" 7 | }, 8 | { 9 | "contextOfText": "test2", 10 | "summaryOfText": "test2", 11 | "wordChain": "test2", 12 | "filename": "test2" 13 | } 14 | ] -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/controllers/DefaultController.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.controllers 2 | 3 | 4 | import com.twitter.finagle.http.Request 5 | import com.twitter.finatra.http.Controller 6 | 7 | 8 | class DefaultController extends Controller { 9 | get("/") { request: Request => 10 | response.movedPermanently.location("/api-docs/ui") 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | *.gz 4 | 5 | log* 6 | access* 7 | service* 8 | # sbt specific 9 | .cache/ 10 | .history/ 11 | .lib/ 12 | dist/* 13 | target/ 14 | summarydb/* 15 | lib_managed/ 16 | src_managed/ 17 | project/boot/ 18 | project/plugins/project/ 19 | 20 | # Scala-IDE specific 21 | .scala_dependencies 22 | .worksheet 23 | .idea 24 | 25 | .classpath 26 | .project 27 | .settings/ 28 | target/ 29 | -------------------------------------------------------------------------------- /ornek-api-kullanim/ornek.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/PingServerStartupTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer 2 | 3 | import com.google.inject.Stage 4 | import com.twitter.finatra.http.test.EmbeddedHttpServer 5 | import com.twitter.inject.Test 6 | 7 | class PingServerStartupTest extends Test { 8 | 9 | val server = new EmbeddedHttpServer( 10 | stage = Stage.PRODUCTION, 11 | twitterServer = new SummaryServer) 12 | 13 | "server" in { 14 | server.assertHealthy() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/domain/LexicalTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain 2 | import org.scalatest.FunSpec 3 | 4 | class LexicalTest extends FunSpec { 5 | 6 | describe("Get and Set Lexical") { 7 | it("should crete lexical correctly") { 8 | val newLexical = new Lexical("test",1,2) 9 | assert(newLexical.getWord() === "test") 10 | assert(newLexical.getSentenceNo() === 1) 11 | assert(newLexical.getParagraphNo() === 2) 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/warmup/WarmupHandler.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.warmup 2 | 3 | 4 | import com.google.inject.{Inject, Singleton} 5 | import com.twitter.finatra.http.routing.HttpWarmup 6 | import com.twitter.finatra.httpclient.RequestBuilder._ 7 | import com.twitter.inject.utils.Handler 8 | 9 | @Singleton 10 | class WarmupHandler @Inject()(httpWarmup: HttpWarmup) extends Handler { 11 | override def handle(): Unit = { 12 | httpWarmup.send(get("/ping"),times = 5) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %date %.-3level %-25X{traceId} %-25logger{0} %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/Lexical.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain 2 | 3 | class Lexical(word: String, sentenceNo: Int, paragraphNo: Int) { 4 | 5 | def getWord(): String = { 6 | word 7 | } 8 | 9 | def getSentenceNo(): Int = { 10 | sentenceNo 11 | } 12 | 13 | def getParagraphNo(): Int = { 14 | paragraphNo 15 | } 16 | 17 | def printLexical(): Unit = { 18 | println("Word: " + this.word) 19 | println("Sentence No: " + this.sentenceNo) 20 | println("Paragraph No: " + this.paragraphNo) 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/Summary.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain 2 | 3 | import org.json4s.DefaultFormats 4 | import org.mongodb.scala.bson.ObjectId 5 | 6 | case class Summary(_id: String = new ObjectId().toHexString, 7 | contextOfText: String, 8 | summaryOfText: Option[String] = None, 9 | wordChain: Option[String] = None, 10 | filename: Option[String] = None) 11 | 12 | object Summary { 13 | 14 | implicit val formats = new DefaultFormats {} 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/resources/text/summary1.txt: -------------------------------------------------------------------------------- 1 | Yıldız Kızlarımız Dünya Şampiyonu 2 | Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, voleybol tarihinin ilk Dünya şampiyonluğunu elde etti. Yıldız Milli Takım, TVF Başkent Salonu'nda yapılan final maçında baştan sona üstün bir performans sergileyerek, Dünyanın iyi takımları yer alan Çin'e göz açtırmadı. Tüm oyuncuların iyi oynadığı Türk Milli Takımı'nda Kübra Akman performansıyla göz doldururken, Çin Milli Takımı'nın solak smaçörü Peiyi Liu, Yıldız kızları zorlayan önemli oyuncu oldu. -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/ParagraphService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Singleton} 4 | 5 | @ImplementedBy(classOf[DefaultParagraphService]) 6 | trait ParagraphService { 7 | 8 | def getParagraphs(text: String): Seq[String] 9 | } 10 | 11 | @Singleton 12 | class DefaultParagraphService extends ParagraphService { 13 | 14 | def getParagraphs(text: String): Seq[String] = { 15 | val delimiter = "\n\n" 16 | val paragraphs = text.split(delimiter) 17 | 18 | paragraphs.filter(paragraph => paragraph.length > 1) 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/CommonServices.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import zemberek.tokenization.TurkishTokenizer 4 | 5 | trait CommonServices { 6 | val tokenizer = TurkishTokenizer.DEFAULT 7 | val sentenceService = new DefaultSentenceService 8 | val paragraphService = new DefaultParagraphService 9 | val nounService = new DefaultNounService(sentenceService, paragraphService) 10 | val verbService = new DefaultVerbService(sentenceService, paragraphService) 11 | val preProcessService = new DefaultPreProcessService(nounService,sentenceService,paragraphService) 12 | } 13 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/controllers/PingController.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.controllers 2 | 3 | import com.summarizer.domain.http.PingResponse 4 | import com.summarizer.swagger.SummarySwaggerDocument 5 | import com.github.xiaodongw.swagger.finatra.SwaggerSupport 6 | import com.twitter.finagle.http.Request 7 | import com.twitter.finatra.http.Controller 8 | 9 | class PingController extends Controller with SwaggerSupport { 10 | 11 | implicit protected val swagger = SummarySwaggerDocument 12 | 13 | get("/ping", swagger { 14 | _.summary("Get response for ping") 15 | .tag("Ping") 16 | .responseWith[PingResponse](200, "The pong message") 17 | }) { request: Request => 18 | info("ping") 19 | PingResponse(s"pong") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/CorsFilter.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain 2 | 3 | import com.twitter.finagle.http.{Request, Response} 4 | import com.twitter.finagle.{Service, SimpleFilter} 5 | import com.twitter.util.Future 6 | 7 | class CorsFilter extends SimpleFilter[Request, Response] { 8 | override def apply(request: Request, service: Service[Request, Response]): Future[Response] = { 9 | 10 | service(request).map { 11 | response => 12 | response.headerMap 13 | .add("access-control-allow-origin", "*") 14 | .add("access-control-allow-headers", "accept, content-type") 15 | .add("access-control-allow-methods", "GET,HEAD,POST,DELETE,OPTIONS,PUT,PATCH") 16 | 17 | response 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/TurkishParser.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{Inject, Singleton} 4 | import zemberek.morphology.TurkishMorphology 5 | import zemberek.tokenization.TurkishTokenizer 6 | 7 | //tek bir tane olusturmamiz gerek cunku cok zaman aliyor yaklasik 1,5 sn 8 | //server icin iyi degil , bu yuzden bu sekilde hizlandirildi 9 | @Singleton 10 | class TurkishParser @Inject()(turkishMorphology: TurkishMorphology, 11 | turkishTokenizer: TurkishTokenizer) 12 | { 13 | //parser ı burda oluşturmayıp fonksiyon içinde oluşturursak çok zaman alıyor! 14 | def getMorphology: TurkishMorphology = turkishMorphology 15 | def getTokenizer : TurkishTokenizer = turkishTokenizer 16 | } -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/unit/helper/TwitterFutures.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.unit.helper 2 | 3 | import com.twitter.util.{Return, Throw} 4 | import org.scalatest.concurrent.Futures 5 | 6 | trait TwitterFutures extends Futures { 7 | 8 | import scala.language.implicitConversions 9 | 10 | implicit def convertTwitterFuture[T](twitterFuture: com.twitter.util.Future[T]): FutureConcept[T] = 11 | new FutureConcept[T] { 12 | override def eitherValue: Option[Either[Throwable, T]] = { 13 | twitterFuture.poll.map { 14 | case Return(o) => Right(o) 15 | case Throw(e) => Left(e) 16 | } 17 | } 18 | override def isCanceled: Boolean = false 19 | override def isExpired: Boolean = false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/scala/com/scalaza/raven/future/Conversions.scala: -------------------------------------------------------------------------------- 1 | package com.scalaza.raven.future 2 | 3 | import com.scalaza.raven.future.Converter._ 4 | import com.twitter.{util => twitter} 5 | 6 | import scala.concurrent.ExecutionContext.Implicits.global 7 | import scala.concurrent.Future 8 | import scala.language.implicitConversions 9 | 10 | object Conversions { 11 | 12 | implicit class ScalaToTwitterFuture[T](f: Future[T]) { 13 | def toTwitterFuture: twitter.Future[T] = f 14 | } 15 | 16 | implicit class TwitterToScalaFuture[T](f: twitter.Future[T]) { 17 | def toScalaFuture: Future[T] = f 18 | } 19 | 20 | implicit class TwitterFutureFlatten[T](f: twitter.Future[twitter.Future[T]]) { 21 | def flatten(): twitter.Future[T] = f.flatMap(x => x) 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/modules/CustomJacksonModule.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.modules 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude.Include 4 | import com.fasterxml.jackson.core.JsonGenerator.Feature 5 | import com.fasterxml.jackson.databind.ObjectMapper 6 | import com.twitter.finatra.json.modules.FinatraJacksonModule 7 | import com.twitter.finatra.json.utils.CamelCasePropertyNamingStrategy 8 | 9 | object CustomJacksonModule extends FinatraJacksonModule { 10 | 11 | override val serializationInclusion = Include.ALWAYS 12 | 13 | override val propertyNamingStrategy = CamelCasePropertyNamingStrategy 14 | 15 | override def additionalMapperConfiguration(mapper: ObjectMapper) { 16 | mapper.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/modules/TurkishParserModule.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.modules 2 | 3 | import com.google.inject.{Provides, Singleton} 4 | import com.twitter.inject.TwitterModule 5 | import zemberek.morphology.TurkishMorphology 6 | import zemberek.tokenization.{TurkishSentenceExtractor, TurkishTokenizer} 7 | 8 | //tek bir tane olusturmamiz gerek cunku cok zaman aliyor yaklasik 1,5 sn 9 | //server icin iyi degil , bu yuzden bu sekilde hizlandirildi 10 | @Singleton 11 | @Provides 12 | object TurkishParserModule extends TwitterModule { 13 | 14 | val getMorphology: TurkishMorphology = TurkishMorphology.createWithDefaults() 15 | 16 | val getTokenizer : TurkishTokenizer = TurkishTokenizer.DEFAULT 17 | 18 | val sentenceExtractor: TurkishSentenceExtractor = TurkishSentenceExtractor.DEFAULT 19 | 20 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/modules/SummaryModule.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.modules 2 | 3 | import com.summarizer.services._ 4 | import com.twitter.inject.TwitterModule 5 | 6 | object SummaryModule extends TwitterModule{ 7 | override def configure { 8 | bind[ChainScoresService].to[DefaultChainScoresService] 9 | bind[ExtractSentenceService].to[DefaultExtractSentenceService] 10 | bind[FileService].to[DefaultFileService] 11 | bind[LexicalChainService].to[DefaultLexicalChainService] 12 | bind[NounService].to[DefaultNounService] 13 | bind[ParagraphService].to[DefaultParagraphService] 14 | bind[PreProcessService].to[DefaultPreProcessService] 15 | bind[SemanticListParserService].to[DefaultSemanticListParserService] 16 | bind[SentenceService].to[DefaultSentenceService] 17 | bind[VerbService].to[DefaultVerbService] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/VerbServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import org.scalatest.FunSpec 4 | 5 | class VerbServiceTest extends FunSpec with CommonServices { 6 | 7 | val paragraph1 = "Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.\n\n" 8 | val paragraph2 = "İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir." 9 | 10 | describe("Get verbs") { 11 | it("should return all verbs") { 12 | val text = paragraph1.concat(paragraph2) 13 | val verbs = verbService.getVerbs(text) 14 | val result = Seq("yenmek", "olmak", "etmek", "yapmak", "düzenlemek", "elemek", "katılmak") 15 | 16 | assert(verbs === result) 17 | } 18 | 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/FileService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | import com.twitter.inject.Logging 3 | 4 | import scala.io.Source._ 5 | import java.io._ 6 | 7 | import com.google.inject.{ImplementedBy, Singleton} 8 | 9 | import scala.io.{Codec, Source} 10 | 11 | @ImplementedBy(classOf[DefaultFileService]) 12 | trait FileService extends Logging { 13 | 14 | def readFile(path: String): String 15 | 16 | def writeFile(path: String, file: String) 17 | 18 | } 19 | 20 | @Singleton 21 | class DefaultFileService extends FileService { 22 | 23 | def readFile(path: String): String = { 24 | val source = Source.fromInputStream(getClass().getClassLoader().getResourceAsStream(path))(Codec.UTF8) 25 | val text = try source.mkString finally source.close() 26 | text 27 | } 28 | 29 | def writeFile(path: String, file: String) = { 30 | val writer = new PrintWriter(new File(path)) 31 | writer.write(file) 32 | writer.close() 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/FileServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import org.scalatest.FunSpec 4 | import org.scalatest.Matchers._ 5 | 6 | class FileServiceTest extends FunSpec { 7 | 8 | def randomString(length: Int) = { 9 | val r = new scala.util.Random 10 | val sb = new StringBuilder 11 | for (i <- 1 to length) { 12 | sb.append(r.nextPrintableChar) 13 | } 14 | sb.toString 15 | } 16 | 17 | describe("Read and write file") { 18 | val fileService = new DefaultFileService 19 | val file = randomString(15) 20 | 21 | it("should write file successfully") { 22 | val resourcesPath = getClass.getResource("/lexical/test.csv").getPath 23 | fileService.writeFile(resourcesPath,file) 24 | } 25 | 26 | it("should read file successfully") { 27 | val resourcesPath = "lexical/test.csv" 28 | val result = fileService.readFile(resourcesPath) 29 | val expectedResult = file 30 | result shouldBe expectedResult 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/repositories/SummaryRepository.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.repositories 2 | 3 | import com.google.inject.Singleton 4 | import com.summarizer.domain.Summary 5 | import com.summarizer.modules.DatabaseModule._ 6 | import org.mongodb.scala._ 7 | import com.twitter.util.{Future => TwitterFuture} 8 | import com.scalaza.raven.future.Conversions._ 9 | import scala.concurrent.ExecutionContext.Implicits.global 10 | import org.mongodb.scala.model.Filters._ 11 | 12 | @Singleton 13 | class SummaryRepository { 14 | private val summaryCollection = provideSummaryCollection() 15 | 16 | def findByContextOfText(contextOfText: String): TwitterFuture[Option[Summary]] = 17 | summaryCollection 18 | .find(equal("contextOfText", contextOfText)) 19 | .toFuture() 20 | .map(_.headOption) 21 | .toTwitterFuture 22 | 23 | def save(summary: Summary): TwitterFuture[String] = 24 | summaryCollection 25 | .insertOne(summary) 26 | .toFuture() 27 | .map(_ => summary._id) 28 | .toTwitterFuture 29 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/SentenceService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Inject, Singleton} 4 | import com.summarizer.modules.TurkishParserModule 5 | import zemberek.tokenization.TurkishSentenceExtractor 6 | 7 | import scala.collection.JavaConverters._ 8 | 9 | @ImplementedBy(classOf[DefaultSentenceService]) 10 | trait SentenceService { 11 | 12 | def getSentences(text: String): Seq[String] 13 | def getTitle(sentences: Seq[String]): String 14 | } 15 | 16 | @Singleton 17 | class DefaultSentenceService extends SentenceService { 18 | 19 | val sentenceExtractor = TurkishParserModule.sentenceExtractor 20 | 21 | def getSentences(text: String): Seq[String] = { 22 | sentenceExtractor.fromParagraph(text).asScala.toList 23 | } 24 | 25 | //ilk cümleyi alır ve başlık sonunda bir noktalama işareti olmadığı için, 26 | // satırlara böler, ilk satırı başlık olarak geri dönderir 27 | def getTitle(sentences: Seq[String]): String = { 28 | sentences.head.split("\\r?\\n").head 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/NounServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import org.scalatest.FunSpec 4 | 5 | class NounServiceTest extends FunSpec with CommonServices { 6 | 7 | val paragraph1 = "Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.\n\n" 8 | val paragraph2 = "İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir." 9 | 10 | describe("Get nouns") { 11 | it("should return all nouns") { 12 | val text = paragraph1.concat(paragraph2) 13 | val nouns = nounService.getNouns(text) 14 | val result = Seq("dünya", "yıldız", "kız", "voleybol", "şampiyona", "yıldız", "takım", "final", "maç", "çin", "şampiyon", "türkiye", "voleybol", "tarih", "dünya", "şampiyon", "el", "şampiyona", "yıl", "brezilya", "curitiba", "kent", "yıl", "şampiyona", "kıta", "ele", "ülke", "takım") 15 | 16 | assert(nouns === result) 17 | } 18 | 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/main/scala/com/scalaza/raven/future/Converter.scala: -------------------------------------------------------------------------------- 1 | package com.scalaza.raven.future 2 | 3 | import com.twitter.{util => twitter} 4 | 5 | import scala.concurrent.ExecutionContext.Implicits.global 6 | import scala.concurrent.{ExecutionContext, Future, Promise} 7 | import scala.language.implicitConversions 8 | import scala.util.{Failure, Success, Try} 9 | 10 | 11 | object Converter { 12 | implicit def scalaToTwitterTry[T](t: Try[T]): twitter.Try[T] = t match { 13 | case Success(r) => twitter.Return(r) 14 | case Failure(ex) => twitter.Throw(ex) 15 | } 16 | 17 | implicit def twitterToScalaTry[T](t: twitter.Try[T]): Try[T] = t match { 18 | case twitter.Return(r) => Success(r) 19 | case twitter.Throw(ex) => Failure(ex) 20 | } 21 | 22 | implicit def scalaToTwitterFuture[T](f: Future[T])(implicit ec: ExecutionContext): twitter.Future[T] = { 23 | val promise = twitter.Promise[T]() 24 | f.onComplete(promise update _) 25 | promise 26 | } 27 | 28 | implicit def twitterToScalaFuture[T](f: twitter.Future[T]): Future[T] = { 29 | val promise = Promise[T]() 30 | f.respond(promise complete _) 31 | promise.future 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/modules/DatabaseModule.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.modules 2 | 3 | import com.summarizer.domain.Summary 4 | import com.google.inject.{Provides, Singleton} 5 | import com.twitter.inject.TwitterModule 6 | import org.bson.codecs.configuration.CodecRegistries._ 7 | import org.mongodb.scala._ 8 | import org.mongodb.scala.bson.codecs.DEFAULT_CODEC_REGISTRY 9 | import org.mongodb.scala.bson.codecs.Macros._ 10 | import com.typesafe.config.ConfigFactory 11 | 12 | @Singleton 13 | @Provides 14 | object DatabaseModule extends TwitterModule { 15 | val config = ConfigFactory.load() 16 | val MONGODB_URI = config.getString("mongo.uri") 17 | val MONGODB_DB_NAME = config.getString("mongo.database") 18 | val MONGODB_COLLECTION_SUMMARY = "summary" 19 | 20 | lazy val mongoClient: MongoClient = MongoClient(MONGODB_URI) 21 | lazy val codecRegistry = fromRegistries(fromProviders(classOf[Summary]), DEFAULT_CODEC_REGISTRY) 22 | lazy val database: MongoDatabase = mongoClient.getDatabase(MONGODB_DB_NAME).withCodecRegistry(codecRegistry) 23 | 24 | def provideSummaryCollection(): MongoCollection[Summary] = database.getCollection[Summary](MONGODB_COLLECTION_SUMMARY) 25 | } -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/SummaryServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import org.scalatest.FunSpec 4 | import com.twitter.inject.Mockito 5 | import com.twitter.util.Await 6 | import org.scalatest.Matchers._ 7 | 8 | class SummaryServiceTest extends FunSpec with CommonServices with Mockito { 9 | 10 | describe("Get summary") { 11 | val lexicalChainService = new DefaultLexicalChainService 12 | val chainScoresService = new DefaultChainScoresService 13 | val extractSentenceService = new DefaultExtractSentenceService 14 | val summaryService = new DefaultSummaryService(preProcessService, nounService, lexicalChainService, chainScoresService, extractSentenceService, sentenceService) 15 | val fileService = new DefaultFileService 16 | it("should create summary") { 17 | val fileResourcesPath = "text/1.txt" 18 | val file = fileService.readFile(fileResourcesPath) 19 | val summaryResourcesPath = "text/summary1.txt" 20 | val expected = fileService.readFile(summaryResourcesPath) 21 | val summary = summaryService.create(file) 22 | val result = Await.result(summary).right.get.summaryOfText 23 | result shouldBe Some(expected) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/ParagraphServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | import org.scalatest.FunSpec 3 | 4 | class ParagraphServiceTest extends FunSpec { 5 | val paragraphService = new DefaultParagraphService 6 | val title = "Yıldız Kızlarımız Dünya Şampiyonu\n\n" 7 | val paragraph1 = "Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.\n\n" 8 | val paragraph2 = "Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği ve 18 yaşının altındaki voleybolcuların katılabildiği bir şampiyonadır. İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir." 9 | 10 | describe("Get paragraphs") { 11 | it("should get paragraphs correctly") { 12 | val text = title.concat(paragraph1).concat(paragraph2) 13 | assert(paragraphService.getParagraphs(text).length === 3) 14 | } 15 | 16 | it("should remove empty paragraphs") { 17 | val emptyLines = "\n\n" 18 | val text = title.concat(paragraph1).concat(paragraph2).concat(emptyLines) 19 | assert(paragraphService.getParagraphs(text).length === 3) 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/feature/SummaryFeatureTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.feature 2 | 3 | import com.summarizer.SummaryServer 4 | import com.summarizer.domain.Summary 5 | import com.summarizer.services.SummaryService 6 | import com.google.inject.testing.fieldbinder.Bind 7 | import com.twitter.finagle.http.Status 8 | import com.twitter.finatra.http.test.EmbeddedHttpServer 9 | import com.twitter.finagle.http.Status._ 10 | import com.twitter.inject.server.FeatureTest 11 | import com.twitter.inject.Mockito 12 | import com.twitter.util.Future 13 | 14 | class SummaryFeatureTest extends FeatureTest with Mockito { 15 | 16 | override val server = new EmbeddedHttpServer(new SummaryServer) 17 | val summary = Summary(_id = "5ab95038231118493361db1f", contextOfText = "Summary Test", summaryOfText = Some("Test is Successful")) 18 | @Bind val summaryService = mock[SummaryService] 19 | 20 | "post /ozetle/api/new" should { 21 | "return summary of the text" in { 22 | summaryService.create(anyString) returns Future.value(Right(summary)) 23 | 24 | server.httpPost( 25 | path = "/ozetle/api/new", 26 | postBody = 27 | """ 28 | { 29 | "contextOfText" : "Summary Test" 30 | } 31 | """, 32 | withJsonBody = 33 | s"""{ 34 | "result":"Test is Successful" 35 | }""", 36 | andExpect = Ok 37 | ) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/modules/TurkishLanguageToolsModule.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.modules 2 | 3 | import com.google.inject.{Provides, Singleton} 4 | import com.summarizer.services.{DefaultFileService, DefaultSemanticListParserService} 5 | import com.twitter.inject.TwitterModule 6 | 7 | @Singleton 8 | @Provides 9 | object TurkishLanguageToolsModule extends TwitterModule { 10 | private val fileService = new DefaultFileService 11 | private val semanticListParserService = new DefaultSemanticListParserService 12 | 13 | private val semanticRelationWordList = { 14 | val resourcesPath = "lexical/all_relations.csv" 15 | val file = fileService.readFile(resourcesPath) 16 | val parsedFile = file.split("\n").toSeq 17 | val words = semanticListParserService.createWordList(parsedFile) 18 | semanticListParserService.createRelationList(words, parsedFile) 19 | } 20 | 21 | private val stopWordList = { 22 | val resourcesPath = "lexical/stopwords.csv" 23 | val file = fileService.readFile(resourcesPath) 24 | file.split("\n").toSeq 25 | } 26 | 27 | private val helperWordList = { 28 | val resourcesPath = "lexical/helperWords.csv" 29 | val file = fileService.readFile(resourcesPath) 30 | file.split("\n").toSeq 31 | } 32 | 33 | def getSemanticRelationWordList : Map[String, Seq[String]] = semanticRelationWordList 34 | 35 | def getStopWordList : Seq[String] = stopWordList 36 | 37 | def getHelperWordList : Seq[String] = helperWordList 38 | } -------------------------------------------------------------------------------- /src/test/resources/text/1.txt: -------------------------------------------------------------------------------- 1 | Yıldız Kızlarımız Dünya Şampiyonu 2 | 3 | Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti. 4 | 5 | Yıldız Milli Takım, TVF Başkent Salonu'nda yapılan final maçında baştan sona üstün bir performans sergileyerek, Dünyanın en iyi takımları arasında yer alan Çin'e adeta göz açtırmadı. Tüm oyuncuların iyi oynadığı Türk Milli Takımı'nda Kübra Akman performansıyla göz doldururken, Çin Milli Takımı'nın solak smaçörü Peiyi Liu, Yıldız kızları zorlayan en önemli oyuncu oldu. Türkiye, 2007 yılında Meksika'da yapılan Dünya Yıldız Kızlar Şampiyonası finalinde Çin'e karşı 3-1 kaybederek Dünya ikincisi olduğu maçın rövanşını set kayıpsız aldı. 6 | 7 | Bu arada karşılaşmayı Gençlik ve Spor Bakanı Suat Kılıç, Türkiye Voleybol Federasyonu Başkanı Erol Ünal Karabıyık ile birlikte protokol tribününden takip etti. TVF Başkent Salonu'nun tamamını dolduran seyirciler, ellerindeki Türk bayraklarıyla maç boyunca Türk Milli Takımı'nı coşkulu bir şekilde desteklediler.Voleybolseverler, TVF Bandosunun çaldığı hareketli parçalara eşlik ederek, takımlarını bir an bile yalnız bırakmadılar. 8 | 9 | Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği ve 18 yaşının altındaki voleybolcuların katılabildiği bir şampiyonadır. İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir. -------------------------------------------------------------------------------- /src/main/resources/lexical/helperWords.csv: -------------------------------------------------------------------------------- 1 | acaba 2 | adeta 3 | aksine 4 | ama 5 | ancak 6 | arada 7 | arasında 8 | artık 9 | aslında 10 | ayrıca 11 | bana 12 | bazen 13 | bazı 14 | belki 15 | benden 16 | bi 17 | bile 18 | biraz 19 | birçok 20 | birkaç 21 | birkez 22 | birşey 23 | birşeyi 24 | böyle 25 | böylece 26 | buna 27 | bunda 28 | bundan 29 | bunlar 30 | bunları 31 | bunların 32 | bunu 33 | bunun 34 | burada 35 | buradan 36 | bütün 37 | çok 38 | çünkü 39 | da 40 | daha 41 | dahi 42 | dedi 43 | defa 44 | değil 45 | dek 46 | diğer 47 | diye 48 | dolayı 49 | dolayısıyla 50 | eğer 51 | elbette 52 | en 53 | etmesi 54 | gercekten 55 | gibi 56 | göre 57 | hala 58 | halen 59 | hatta 60 | hem 61 | hemen 62 | henüz 63 | hep 64 | hepsi 65 | her 66 | herhangi 67 | herkesin 68 | hiç 69 | hiçbir 70 | ile 71 | ilgili 72 | ise 73 | işte 74 | istifade 75 | itibaren 76 | itibariyle 77 | kadar 78 | karşın 79 | kesinlikle 80 | kez 81 | ki 82 | kimse 83 | lakin 84 | muhtemelen 85 | neredeyse 86 | nihayet 87 | niye 88 | of 89 | olan 90 | onun 91 | oradan 92 | öyle 93 | oysa 94 | öz 95 | özü 96 | pek 97 | rağmen 98 | sadece 99 | sanki 100 | şekilde 101 | şey 102 | şeyden 103 | şeyi 104 | şeyler 105 | sonra 106 | şöyle 107 | şu 108 | şuna 109 | şunda 110 | şundan 111 | şunları 112 | şunu 113 | tamamen 114 | tarafından 115 | teessüf 116 | temelde 117 | tüm 118 | üzere 119 | ya 120 | yalnız 121 | yani 122 | yerine 123 | yine 124 | yoksa 125 | zaman 126 | zaten 127 | -------------------------------------------------------------------------------- /src/test/resources/lexical/stopwords.csv: -------------------------------------------------------------------------------- 1 | acaba 2 | altmış 3 | altı 4 | ama 5 | ancak 6 | arada 7 | aslında 8 | ayrıca 9 | bana 10 | bazı 11 | belki 12 | benden 13 | beri 14 | beş 15 | bile 16 | bin 17 | bir 18 | birçok 19 | biri 20 | birkaç 21 | birkez 22 | birşey 23 | birşeyi 24 | böyle 25 | böylece 26 | bu 27 | buna 28 | bunda 29 | bundan 30 | bunlar 31 | bunları 32 | bunların 33 | bunu 34 | bunun 35 | burada 36 | çok 37 | çünkü 38 | daha 39 | dahi 40 | defa 41 | değil 42 | diğer 43 | diye 44 | doksan 45 | dokuz 46 | dolayı 47 | dolayısıyla 48 | dört 49 | eğer 50 | elli 51 | en 52 | etmesi 53 | gibi 54 | göre 55 | halen 56 | hangi 57 | hatta 58 | hem 59 | henüz 60 | hep 61 | hepsi 62 | her 63 | herhangi 64 | herkesin 65 | hiç 66 | hiçbir 67 | için 68 | iki 69 | ile 70 | ilgili 71 | ise 72 | işte 73 | itibaren 74 | itibariyle 75 | kadar 76 | karşın 77 | katrilyon 78 | kez 79 | ki 80 | kim 81 | kimden 82 | kime 83 | kimi 84 | kimse 85 | kırk 86 | milyar 87 | milyon 88 | mu 89 | mü 90 | mı 91 | o 92 | on 93 | otuz 94 | oysa 95 | öyle 96 | pek 97 | rağmen 98 | sadece 99 | sanki 100 | sekiz 101 | seksen 102 | şey 103 | şeyden 104 | şeyi 105 | şeyler 106 | şöyle 107 | şu 108 | şuna 109 | şunda 110 | şundan 111 | şunları 112 | şunu 113 | tarafından 114 | trilyon 115 | tüm 116 | üç 117 | üzere 118 | var 119 | vardı 120 | ve 121 | veya 122 | ya 123 | yani 124 | yedi 125 | yerine 126 | yetmiş 127 | yine 128 | yirmi 129 | yoksa 130 | yüz 131 | zaten 132 | yüzbin 133 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/SemanticListParserService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Singleton} 4 | import com.twitter.inject.Logging 5 | 6 | @ImplementedBy(classOf[DefaultSemanticListParserService]) 7 | trait SemanticListParserService extends Logging { 8 | 9 | def createWordList(file: Seq[String]): Seq[String] 10 | 11 | def createRelationList(words: Seq[String], file: Seq[String]): Map[String,Seq[String]] 12 | 13 | } 14 | 15 | @Singleton 16 | class DefaultSemanticListParserService extends SemanticListParserService { 17 | 18 | def createWordList(file: Seq[String]): Seq[String] = { 19 | val words = file.map(_.split(":").head).distinct 20 | words 21 | } 22 | 23 | def createRelationList(words: Seq[String], file: Seq[String]): Map[String,Seq[String]] = { 24 | var relations: Seq[String] = Seq.empty[String] 25 | var relationMap: Map[String,Seq[String]] = Map.empty[String,Seq[String]] 26 | 27 | var word = file.head.split(":")(0) 28 | relations = relations :+ file.head 29 | 30 | for( index <- 1 until file.size) { 31 | 32 | val previousWord = file(index-1).split(":")(0) 33 | word = file(index).split(":")(0) 34 | if(word == previousWord) { 35 | relations = relations :+ file(index) 36 | } else { 37 | relationMap += (previousWord -> relations) 38 | relations = Seq.empty[String] 39 | relations = relations :+ file(index) 40 | } 41 | } 42 | relationMap += (word -> relations) 43 | relationMap 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/SentenceServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import zemberek.tokenization.TurkishSentenceExtractor 4 | import org.scalatest.FlatSpec 5 | import org.scalatest.Matchers._ 6 | 7 | class SentenceServiceTest extends FlatSpec { 8 | val sentenceService = new DefaultSentenceService 9 | 10 | val title = "Yıldız Kızlarımız Dünya Şampiyonu\n\n" 11 | val paragraph1 = "Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.\n\n" 12 | val paragraph2 = "Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği ve 18 yaşının altındaki voleybolcuların katılabildiği bir şampiyonadır. İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir." 13 | 14 | it should "get sentences from paragraph correctly" in { 15 | val sentence1 = "Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu." 16 | val sentence2 = "Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti." 17 | 18 | val result = sentenceService.getSentences(paragraph1) 19 | result shouldBe Seq(sentence1,sentence2) 20 | } 21 | 22 | it should "get title" in { 23 | val textWithTitle = title.concat(paragraph1) 24 | val expectedTitle = title.replaceAll("\n","") 25 | val result = sentenceService.getTitle(Seq(textWithTitle)) 26 | result shouldBe expectedTitle 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/LexicalChainServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.summarizer.domain.{Chain, Lexical} 4 | import org.scalatest.FunSpec 5 | 6 | class LexicalChainServiceTest extends FunSpec { 7 | 8 | val lexicalChainService = new DefaultLexicalChainService 9 | describe("build chains") { 10 | it("should build chains") { 11 | 12 | val lexical1 = new Lexical("araba", 1, 1) 13 | val lexical2 = new Lexical("otobüs", 1, 2) 14 | val lexical3 = new Lexical("moto", 1, 3) 15 | val lexical4 = new Lexical("bisiklet", 1, 5) 16 | 17 | val chains = lexicalChainService.buildChains(Seq(lexical1, lexical2, lexical3, lexical4)) 18 | val chain1 = Chain(None, 0, 0.0, List((lexical1, "synonymy", "otomobil"))) 19 | val chain2 = Chain(None, 0, 0.0, List((lexical1, "synonymy", "tekerlekli"))) 20 | val chain3 = Chain(None, 0, 0.0, List((lexical2, "holo_member", "araç filosu"))) 21 | val chain4 = Chain(None, 0, 0.0, List((lexical2, "holo_member", "toplu taşıma aracı"))) 22 | val chain5 = Chain(None, 0, 0.0, List((lexical2, "synonymy", "motorlu"))) 23 | chain5.addLexicalToChain(lexical3, "synonymy", "motorlu") 24 | val chain6 = Chain(None, 0, 0.0, List((lexical1, "hypernymy", "taşıt"))) 25 | chain6.addLexicalToChain(lexical4, "hypernymy", "taşıt") 26 | val chain7 = Chain(None, 0, 0.0, List((lexical4, "synonymy", "çiftteker"))) 27 | 28 | assert(chains.size === 7) 29 | assert(chains.contains(chain1) === true) 30 | assert(chains.contains(chain2) === true) 31 | assert(chains.contains(chain3) === true) 32 | assert(chains.contains(chain4) === true) 33 | assert(chains.contains(chain5) === true) 34 | assert(chains.contains(chain6) === true) 35 | assert(chains.contains(chain7) === true) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/SummaryServer.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer 2 | 3 | import com.summarizer.controllers._ 4 | import com.summarizer.modules.{CustomJacksonModule, SummaryModule, TurkishParserModule} 5 | import com.summarizer.swagger.SummarySwaggerDocument 6 | import com.summarizer.warmup.WarmupHandler 7 | import com.github.xiaodongw.swagger.finatra.SwaggerController 8 | import com.summarizer.domain.CorsFilter 9 | import com.twitter.finagle.http.{Request, Response} 10 | import com.twitter.finatra.http.HttpServer 11 | import com.twitter.finatra.http.filters.{CommonFilters, LoggingMDCFilter, TraceIdMDCFilter} 12 | import com.twitter.finatra.http.routing.HttpRouter 13 | import com.twitter.inject.requestscope.FinagleRequestScopeFilter 14 | import io.swagger.models.Info 15 | 16 | object SummaryServerMain extends SummaryServer 17 | 18 | class SummaryServer extends HttpServer { 19 | 20 | SummarySwaggerDocument.info(new Info() 21 | .description("Summary application API") 22 | .version("0.0.1") 23 | .title("Summary") 24 | ) 25 | 26 | override def jacksonModule = CustomJacksonModule 27 | 28 | override def modules = Seq(SummaryModule, TurkishParserModule) 29 | 30 | override def defaultFinatraHttpPort = ":9999" 31 | 32 | override val disableAdminHttpServer: Boolean = true 33 | 34 | override def configureHttp(router: HttpRouter): Unit = { 35 | router 36 | .filter[FinagleRequestScopeFilter[Request,Response]] 37 | .filter[LoggingMDCFilter[Request, Response]] 38 | .filter[TraceIdMDCFilter[Request, Response]] 39 | .filter[CommonFilters] 40 | .add(new SwaggerController(swagger = SummarySwaggerDocument)) 41 | .add[PingController] 42 | .add[CorsFilter, SummaryController] 43 | .add[DefaultController] 44 | } 45 | 46 | override def warmup(): Unit = { 47 | run[WarmupHandler]() 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/VerbService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Inject, Singleton} 4 | import zemberek.morphology.analysis.{SentenceAnalysis, SingleAnalysis} 5 | import com.summarizer.modules.TurkishParserModule 6 | import com.twitter.inject.Logging 7 | 8 | import scala.collection.JavaConverters._ 9 | 10 | @ImplementedBy(classOf[DefaultVerbService]) 11 | trait VerbService { 12 | 13 | def getAnalyses(text: String): Seq[SentenceAnalysis] 14 | 15 | def handleAnalyses(analysis: SentenceAnalysis) : Seq[String] 16 | 17 | def getVerbs(text: String): Seq[String] 18 | 19 | } 20 | 21 | @Singleton 22 | class DefaultVerbService @Inject() (sentenceService: SentenceService, 23 | paragraphService: ParagraphService) extends VerbService with Logging { 24 | 25 | val turkishMorphology = TurkishParserModule.getMorphology 26 | 27 | override def getAnalyses(text: String): Seq[SentenceAnalysis] = { 28 | val paragraphs = paragraphService.getParagraphs(text) 29 | val sentences = paragraphs.flatMap(paragraph => sentenceService.getSentences(paragraph)) 30 | val analyses : Seq[SentenceAnalysis] = sentences.map { sentence => 31 | val analysis = turkishMorphology.analyzeSentence(sentence) 32 | turkishMorphology.disambiguate(sentence, analysis) 33 | } 34 | analyses 35 | } 36 | 37 | override def handleAnalyses(analysis: SentenceAnalysis): Seq[String] = { 38 | var verbs : Seq[String] = Seq.empty[String] 39 | for(word : SingleAnalysis <- analysis.bestAnalysis().asScala) { 40 | if(word.formatLong().contains("Verb")) { 41 | verbs = verbs :+ word.getDictionaryItem.lemma 42 | } 43 | } 44 | verbs 45 | } 46 | 47 | override def getVerbs(text: String): Seq[String] = { 48 | info("Verb Service get verbs") 49 | val analyses = getAnalyses(text) 50 | val verbs = analyses.flatMap(analysis => handleAnalyses(analysis)) 51 | verbs 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/ChainScoresServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.summarizer.domain.{Chain, Lexical} 4 | import org.scalatest.FlatSpec 5 | import org.scalatest.Matchers._ 6 | 7 | class ChainScoresServiceTest extends FlatSpec { 8 | 9 | val lexical1 = new Lexical("araba",1,1) 10 | val lexical2 = new Lexical("otobüs",1,2) 11 | val lexical3 = new Lexical("uçak",1,3) 12 | val lexical4 = new Lexical("araba",1,4) 13 | val lexical5 = new Lexical("otobüs",1,5) 14 | val members = List((lexical1,"hypernymy","taşıt"), 15 | (lexical2,"hypernymy","taşıt"), 16 | (lexical3,"hypernymy","taşıt"), 17 | (lexical4,"hypernymy","taşıt"), 18 | (lexical5,"hypernymy","taşıt")) 19 | val chain = Chain(members = members) 20 | 21 | val chainScoresService = new DefaultChainScoresService 22 | 23 | /* 24 | hypernymy = 4 points 25 | 3 words have hypernymy relation = 3 * 4 = 12 26 | */ 27 | it should "calculate Chain Scores correctly" in { 28 | val result = chainScoresService.calculateChainScores(Seq(chain)) 29 | val expectedResult = 20 30 | result.head.score shouldBe expectedResult 31 | } 32 | 33 | it should "calculate Chain Strength correctly" in { 34 | val result = chainScoresService.calculateChainStrengths(Seq(chain)) 35 | val expectedResult = 2.0 36 | result.head.strength shouldBe expectedResult 37 | } 38 | 39 | 40 | it should "get strong chain correctly" in { 41 | val lexical4 = new Lexical("derviş",1,1) 42 | val lexical5 = new Lexical("denetçi",1,2) 43 | val lexical6 = new Lexical("insan",1,3) 44 | val members2 = List((lexical4,"hypernymy","kişi"), 45 | (lexical5,"hypernymy","kişi"), 46 | (lexical6,"synonymy","kişi")) 47 | 48 | val chain1 = Chain(score = 20, strength =2.0, members = members) 49 | val chain2 = Chain(score = 18, members = members2) 50 | 51 | val result = chainScoresService.getStrongChains(Seq(chain1,chain2)) 52 | result.head shouldBe chain1 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/resources/lexical/stopwords.csv: -------------------------------------------------------------------------------- 1 | acaba 2 | altı 3 | altmış 4 | ama 5 | ancak 6 | arada 7 | arasında 8 | artık 9 | aslında 10 | ayrıca 11 | bana 12 | bazen 13 | bazı 14 | belki 15 | benden 16 | beş 17 | bile 18 | bin 19 | bir 20 | biraz 21 | birçok 22 | biri 23 | birkaç 24 | birkez 25 | birşey 26 | birşeyi 27 | biz 28 | bizim 29 | bizler 30 | böyle 31 | böylece 32 | bu 33 | buna 34 | bunda 35 | bundan 36 | bunlar 37 | bunları 38 | bunların 39 | bunu 40 | bunun 41 | burada 42 | buradan 43 | bütün 44 | çok 45 | çünkü 46 | da 47 | daha 48 | dahi 49 | dedi 50 | defa 51 | değil 52 | dek 53 | diğer 54 | dir 55 | diye 56 | doksan 57 | dokuz 58 | dolayı 59 | dolayısıyla 60 | dört 61 | düz 62 | eğer 63 | elbette 64 | elli 65 | en 66 | etmesi 67 | gibi 68 | göre 69 | halen 70 | hangi 71 | hatta 72 | hem 73 | hemen 74 | henüz 75 | hep 76 | hepsi 77 | her 78 | herhangi 79 | herkesin 80 | hiç 81 | hiçbir 82 | için 83 | iki 84 | ile 85 | ilgili 86 | ilk 87 | ise 88 | işte 89 | istifade 90 | itibaren 91 | itibariyle 92 | kadar 93 | karşın 94 | katrilyon 95 | kez 96 | ki 97 | kim 98 | kimden 99 | kime 100 | kimi 101 | kimse 102 | kırk 103 | lakin 104 | milyar 105 | milyon 106 | mı 107 | mu 108 | mü 109 | ne 110 | nihayet 111 | niye 112 | o 113 | of 114 | olan 115 | oldu 116 | olduğu 117 | olmadı 118 | olmaz 119 | olsun 120 | olur 121 | on 122 | ona 123 | ondan 124 | onlar 125 | onlardan 126 | onların 127 | onsuzda 128 | onu 129 | onun 130 | oradan 131 | otuz 132 | öyle 133 | oysa 134 | öz 135 | özü 136 | pek 137 | rağmen 138 | sadece 139 | sana 140 | sanki 141 | sekiz 142 | seksen 143 | sen 144 | senin 145 | şey 146 | şeyden 147 | şeyi 148 | şeyler 149 | siz 150 | sizin 151 | sizler 152 | sonra 153 | şöyle 154 | şu 155 | şuna 156 | şunda 157 | şundan 158 | şunları 159 | şunu 160 | tarafından 161 | teessüf 162 | trilyon 163 | tüm 164 | üç 165 | üzere 166 | var 167 | vardı 168 | ve 169 | veya 170 | ya 171 | yalnız 172 | yani 173 | yedi 174 | yerine 175 | yetmiş 176 | yine 177 | yirmi 178 | yoksa 179 | yüz 180 | yüzbin 181 | zaman 182 | zaten 183 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/NounService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Inject, Singleton} 4 | import zemberek.morphology.analysis.{SentenceAnalysis, SingleAnalysis} 5 | 6 | import scala.collection.JavaConverters._ 7 | import com.summarizer.modules.TurkishParserModule 8 | import com.twitter.inject.Logging 9 | 10 | @ImplementedBy(classOf[DefaultNounService]) 11 | trait NounService { 12 | 13 | def getAnalyses(text: String): Seq[SentenceAnalysis] 14 | 15 | def handleAnalyses(analysis: SentenceAnalysis) : Seq[String] 16 | 17 | def getNouns(text: String): Seq[String] 18 | 19 | def getNounsForSummary(text: String): Seq[String] 20 | 21 | } 22 | 23 | @Singleton 24 | class DefaultNounService @Inject() (sentenceService: SentenceService, 25 | paragraphService: ParagraphService) extends NounService with Logging { 26 | 27 | private val turkishMorphology = TurkishParserModule.getMorphology 28 | 29 | override def getAnalyses(text: String): Seq[SentenceAnalysis] = { 30 | val paragraphs = paragraphService.getParagraphs(text) 31 | val sentences = paragraphs.flatMap(paragraph => sentenceService.getSentences(paragraph)) 32 | val analyses : Seq[SentenceAnalysis] = sentences.map { sentence => 33 | turkishMorphology.analyzeAndDisambiguate(sentence) 34 | } 35 | analyses 36 | } 37 | 38 | override def handleAnalyses(analysis: SentenceAnalysis): Seq[String] = { 39 | var nouns : Seq[String] = Seq.empty[String] 40 | for(word : SingleAnalysis <- analysis.bestAnalysis().asScala) { 41 | if(word.formatLong().contains("Noun")) { 42 | nouns = nouns :+ word.getStem 43 | } 44 | } 45 | nouns 46 | } 47 | 48 | override def getNouns(text: String): Seq[String] = { 49 | val analyses = getAnalyses(text) 50 | val nouns = analyses.flatMap(analysis => handleAnalyses(analysis)) 51 | nouns 52 | } 53 | 54 | override def getNounsForSummary(text: String): Seq[String] = { 55 | val wordAnalysis = turkishMorphology.analyzeAndDisambiguate(text) 56 | val nouns = handleAnalyses(wordAnalysis) 57 | nouns 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/domain/Chain.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.domain 2 | 3 | case class Chain (var subjectOfChain : Option[String] = None, 4 | var score : Int = 0, 5 | var strength : Double = 0.0, 6 | var members : List[(Lexical, String, String)]) { //lexical, relationType, relatedWord 7 | 8 | def addLexicalToChain(lexical: Lexical, relationType: String, relatedWord: String) = { 9 | this.members = this.members :+ (lexical, relationType, relatedWord) 10 | } 11 | 12 | def getWordsOfChain: Seq[String] = { 13 | val words = this.members.map(_._1.getWord()) 14 | words 15 | } 16 | 17 | def getRelationTypesOfChain: Seq[String] = { 18 | this.members.map(_._2) 19 | } 20 | 21 | def getRelatedWordsOfChain: Seq[String] = { 22 | this.members.map(_._3) 23 | } 24 | 25 | def getMember(lexical: Lexical): Option[(Lexical, String, String)] = { 26 | this.members.find(_._1.getWord() == lexical.getWord()) 27 | } 28 | 29 | def getMembers: List[(Lexical, String, String)] = { 30 | this.members 31 | } 32 | 33 | def getParagraphsOfChain: Seq[Int] = { 34 | val paragraphs = this.members.map(_._1).map(_.getParagraphNo()) 35 | paragraphs 36 | } 37 | 38 | def getSentencesOfChain(paragraphNo: Int): Seq[Int] = { 39 | val sentences = this.members.map(_._1).filter(_.getParagraphNo() == paragraphNo).map(_.getSentenceNo()) 40 | sentences 41 | } 42 | 43 | def printChain() = { 44 | for((lexical, relationType, relatedWord) <- this.members) { 45 | println(lexical.getWord()) 46 | println(relationType) 47 | println(relatedWord) 48 | } 49 | 50 | println("Lexical size: " + this.members.size) 51 | println("Score: " + this.score) 52 | println("Strength: " + this.strength) 53 | 54 | } 55 | 56 | def getChainInformation: String = { 57 | var chain = "" 58 | 59 | for((lexical, relationType, relatedWord) <- this.members) { 60 | chain += "(" + lexical.getWord() + " " 61 | chain += relationType + " " 62 | chain += relatedWord + ") " 63 | chain += "P" + lexical.getParagraphNo() + "-S" + lexical.getSentenceNo() + "," 64 | } 65 | 66 | chain += ":" + this.members.size 67 | chain += ":" + this.score 68 | chain += ":" + this.strength + "\n" 69 | chain 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ${log.service.output} 10 | 11 | service-%d{yyyy-MM-dd}.%i 12 | 14 | 50MB 15 | 16 | 17 | 18 | %date %.-3level %-16X{traceId} %-25logger{0} %msg%n 19 | 20 | 21 | 22 | 23 | 24 | ${log.access.output} 25 | 26 | access-%d{yyyy-MM-dd}.%i 27 | 29 | 50MB 30 | 31 | 32 | 33 | %msg %X{traceId}%n 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/controllers/SummaryController.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.controllers 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper 4 | import com.fasterxml.jackson.module.scala.DefaultScalaModule 5 | import com.summarizer.domain.http.{SummaryPostRequest, SummaryPostResponse} 6 | import com.summarizer.services.{NounService, SummaryService, VerbService} 7 | import com.summarizer.swagger.SummarySwaggerDocument 8 | import com.github.xiaodongw.swagger.finatra.SwaggerSupport 9 | import com.google.inject.{Inject, Singleton} 10 | import com.twitter.finagle.http.Request 11 | import com.twitter.finatra.http.Controller 12 | import com.twitter.inject.Logging 13 | 14 | @Singleton 15 | class SummaryController @Inject()(summaryService: SummaryService, 16 | nounService: NounService, 17 | verbService: VerbService) extends Controller with SwaggerSupport with Logging { 18 | implicit protected val swagger = SummarySwaggerDocument 19 | 20 | val mapper = new ObjectMapper() 21 | mapper.registerModule(DefaultScalaModule) 22 | 23 | post("/ozetle/api/new", swagger { 24 | _.summary("Create new summary") 25 | .tag("Summary") 26 | .bodyParam[SummaryPostRequest]("Summary object") 27 | .responseWith[SummaryPostResponse](200, "summary created") 28 | }) { post: Request => 29 | info("summary post") 30 | val summaryPostRequest = mapper.readValue(post.getContentString(), classOf[SummaryPostRequest]) 31 | summaryService.create(summaryPostRequest.toDomain).map { 32 | case Right(summary) => 33 | info("summary created") 34 | SummaryPostResponse(summary.summaryOfText) 35 | case Left(error) => response.ok.body("couldn't create summary: " + error) 36 | } 37 | } 38 | 39 | post("/ozetle/api/noun/new", swagger { 40 | _.summary("Get all nouns") 41 | .tag("Nouns") 42 | .bodyParam[SummaryPostRequest]("Summary object") 43 | .responseWith[SummaryPostResponse](200, "summary created") 44 | }) { post: Request => 45 | info("get nouns") 46 | val summaryPostRequest = mapper.readValue(post.getContentString(), classOf[SummaryPostRequest]) 47 | val nouns = nounService.getNouns(summaryPostRequest.toDomain).mkString(",") 48 | info("nouns are ready") 49 | SummaryPostResponse(Some(nouns)) 50 | } 51 | 52 | post("/ozetle/api/verb/new", swagger { 53 | _.summary("Get all verbs") 54 | .tag("Verbs") 55 | .bodyParam[SummaryPostRequest]("Summary object") 56 | .responseWith[SummaryPostResponse](200, "summary created") 57 | }) { post: Request => 58 | info("get verbs") 59 | val summaryPostRequest = mapper.readValue(post.getContentString(), classOf[SummaryPostRequest]) 60 | val verbs = verbService.getVerbs(summaryPostRequest.toDomain).mkString(",") 61 | info("verbs are ready") 62 | SummaryPostResponse(Some(verbs)) 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/LexicalChainService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Singleton} 4 | import com.summarizer.domain.{Chain, Lexical} 5 | import com.twitter.inject.Logging 6 | import com.summarizer.modules.TurkishLanguageToolsModule 7 | 8 | import scala.collection.mutable.Buffer 9 | 10 | @ImplementedBy(classOf[DefaultLexicalChainService]) 11 | trait LexicalChainService extends Logging { 12 | 13 | def chainAnalyse(chains: Seq[Chain]) : Seq[Chain] 14 | 15 | def buildChains(lexicals: Seq[Lexical]): Seq[Chain] 16 | } 17 | 18 | @Singleton 19 | class DefaultLexicalChainService extends LexicalChainService with Logging { 20 | 21 | /* 22 | * burada chain analiz edilecek ve içindekilere bakılcak mesela aynı kelimeye 23 | * ait ve hep aynı kelimeden oluşan birden fazla zincir olmaması gerek çünkü 24 | * farklı synonymler olduğu için aynı kelimenin birden fazla zinciri 25 | * olabiliyor hepsinin de boyutu aynı oluyor 26 | */ 27 | 28 | def chainAnalyse(chains: Seq[Chain]) : Seq[Chain] = { 29 | info("Lexical Chain Service analyze chains") 30 | val uniqueChains = collection.mutable.Map.empty[String, Chain] 31 | chains.foreach { chain => 32 | uniqueChains += (chain.getWordsOfChain.toString() -> chain) 33 | } 34 | 35 | uniqueChains.values.toSeq 36 | } 37 | 38 | /* tum lexicaller birer birer isleme alinacak 39 | * zincirimiz bos ise -> kelimemizi semantik iliski listesinde sorgulayarak, tum iliskilerini aliyoruz 40 | * ve zincirimize ekliyoruz 41 | * zincirimiz bos degil ise -> her bir zinciri inceliyoruz 42 | * zincirde ayni kelime var mi sorguluyoruz -> varsa zincire ayni iliski tipi ve iliskilenen sözcukle ekliyoruz 43 | * eger yoksa -> kelimemizi semantik iliski listesinde sorgulayarak, tum iliskilerini aliyoruz 44 | * mevcut zincir + tum iliskiler icin bir zincir olusturuyoruz 45 | */ 46 | def buildChains(lexicals: Seq[Lexical]): Seq[Chain] = { 47 | info("Lexical Chain Service build chains") 48 | var mapOfChains = scala.collection.mutable.Map[String, Chain]() 49 | val wordnet = TurkishLanguageToolsModule.getSemanticRelationWordList 50 | lexicals.foreach { lexical => 51 | wordnet.get(lexical.getWord()) match { 52 | case Some(semanticRelations) => { 53 | for (semanticRelation <- semanticRelations) { 54 | val result = semanticRelation.split(":") 55 | val relationType = result(1) 56 | val relatedWord = result(2) 57 | mapOfChains.get(relatedWord) match { 58 | case Some(chain) => chain.addLexicalToChain(lexical, relationType, relatedWord) 59 | case None => mapOfChains(relatedWord) = Chain(None, 0, 0.0, List((lexical, relationType, relatedWord))) 60 | } 61 | } 62 | } 63 | case None => 64 | } 65 | } 66 | mapOfChains.values.toSeq 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/SummaryService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import java.io.{PrintWriter, StringWriter} 4 | 5 | import com.summarizer.domain.Summary 6 | import com.google.inject.{ImplementedBy, Inject, Singleton} 7 | import com.twitter.util.Future 8 | import com.twitter.inject.Logging 9 | 10 | @ImplementedBy(classOf[DefaultSummaryService]) 11 | trait SummaryService { 12 | def create(contextOfText: String): Future[Either[String, Summary]] 13 | } 14 | 15 | @Singleton 16 | class DefaultSummaryService @Inject()(preProcessService: PreProcessService, 17 | nounService: NounService, 18 | lexicalChainService: LexicalChainService, 19 | chainScoresService: ChainScoresService, 20 | extractSentenceService: ExtractSentenceService, 21 | sentenceService: SentenceService) extends SummaryService with Logging { 22 | 23 | override def create(contextOfText: String): Future[Either[String, Summary]] = { 24 | info("Summary service create") 25 | Future { 26 | try { 27 | val start = System.currentTimeMillis() 28 | val paragraphsAndSentencesWithoutHelperWords = preProcessService.paragraphsAndSentencesWithoutHelperWords(contextOfText) 29 | val paragraphsAndSentences = preProcessService.parseTextToSentencesAndParagraphs(contextOfText) 30 | val lexicals = preProcessService.getAllLexicals(paragraphsAndSentences) 31 | val chains = lexicalChainService.buildChains(lexicals) 32 | if (chains.isEmpty) { 33 | Left("Summarizer can't create summary!") 34 | } else { 35 | val uniqueChains = lexicalChainService.chainAnalyse(chains) 36 | val chainsWithScores = chainScoresService.calculateChainScores(uniqueChains) 37 | val chainsWithStrengths = chainScoresService.calculateChainStrengths(chainsWithScores) 38 | val strongChains = chainScoresService.getStrongChains(chainsWithStrengths) 39 | val extractedSentences = extractSentenceService.heuristic2(strongChains, paragraphsAndSentences, paragraphsAndSentencesWithoutHelperWords) 40 | val summaryOfText = extractedSentences.mkString(" ") 41 | val summary = Summary(contextOfText = contextOfText, 42 | summaryOfText = Some(summaryOfText), 43 | wordChain = None) 44 | info(s"contextOfText = $contextOfText") 45 | info(s"summaryOfText = $summaryOfText") 46 | val end = System.currentTimeMillis() 47 | println(end - start) 48 | Right(summary) 49 | } 50 | } 51 | catch { 52 | case t: Throwable => 53 | val errorMessage = t.getMessage 54 | info(s"error: = $errorMessage") 55 | info(getStackTraceAsString(t)) 56 | Left(errorMessage) 57 | } 58 | } 59 | } 60 | 61 | private def getStackTraceAsString(t: Throwable) = { 62 | val sw = new StringWriter 63 | t.printStackTrace(new PrintWriter(sw)) 64 | sw.toString 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/PreProcessService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Inject, Singleton} 4 | import com.summarizer.domain.Lexical 5 | import com.summarizer.modules.TurkishLanguageToolsModule 6 | import com.twitter.inject.Logging 7 | 8 | @ImplementedBy(classOf[DefaultPreProcessService]) 9 | trait PreProcessService { 10 | 11 | def cleanStopWords(text: String): String 12 | 13 | def cleanHelperWords(text: String): String 14 | 15 | def getAllLexicals(paragraphsAndSentences: Map[Int, Seq[String]]): Seq[Lexical] 16 | 17 | def parseTextToSentencesAndParagraphs(text: String) : Map[Int,Seq[String]] 18 | 19 | def paragraphsAndSentencesWithoutHelperWords(text: String): Map[Int, Seq[String]] 20 | 21 | } 22 | 23 | @Singleton 24 | class DefaultPreProcessService @Inject()(nounService: NounService, 25 | sentenceService: SentenceService, 26 | paragraphService: ParagraphService) extends PreProcessService with Logging { 27 | 28 | def cleanStopWords(text: String): String = { 29 | info("Pre Process Service clean stop words") 30 | val stopWords = TurkishLanguageToolsModule.getStopWordList 31 | stopWords.foldLeft(text)((a, b) => a.replaceAllLiterally(" " + b + " ", " ")).toString 32 | } 33 | 34 | def cleanHelperWords(text: String): String = { 35 | info("Pre Process Service clean helper words") 36 | val helperWords = TurkishLanguageToolsModule.getHelperWordList 37 | helperWords.foldLeft(text)((a, b) => a.replaceAllLiterally(" " + b + " ", " ")).toString 38 | } 39 | 40 | def getAllLexicals(paragraphsAndSentences: Map[Int, Seq[String]]): Seq[Lexical] = { 41 | info("Pre Process Service get paragraphs and sentences") 42 | val lexicals = paragraphsAndSentences.flatMap { case (paragraphNo, sentences) => 43 | sentences.zipWithIndex.flatMap { case (sentence, sentenceIndexNo) => 44 | val words = nounService.getNounsForSummary(sentence) 45 | words.map(new Lexical(_, sentenceIndexNo, paragraphNo)) 46 | } 47 | } 48 | lexicals.toSeq 49 | } 50 | 51 | def parseTextToSentencesAndParagraphs(text: String): Map[Int, Seq[String]] = { 52 | info("Pre Process Service parse text to paragraphs and sentences") 53 | val textWithoutStopWords = cleanStopWords(text) 54 | var paragraphsAndSentences = Map.empty[Int, Seq[String]] 55 | val paragraphs = paragraphService.getParagraphs(textWithoutStopWords) 56 | paragraphs.zipWithIndex.foreach { case (paragraph, paragraphIndexNo) => 57 | val sentences = sentenceService.getSentences(paragraph) 58 | paragraphsAndSentences += (paragraphIndexNo -> sentences) 59 | } 60 | paragraphsAndSentences 61 | } 62 | 63 | def paragraphsAndSentencesWithoutHelperWords(text: String): Map[Int, Seq[String]] = { 64 | info("Pre Process Service parse text to paragraphs and sentences") 65 | val textWithoutHelperWords = cleanHelperWords(text) 66 | var paragraphsAndSentences = Map.empty[Int, Seq[String]] 67 | val paragraphs = paragraphService.getParagraphs(textWithoutHelperWords) 68 | paragraphs.zipWithIndex.foreach { case (paragraph, paragraphIndexNo) => 69 | val sentences = sentenceService.getSentences(paragraph) 70 | paragraphsAndSentences += (paragraphIndexNo -> sentences) 71 | } 72 | paragraphsAndSentences 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/SemanticListParserServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import org.scalatest.FunSpec 4 | import org.scalatest.Matchers._ 5 | 6 | class SemanticListParserServiceTest extends FunSpec { 7 | describe("Parse Semantic List") { 8 | val semanticListParserService = new DefaultSemanticListParserService 9 | val relationList = Seq( "abacı:hypernymy:kişi", 10 | "abacı:hypernymy:köy", 11 | "abacı:synonymy:asalak", 12 | "abacılık:hypernymy:iş", 13 | "abacılık:synonymy:keçecilik", 14 | "abadan:hypernymy:köy", 15 | "abadan:hypernymy:şehir", 16 | "abadan:synonymy:bağışlayıcı", 17 | "abajur:hypernymy:kâğıt", 18 | "abajur:synonymy:lamba", 19 | "abak:hypernymy:köy", 20 | "abak:synonymy:iffetli", 21 | "abak:synonymy:temiz", 22 | "abakan:synonymy:alicenap", 23 | "abakan:synonymy:cömert", 24 | "abaküs:related_with:matematik", 25 | "abaküs:synonymy:çörkü", 26 | "abaküs:synonymy:sayı boncuğu", 27 | "abaküs:yan_kavram:hesap makinesi", 28 | "abalı:synonymy:güçsüz", 29 | "abalı:synonymy:kimsesiz") 30 | 31 | it("should create set of words") { 32 | val result = semanticListParserService.createWordList(relationList) 33 | val expectedResult = Seq( "abacı", 34 | "abacılık", 35 | "abadan", 36 | "abajur", 37 | "abak", 38 | "abakan", 39 | "abaküs", 40 | "abalı") 41 | 42 | result shouldBe expectedResult 43 | } 44 | 45 | it("should create map of words with their relations") { 46 | val words = semanticListParserService.createWordList(relationList) 47 | val result = semanticListParserService.createRelationList(words, relationList) 48 | val expectedResult = Map( "abajur" -> Seq("abajur:hypernymy:kâğıt", "abajur:synonymy:lamba"), 49 | "abacı" -> Seq("abacı:hypernymy:kişi", "abacı:hypernymy:köy", "abacı:synonymy:asalak"), 50 | "abaküs" -> Seq("abaküs:related_with:matematik", "abaküs:synonymy:çörkü", "abaküs:synonymy:sayı boncuğu", "abaküs:yan_kavram:hesap makinesi"), 51 | "abak" -> Seq("abak:hypernymy:köy", "abak:synonymy:iffetli", "abak:synonymy:temiz"), 52 | "abakan" -> Seq("abakan:synonymy:alicenap", "abakan:synonymy:cömert"), 53 | "abacılık" -> Seq("abacılık:hypernymy:iş", "abacılık:synonymy:keçecilik"), 54 | "abadan" -> Seq("abadan:hypernymy:köy", "abadan:hypernymy:şehir", "abadan:synonymy:bağışlayıcı"), 55 | "abalı" -> Seq("abalı:synonymy:güçsüz", "abalı:synonymy:kimsesiz") 56 | ) 57 | 58 | result shouldBe expectedResult 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/ChainScoresService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Singleton} 4 | import com.summarizer.domain.Chain 5 | import com.twitter.inject.Logging 6 | 7 | @ImplementedBy(classOf[DefaultChainScoresService]) 8 | trait ChainScoresService extends Logging { 9 | 10 | def calculateChainScores(chains: Seq[Chain]): Seq[Chain] 11 | 12 | def calculateChainStrengths(chains: Seq[Chain]): Seq[Chain] 13 | 14 | def getStrongChains(chains: Seq[Chain]): Seq[Chain] 15 | 16 | } 17 | 18 | @Singleton 19 | class DefaultChainScoresService extends ChainScoresService with Logging { 20 | /* 21 | We define the score of an interpretation as the sum of its chain scores. 22 | A chain score is determined by the number and weight of the relations 23 | between chain members. Experimentally, we fixed the weight of reiteration 24 | = 10 synonymy = 10 antonymy = 7 hypernymy = 4 hyponymy = 4 related_with = 4 holo_part = 4 holo_member = 4 yan_kavram = 4 25 | */ 26 | 27 | def calculateChainScores(chains: Seq[Chain]): Seq[Chain] = { 28 | info("Chain Scores Service calculate Chain Scores") 29 | var sumScore = 0 30 | val chainsWithScores = chains.map { chain => 31 | val relations = chain.members.map(_._2) 32 | for(relation <- relations) { 33 | if (relation.equals("synonymy")) { 34 | sumScore += 10 35 | } else if (relation.equals("antonymy")) { 36 | sumScore += 7 37 | } else if (relation.equals("hypernymy") || relation.equals("hyponymy") 38 | || relation.equals("related_with") || relation.equals("holo_part") 39 | || relation.equals("holo_member") || relation.equals("yan_kavram") 40 | || relation.equals("holo_portion")) { 41 | sumScore += 4 42 | } 43 | } 44 | chain.score = sumScore 45 | sumScore = 0 46 | chain 47 | } 48 | chainsWithScores 49 | } 50 | 51 | /* 52 | * 53 | * 1. Compute the aggregate score of each chain by summing the scores of 54 | * each individual element in the chain. 2. Pick up the chains whose score 55 | * is more than the mean of the scores for every chain computed in the 56 | * document. 3. For each of the strong chains, identify representative 57 | * words, whose contribution to the chain is maximum 4. Choose the sentence 58 | * that contains the first appearance of a representative chain member in 59 | * the text. 60 | */ 61 | 62 | def calculateChainStrengths(chains: Seq[Chain]): Seq[Chain] = { 63 | info("Chain Scores Service calculate Chain Strengths") 64 | val chainsWithStrengths = chains.map { chain => 65 | val lexicals = chain.members.map(_._1) 66 | val uniqueLexicals = lexicals.map(_.getWord()).distinct 67 | val homogenity = 1.0 - (uniqueLexicals.size.toDouble / lexicals.size.toDouble) 68 | val strength = lexicals.size.toDouble * homogenity 69 | chain.strength = strength 70 | chain 71 | } 72 | chainsWithStrengths 73 | } 74 | 75 | /* 76 | * ortalama puanın üstündekileri al ortalama strength üstündekileri al 77 | * “Strength Criterion”: Score(Chain) > Average(Scores) + 2 ∗ 78 | * StandardDeviation(Scores) 79 | */ 80 | 81 | def getStrongChains(chains: Seq[Chain]): Seq[Chain] = { 82 | info("Chain Scores Service get Strong Chains") 83 | val sumScoreOfChain = chains.foldLeft(0.0)(_ + _.score) 84 | val sumStrengthOfChain = chains.foldLeft(0.0)(_ + _.strength) 85 | val averageScoreOfChain = sumScoreOfChain / chains.size.toDouble 86 | val averageStrengthOfChain = sumStrengthOfChain / chains.size.toDouble 87 | 88 | info(f"Kelime zinciri ortalama puan değeri = $averageScoreOfChain") 89 | info(f"Kelime zinciri ortalama güç değeri = $averageStrengthOfChain") 90 | var temp = 0.0 91 | chains.foreach { chain => 92 | temp = temp + (averageStrengthOfChain - chain.strength) * (averageStrengthOfChain - chain.strength) 93 | } 94 | val variance = temp / chains.size.toDouble 95 | val stddev = Math.sqrt(variance) 96 | val criterion = averageStrengthOfChain + 2.0 * stddev 97 | info(f"Kelime zinciri kriter değeri = $criterion") 98 | 99 | val strongChains = chains.filter(chain => chain.strength >= criterion) 100 | if(strongChains.isEmpty) { 101 | info("Kriter degerinin ustunde zincir bulunamadi, en guclu zincir alincak!") 102 | Seq(chains.maxBy(chain => chain.strength)) 103 | } else { 104 | strongChains 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/PreProcessServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import org.scalatest.FunSpec 4 | import org.scalatest.Matchers._ 5 | 6 | class PreProcessServiceTest extends FunSpec with CommonServices { 7 | describe("Pre process text") { 8 | 9 | val paragraph1 = "Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.\n\n" 10 | val paragraph2 = "Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği ve 18 yaşının altındaki voleybolcuların katılabildiği bir şampiyonadır. İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir." 11 | 12 | describe("cleanStopWords") { 13 | it("should remove stop words") { 14 | val cleanText = preProcessService.cleanStopWords(paragraph2) 15 | val expected = "Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği 18 yaşının altındaki voleybolcuların katılabildiği şampiyonadır. İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her yılda düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir." 16 | 17 | cleanText shouldBe expected 18 | } 19 | } 20 | 21 | describe("cleanHelperWords") { 22 | it("should remove helper words") { 23 | val cleanText = preProcessService.cleanHelperWords(paragraph1) 24 | val expected = "Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.\n\n" 25 | 26 | cleanText shouldBe expected 27 | } 28 | } 29 | 30 | describe("getAllLexicals") { 31 | it("should generate all lexicals") { 32 | val sentences = Seq("Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu.", 33 | "Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.") 34 | val paragraphsAndSentences = Map(0 -> sentences) 35 | val allLexicals = preProcessService.getAllLexicals(paragraphsAndSentences) 36 | val expectedLexicals = Seq("dünya", "yıldız", "kız", "voleybol", "şampiyona", "yıldız", "takım", "final", "maç", "çin", "şampiyon", "türkiye", "voleybol", "tarih", "dünya", "şampiyon", "el", "şampiyona", "yıl", "brezilya", "curitiba", "kent", "yıl", "şampiyona", "kıta", "ele", "ülke", "takım") 37 | 38 | allLexicals.size shouldBe 17 39 | allLexicals.zipWithIndex.foreach { case (lexical, lexicalIndexNo) => 40 | lexical.getWord() shouldBe expectedLexicals(lexicalIndexNo) 41 | } 42 | } 43 | } 44 | 45 | describe("parseTextToSentencesAndParagraphs") { 46 | it("should parse text to sentences and paragraphs") { 47 | val sentencesFirstParagraph = Seq("Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu.", 48 | "Türkiye, voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.") 49 | val sentencesSecondParagraph = Seq("Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği 18 yaşının altındaki voleybolcuların katılabildiği şampiyonadır.", 50 | "İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır.", "Her yılda düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir.") 51 | val paragraphsAndSentences = preProcessService.parseTextToSentencesAndParagraphs(paragraph1.concat(paragraph2)) 52 | val expected = Map(0 -> sentencesFirstParagraph, 1 -> sentencesSecondParagraph) 53 | 54 | paragraphsAndSentences shouldBe expected 55 | } 56 | } 57 | 58 | describe("paragraphsAndSentencesWithoutHelperWords") { 59 | it("should clean helper words and create paragraphs and sentences") { 60 | val sentencesFirstParagraph = Seq("Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu.", 61 | "Türkiye, voleybol tarihinin ilk Dünya şampiyonluğunu elde etti.") 62 | val sentencesSecondParagraph = Seq("Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği ve 18 yaşının altındaki voleybolcuların katılabildiği bir şampiyonadır.", 63 | "İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır.", "Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir.") 64 | val result = preProcessService.paragraphsAndSentencesWithoutHelperWords(paragraph1.concat(paragraph2)) 65 | val expected = Map(0 -> sentencesFirstParagraph, 1 -> sentencesSecondParagraph) 66 | 67 | result shouldBe expected 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/scala/com/summarizer/services/ExtractSentenceServiceTest.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.summarizer.domain.{Chain, Lexical} 4 | import org.scalatest.FunSpec 5 | import org.scalatest.Matchers._ 6 | 7 | class ExtractSentenceServiceTest extends FunSpec { 8 | private val extractSentenceService = new DefaultExtractSentenceService 9 | 10 | describe("Heuristic Algorithm 1") { 11 | // her zincirdeki ilk kelimenin geçtiği cümleyi al 12 | it("should return correct sentences") { 13 | val lexical1 = new Lexical("araba",0,0) 14 | val lexical2 = new Lexical("otobus",1,0) 15 | val lexical3 = new Lexical("araba",2,0) 16 | val members = List((lexical1,"hypernymy","taşıt"), 17 | (lexical2,"hypernymy","taşıt"), 18 | (lexical3,"hypernymy","taşıt")) 19 | val chain = Chain(members = members) 20 | 21 | val lexical4 = new Lexical("çay",3,1) 22 | val lexical5 = new Lexical("kahve",4,1) 23 | val lexical6 = new Lexical("su",5,1) 24 | val members2 = List((lexical4,"hypernymy","içecek"), 25 | (lexical5,"hypernymy","içecek"), 26 | (lexical6,"hypernymy","içecek")) 27 | val secondChain = Chain(members = members2) 28 | 29 | val sentences = Seq("Bazı insanlar kendi arabalarıyla yolculuk etmeyi sever.", 30 | "Bazı insanlarsa otobüsle yolculuktan hoşlanır.", 31 | "Arabayla yolculuk etmek insanlar için daha konforlu olabilir.", 32 | "Çay, bir çok kişinin en vazgeçilmezidir.", 33 | "Kahve işe yeni yeni alışkanlık haline gelmektedir.", 34 | "Cay ve kahve, su yerine gecmez.") 35 | 36 | val result = extractSentenceService.heuristic1(Seq(chain,secondChain),sentences) 37 | val expectedResult = Seq("Bazı insanlar kendi arabalarıyla yolculuk etmeyi sever.", 38 | "Çay, bir çok kişinin en vazgeçilmezidir.") 39 | 40 | result shouldBe expectedResult 41 | } 42 | 43 | } 44 | 45 | describe("Heuristic Algorithm 2") { 46 | it("should return correct sentences") { 47 | val lexical1 = new Lexical("metin", 0, 0) 48 | val lexical2 = new Lexical("metin", 3, 0) 49 | val lexical3 = new Lexical("metin", 0, 1) 50 | val lexical4 = new Lexical("metin", 0, 1) 51 | val lexical5 = new Lexical("metin", 0, 1) 52 | val lexical6 = new Lexical("metin", 2, 1) 53 | val members = List((lexical1, "holo_part", "okunacak şey"), (lexical2, "holo_part", "okunacak şey"), (lexical3, "holo_part", "okunacak şey"), 54 | (lexical4, "holo_part", "okunacak şey"), (lexical5, "holo_part", "okunacak şey"), (lexical6, "holo_part", "okunacak şey")) 55 | val chain = Chain(members = members) 56 | val sentencesFirstParagraph = Seq("Otomatik metin özetleme uygulamamız üniversite yıllarında geliştirilmeye başlamış ve TÜBİTAK tarafından ödüllendirilmiştir.", 57 | "Açık kaynak yazılım olarak hala geliştirilmeye devam edilmektedir.", 58 | "Bu yüzden yapacağınız her geri bildirim bizim için çok önem arz ediyor.", 59 | "Uygulamayı kullanmak için internet bağlantınızın olması gerekiyor çünkü metin özetleme işlemi sunucumuzda yapılıyor.", 60 | "Bunun dışında herhangi başka bir gereksinime ihtiyaç duymuyor.") 61 | val sentencesSecondParagraph = Seq("Bu uygulamayla tartışma metinlerinizi, makalelerinizi, bilimsel metinlerinizi, tarih metinlerinizi ve analiz çalışmalarınızı özetlemenize ve analiz etmenize yardımcı olmak istiyoruz.", 62 | "Belgelerinizin önemli fikirlerini tanımlayan ve özetleyen bir eğitim aracıdır.", 63 | "Tek Tıklamayla özetleyin, ana fikre gidin ya da basitleştirin, böylece metinlerinizi hızlı bir şekilde yorumlayabilirsiniz.") 64 | val paragraphsAndSentences = Map(0 -> sentencesFirstParagraph, 1 -> sentencesSecondParagraph) 65 | 66 | val sentencesWithoutHelperWordsFirstParagraph = Seq("Otomatik metin özetleme uygulamamız üniversite yıllarında geliştirilmeye başlamış ve TÜBİTAK ödüllendirilmiştir.", 67 | "Açık kaynak yazılım olarak geliştirilmeye devam edilmektedir.", 68 | "yüzden yapacağınız geri bildirim bizim önem arz ediyor.", 69 | "Uygulamayı kullanmak için internet bağlantınızın olması gerekiyor çünkü metin özetleme işlemi sunucumuzda yapılıyor.", 70 | "Bunun dışında başka bir gereksinime ihtiyaç duymuyor.") 71 | val sentencesWithoutHelperWordsSecondParagraph = Seq("Bu uygulamayla tartışma metinlerinizi, makalelerinizi, bilimsel metinlerinizi, tarih metinlerinizi, analiz çalışmalarınızı özetlemenize ve analiz etmenize yardımcı olmak istiyoruz.", 72 | "Belgelerinizin önemli fikirlerini tanımlayan ve özetleyen bir eğitim aracıdır.", 73 | "Tek Tıklamayla özetleyin, ana fikre gidin ya da basitleştirin, böylece metinlerinizi hızlı bir yorumlayabilirsiniz.") 74 | val paragraphsAndSentencesWithoutHelperWords = Map(0 -> sentencesWithoutHelperWordsFirstParagraph, 1 -> sentencesWithoutHelperWordsSecondParagraph) 75 | 76 | val result = extractSentenceService.heuristic2(Seq(chain), paragraphsAndSentences, paragraphsAndSentencesWithoutHelperWords) 77 | val expectedResult = Seq("Otomatik metin özetleme uygulamamız üniversite yıllarında geliştirilmeye başlamış ve TÜBİTAK ödüllendirilmiştir.", 78 | "Uygulamayı kullanmak için internet bağlantınızın olması gerekiyor çünkü metin özetleme işlemi sunucumuzda yapılıyor.") 79 | 80 | result shouldBe expectedResult 81 | 82 | } 83 | 84 | } 85 | 86 | describe("Heuristic Algorithm 3") { 87 | 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/scala/com/summarizer/services/ExtractSentenceService.scala: -------------------------------------------------------------------------------- 1 | package com.summarizer.services 2 | 3 | import com.google.inject.{ImplementedBy, Singleton} 4 | import com.summarizer.domain.Chain 5 | import com.twitter.inject.Logging 6 | 7 | import scala.collection.immutable.ListMap 8 | import util.control.Breaks._ 9 | 10 | @ImplementedBy(classOf[DefaultExtractSentenceService]) 11 | trait ExtractSentenceService extends Logging { 12 | 13 | def heuristic1(chains: Seq[Chain], sentences: Seq[String]): Seq[String] 14 | 15 | def getFrequencyOfWords(words: Seq[String]): Map[String, Int] 16 | 17 | def heuristic2(chains: Seq[Chain], 18 | paragraphsAndSentences: Map[Int, Seq[String]], 19 | paragraphsAndSentencesWithoutHelperWords: Map[Int, Seq[String]]): Seq[String] 20 | 21 | } 22 | 23 | @Singleton 24 | class DefaultExtractSentenceService extends ExtractSentenceService with Logging { 25 | /* 26 | * 27 | * We investigated three alternatives for this step: For each chain in the 28 | * summary representation choose the sentence that contains the first 29 | * appearance of a chain member in the text. 30 | * 31 | * her zincirdeki ilk kelimenin geçtiği cümleyi al 32 | */ 33 | 34 | def heuristic1(chains: Seq[Chain], sentences: Seq[String]): Seq[String] = { 35 | info("Extract Sentence Service heuristic 1") 36 | var sentencesIndexNo = Seq.empty[Int] 37 | chains.foreach { chain => 38 | val lexicals = chain.members.map(_._1) 39 | val sentenceNo = lexicals.head.getSentenceNo() 40 | if (!sentencesIndexNo.contains(sentenceNo)) { 41 | sentencesIndexNo = sentencesIndexNo :+ sentenceNo 42 | } else { 43 | lexicals.foreach { lexical => 44 | val sentenceNo = lexical.getSentenceNo() 45 | if (!sentencesIndexNo.contains(sentenceNo)) { 46 | sentencesIndexNo = sentencesIndexNo :+ sentenceNo 47 | break 48 | } 49 | } 50 | } 51 | } 52 | sentencesIndexNo = sentencesIndexNo.sorted 53 | val extractedSentences = sentencesIndexNo.map(index => sentences(index)) 54 | extractedSentences 55 | } 56 | 57 | /* 58 | * We therefore defined a criterion to evaluate the appropriateness of a 59 | * chain member to represent its chain based on its frequency of occurrence 60 | * in the chain. We found experimentally that such words, call them 61 | * representative words, have a frequency in the chain noless than the 62 | * average word frequency in the chain. 63 | * 64 | * first check the chains length , 65 | * if we have only one chain then check how many unique words includes the chain, if all lexicals of chain are same, 66 | * then get first two lexicals sentence no and fetch them 67 | * else get the unique words and fetch sentences with their sentence no 68 | * 69 | * if we have more than one chain: 70 | * go to for loop 71 | * check if the chain has same lexicals only, then get one sentence from that chain, which is not selected yet 72 | * if chain has different lexicals then get the frequency of words, use lexicals above frequency for fetching sentences 73 | * 74 | */ 75 | 76 | def getFrequencyOfWords(words: Seq[String]): Map[String, Int] = { 77 | val frequency = words.groupBy(identity).mapValues(_.size) 78 | frequency 79 | } 80 | 81 | def heuristic2(chains: Seq[Chain], 82 | paragraphsAndSentences: Map[Int, Seq[String]], 83 | paragraphsAndSentencesWithoutHelperWords: Map[Int, Seq[String]]): Seq[String] = { 84 | info("Extract Sentence Service heuristic algorithm 2") 85 | var selectedSentences = Map.empty[(Int, Int), String] 86 | var representativeWords = Set.empty[String] 87 | 88 | if (chains.length == 1) { 89 | val chain = chains.head 90 | val words = chain.getWordsOfChain 91 | val uniqueWords = words.distinct 92 | if (uniqueWords.size == 1) { 93 | val lexicals = chain.members.map(_._1) 94 | val values = lexicals.map { lexical => 95 | (lexical.getParagraphNo(),lexical.getSentenceNo()) 96 | }.distinct 97 | 98 | val (firstSelectedParagraphNo,firstSelectedSentenceNo) = values.head 99 | val sentences = paragraphsAndSentences(firstSelectedParagraphNo) 100 | selectedSentences += ((firstSelectedParagraphNo,firstSelectedSentenceNo) -> sentences(firstSelectedSentenceNo)) 101 | if (values.size > 1) { 102 | val (secondSelectedParagraphNo,secondSelectedSentenceNo) = values(1) 103 | val sentences = paragraphsAndSentences(secondSelectedParagraphNo) 104 | selectedSentences += ((secondSelectedParagraphNo,secondSelectedSentenceNo) -> sentences(secondSelectedSentenceNo)) 105 | } 106 | } else { 107 | uniqueWords.foreach { word => 108 | val lexicals = chain.members.map(_._1).filter(_.getWord() == word) 109 | var sentenceNotAdded = true 110 | for (lexical <- lexicals; if sentenceNotAdded) { 111 | val (paragraphNo,sentenceNo) = (lexical.getParagraphNo(), lexical.getSentenceNo()) 112 | representativeWords += lexical.getWord() 113 | if (selectedSentences.get((paragraphNo, sentenceNo)).isEmpty) { 114 | val sentences = paragraphsAndSentences(paragraphNo) 115 | selectedSentences += ((paragraphNo,sentenceNo) -> sentences(sentenceNo)) 116 | sentenceNotAdded = false 117 | } 118 | } 119 | } 120 | } 121 | 122 | } else { 123 | for (chain <- chains) { 124 | val words = chain.getWordsOfChain 125 | val uniqueWords = words.distinct 126 | if (uniqueWords.size == 1) { 127 | val lexical = chain.members.map(_._1).head 128 | val (paragraphNo, sentenceNo) = (lexical.getParagraphNo(), lexical.getSentenceNo()) 129 | val sentences = paragraphsAndSentences(paragraphNo) 130 | if (selectedSentences.get((paragraphNo, sentenceNo)).isEmpty) { 131 | selectedSentences += ((paragraphNo, sentenceNo) -> sentences(sentenceNo)) 132 | } 133 | } else { 134 | val frequencyOfWords = getFrequencyOfWords(words) 135 | val meanOfFrequency = words.size.toDouble / uniqueWords.size.toDouble 136 | val wordsAboveMean = frequencyOfWords.filter((word) => word._2.toDouble >= meanOfFrequency).keySet 137 | val lexicals = chain.members.map(_._1).filter(lexical => wordsAboveMean.contains(lexical.getWord())) 138 | var sentenceNotAdded = true 139 | for (lexical <- lexicals; if sentenceNotAdded) { 140 | val (paragraphNo, sentenceNo) = (lexical.getParagraphNo(), lexical.getSentenceNo()) 141 | representativeWords += lexical.getWord() 142 | if (selectedSentences.get((paragraphNo, sentenceNo)).isEmpty) { 143 | val sentences = paragraphsAndSentences(paragraphNo) 144 | selectedSentences += ((paragraphNo, sentenceNo) -> sentences(sentenceNo)) 145 | sentenceNotAdded = false 146 | } 147 | } 148 | } 149 | } 150 | } 151 | val sortedSelectedSentences = ListMap(selectedSentences.toSeq.sortBy(_._1): _*) 152 | val replaceSelectedSenteces = sortedSelectedSentences.map { info => 153 | val sentencesWithoutHelperWords = paragraphsAndSentencesWithoutHelperWords(info._1._1) 154 | val sentence = sentencesWithoutHelperWords(info._1._2) 155 | if (sentence.matches(".*\\p{Punct}")) { 156 | sentence 157 | } else { 158 | sentence + "\n" 159 | } 160 | }.toSeq 161 | replaceSelectedSenteces 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | Kelime Zinciri Algoritmasıyla Türkçe Metin Özetleme - SCALA 2 | =================== 3 | --- 4 | ### NOTLAR 5 | 6 | Uzun bir aradan sonra nihayet fırsat bulup projeye geri dönüş yapabildim. Programın ilk sürümü bitirme projesi olduğu için biraz karışık ve aceleyle yazıldı. Büyüzden tüm projeyi scala dilinde yeniden yazdım. Hem daha anlaşılır hem daha kısa ve öz oldu. Spring MVC, Tomcat ve Postgresql üçlüsünü bırakarak , Finatra + ~~Mongodb~~ ikilisine geçtim. 7 | Şimdi ayrıca docker-compose ile özetleme servisini hızlıca kurabilirsiniz. 8 | 9 | Algorıtma olarak çok bir değişiklik yapmadım, sadece daha önce farketmediğim hataları düzelttim, bu da performansı ve özet kalitesini artırdı. Metnin sınıfını bulma işlemini uygulamadan kaldırdım. İlk sürümde deneme amaçlı eklenmişti, suan kullanılmadığı için gerekli olduğunu düşünmüyorum. 10 | 11 | ### Algoritma 12 | > **Kelime Zinciri Algoritması:** 13 | 14 | Bu algoritma metnin ana konusunu belirmeye çalışmaktadır. Metindeki kelimeler arasında "anlamsal" bağ kurup, aynı anlama gelen kelimelerden bir zincir oluşturulmaktadır [9]. Daha sonra belirlenen puanlama ve sezgisel yöntemlere göre özet niteliği taşıyabilecek cümleleri seçerek belirlemektedir. Bu algoritma için en önemli şey güçlü bir "kelime ağının" var olmasıdır. Çünkü tüm zincirler kelimeler arasındaki ilişkilerden yola çıkarak oluşturulacağı için, güçlü bir kelime ağı belirsiz kalacak kelime sayısını azaltacak, güçlü zincirler kurulmasını sağlayacaktır. Türkçe için hazırlanmış tek kelime ağı Dr. Özlem Çetinoglu ve Dr. Kemal Oflazer tarafından 2004 yılında “BalkaNet” projesiyle oluşturulmuştur [10]. Tarafımızdan geliştirilecek bu proje kapsamında, wordnetin javaya aktarılması ve kullanılabilir hale getirilmesi gerekmekte idi. Öncelikle XML halinde bulunan bu listeyi çözümleyerek (parsing) yeniden oluşturulmuştur. Kullanılacak formata dönüşüm gerçekleştirilmiştir. Daha sonra Yıldız Teknik Üniversitesi Bilgisayar Mühendisliği bölümünden Emre Yıldız'ın oluşturduğu “Anlamsal İlişkiler Veri Kümesi” projesi dökumanları da kullanılacak formata dönüştürülmüştür [11]. Bu iki listeyi birleştirip kendi projemiz için ortak bir kelime ağı oluşturduk. Bu kelime ağı içindeki verileri ön aşamadan geçirdik, bu aşamalar; 15 | >- Etkisiz kelimeler temizlendi. 16 | >- Atasözler ve deyimler çıkartıldı. 17 | >- Hyponymy ilişkiler, hypernymy ilişkilere dönüştürüldü. (Çünkü bu şekilde kelimelerin aranması kolaylaşmaktadır.) 18 | >- Sıfatlar ve fiiller çıkartıldı. 19 | >- Yer belirten adlar düzenlendi. 20 | >- Terim listeleri eklendi. 21 | >- Sayılar çıkartıldı. 22 | 23 | Uygulamamızda tüm bu listeyi okuyup her kelime için bir ilişki listesi oluşturuyoruz, bir kelime girildiğinde bunun ilişkili olduğu kelimeler liste halinde kullanıcıya gönderilmektedir. Bu sistemin ileride ayrı bir servis olarak kullanıma sunulması planlanmaktadır. Böylece çevrimiçi Türkçe kelime ağı erişime açılmış olacaktır. 24 | 25 | > **Zincirlerin puanlanması:** 26 | > 27 | Bu aşamada zincirdeki kelimelerin aralarındaki ilişkiye göre puanlamasını gerçekleştirdik. Regina Barzilay tarafından hazırlanmış olan "Using Lexical Chains for Text Summarization [13]" doktora tezinden ve "Assessing the Impact of Lexical Chain Scoring Methods and Sentence Extraction Schemes on Summarization [14]" makalesinden faydalanılmıştır. Oluşturdukları puanlama sistemi kendi uygulamamıza göre değiştirilmiştir. Aşağıdaki şekilde bir puanlama sistemi oluşturulmuştur: 28 | 29 | >- synonymy = 10 30 | >- antonymy = 7 31 | >- hypernymy = 4 32 | >- hyponymy = 4 33 | >- related_with =4 34 | >- holo_part = 4 35 | >- holo_portion = 4 36 | >- holo_member = 4 37 | >- yan_kavram = 4 38 | 39 | Ayrıca zincirlerin gücünü belirlemek için ayrı bir sistem daha kullanılmıştır. Bu sistem şu 40 | aşamalardan oluşmaktadır: 41 | >- Zincirdeki benzersiz kelimelerin sayısını bul 42 | >- Homojenlik değerini bul = 1 - (benzersiz kelime sayısı / tüm kelimelerin sayısı) 43 | >- Eşik değerini bul = ortalama puan + (2 ∗ puanların standart sapması) 44 | >- Eşik değerinin üstündeki zincirleri güçlü zincirler olarak listeye al 45 | ###### 46 | > **Cümle Seçimi İşlemleri:** 47 | 48 | >- Sezgisel Algoritma 1 49 | Bu algoritma her zincirdeki ilk kelimenin yani zinciri başlatan kelimenin anahtar kelime olarak alınmasına dayanmaktadır. Bu anahtar kelimenin geçtiği ilk cümle tespit edilerek seçilmiştir. 50 | >- Sezgisel Algoritma 2 51 | İlk önce kaç tane güçlü zincir olduğuna bakılır. 52 | Sadece bir tane güçlü zincir varsa, bu zincirdeki tüm kelimelerin aynı olup olmadığına bakılır.Eğer aynıysa, zincirdeki ilk iki kelimenin ait olduğu cümle alınır. Eğer aynı değilse, zincirdeki farklı kelimeler seçilip, onların ait olduğu cümleler alınır. 53 | Birden fazla güçlü zincir varsa, tüm bu zincirler bir döngü içerisine alınır, amacımız her zincir için, o konuyu temsil eden bir cümle seçmek. Bunun için yine zincirde farklı kelimeler var mı diye bakıyoruz, eğer yoksa, zincirdeki ilk iki kelimenin ait olduğu cümle alınır. 54 | Zincirde farkli kelimeler mevcutsa, öncelikle tüm kelimelerin frekansı hesaplanır ve zincirdeki kelimelerin frekans ortalaması bulunur. Ortalama frekansın üstündeki kelimeler işleme alınır. Bu kelimelerin ortak olarak geçtikleri bir cümle mevcut ise bu cümle seçilir, eğer hiçbir kelimenin kesiştiği bir cümle yoksa, en yüksek frekanslı cümlenin geçtiği cümle alınır. 55 | >- Sezgisel Algoritma 3 56 | Bu algoritma her zincirin yoğunlaştığı paragrafı bulmaya ve bu paragrafta zincirdeki 57 | kelimeleri içeren cümle frekansına dayanmaktadır. Eğer tüm kelimeler aynı paragraftaysa doğrudan bu paragraftaki cümlelerin analizi yapılır. Eğer zincirdeki kelimeler farklı paragraflardaysa öncelikle paragrafların frekansları alınır. En yüksek frekanslı paragraf seçilir ve bu paragraftaki cümlelerin analizi yapılır. Cümle analizi, öncelikle zincirdeki kelimelerin hangi cümlelerde geçtiği bilindiği için bu kelimeler paragraflara göre ayıklanır ve her paragraf içinde bu kelimelerin ait oldukları cümlelerin frekansı alınır. En yüksek frekanslı cümleyi o zincir için seçilmektedir. 58 | 59 | ------ 60 | 61 | >- [10] Stamou, S., Oflazer, K., Pala, K., Christodoulakis, D., Cristea, D., Tufis, D., Koeva, S.,Totkov,G., Dutoit, D., Grigoriadou, M.: Balkanet: A multilingual semantic network for Balkan languages.Proceedings of the 1st Global Wordnet Conference. Mysore, Hindistan, (2002). 62 | >- [11] Emre Yıldız, “Anlamsal İlişkiler Veri Kümesi”, Yıldız Teknik Üniversitesi, Bilgisayar Müh. 63 | Bölümü,(2010). 64 | >- [12] Oğuz Yıldırım, Fatih Atık, M. Fatih AMASYALI, "42 Bin Haber Veri Kümesi”, Yıldız Teknik 65 | Üniversitesi, Bilgisayar Müh. Bölümü,(2003). 66 | >- [13] Regina Barzilay and Michael Elhadad, “Using Lexical Chains for Text Summarization”, In 67 | Proceedings of the ACL Workshop on Intelligent Scalable Text Summarization,(1997), 10-17. 68 | >- [14] William Doran, Nicola Stokes, Joe Carthy, John Dunnion. "Assessing the Impact of Lexical Chain Scoring Methods and Sentence Extraction Schemes on Summarization", Computational Linguistics and Intelligent Text Processing Volume 2945 of the series Lecture Notes in Computer Science , (2004), 627-635. 69 | 70 | --- 71 | ##### 72 | > **Gereksinimler:** 73 | >- JavaSE 1.8 74 | >- ~~MongoDb~~ 75 | >- Docker & Docker Compose 76 | 77 | > **Sunucu kurulumu :** 78 | >- LINUX 79 | >- Terminal ile öncelikle uygulama dizinine geciyoruz 80 | >- eger armv7 kullaniyorsak: 81 | sbt 'set dockerBaseImage := "armv7/armhf-java8"' docker:stage 82 | >- eger kullanmiyorsak oracle veya openjdk secebilirsiniz: 83 | sbt 'set dockerBaseImage := "nimmis/java:oracle-8-jdk"' docker:stage 84 | >- sudo docker-compose -f docker-compose.yml up -d --build 85 | >- localhost:9999 adresinden sunucuya ulasabiliriz 86 | >- sunucuyu durdurmak icinse 87 | >- sudo docker-compose down 88 | 89 | ---------- 90 | 91 | ###Örnek 92 | 93 | > **Haber metni:** 94 | 95 | Yıldız Kızlarımız Dünya Şampiyonu 96 | 97 | Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti. 98 | 99 | Yıldız Milli Takım, TVF Başkent Salonu'nda yapılan final maçında baştan sona üstün bir performans sergileyerek, Dünyanın en iyi takımları arasında yer alan Çin'e adeta göz açtırmadı. Tüm oyuncuların iyi oynadığı Türk Milli Takımı'nda Kübra Akman performansıyla göz doldururken, Çin Milli Takımı'nın solak smaçörü Peiyi Liu, Yıldız kızları zorlayan en önemli oyuncu oldu. Türkiye, 2007 yılında Meksika'da yapılan Dünya Yıldız Kızlar Şampiyonası finalinde Çin'e karşı 3-1 kaybederek Dünya ikincisi olduğu maçın rövanşını set kayıpsız aldı. 100 | 101 | Bu arada karşılaşmayı Gençlik ve Spor Bakanı Suat Kılıç, Türkiye Voleybol Federasyonu Başkanı Erol Ünal Karabıyık ile birlikte protokol tribününden takip etti. TVF Başkent Salonu'nun tamamını dolduran seyirciler, ellerindeki Türk bayraklarıyla maç boyunca Türk Milli Takımı'nı coşkulu bir şekilde desteklediler.Voleybolseverler, TVF Bandosunun çaldığı hareketli parçalara eşlik ederek, takımlarını bir an bile yalnız bırakmadılar. 102 | 103 | Yıldız Kızlar Dünya Şampiyonası FIVB'nin düzenlediği ve 18 yaşının altındaki voleybolcuların katılabildiği bir şampiyonadır. İlk şampiyona 1989 yılında Brezilya'nın Curitiba kentinde yapılmıştır. Her iki yılda bir düzenlenen şampiyonaya kıta elemelerini geçen ülke takımları katılabilmektedir. 104 | 105 | > **Özet:** 106 | Yıldız Kızlarımız Dünya Şampiyonu Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu. Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti. Yıldız Milli Takım, TVF Başkent Salonu'nda yapılan final maçında baştan sona üstün bir performans sergileyerek, Dünyanın en iyi takımları arasında yer alan Çin'e adeta göz açtırmadı. Tüm oyuncuların iyi oynadığı Türk Milli Takımı'nda Kübra Akman performansıyla göz doldururken, Çin Milli Takımı'nın solak smaçörü Peiyi Liu, Yıldız kızları zorlayan en önemli oyuncu oldu. 107 | 108 | > **Kelime Zincirleri** 109 | >- "P1 S2" kelimenin 1. paragrafdaki 2. cümlede geçtiğini belirtir 110 | > 111 | >- (şampiyon synonymy kişi) P0-S0,(yıldız hypernymy kişi) P1-S0,(şampiyon synonymy kişi) P1-S0,(şampiyon synonymy kişi) P1-S1,(el hypernymy kişi) P1-S1,(baş hypernymy kişi) P2-S0,(üst hypernymy kişi) P2-S0,(türk hypernymy kişi) P2-S1,(başkan hypernymy kişi) P3-S0,(el hypernymy kişi) P3-S1,(türk hypernymy kişi) P3-S1,(türk hypernymy kişi) P3-S1, 112 | >- Zincirdeki kelime sayisi: 12 113 | >- Zincirin iliskisel puan degeri: 66 114 | >- Zincirin guc degeri: 5 115 | 116 | >- (mil related_with matematik) P1-S0,(mil related_with matematik) P2-S0,(mil related_with matematik) P2-S1,(mil related_with matematik) P2-S1,(mil related_with matematik) P3-S1,(şekil related_with matematik) P3-S1,:6:24:4.0 117 | >- Zincirdeki kelime sayisi: 6 118 | >- Zincirin iliskisel puan degeri: 24 119 | >- Zincirin guc degeri: 4.0 120 | 121 | >- (dünya holo_member güneş sistemi) P0-S0,(dünya holo_member güneş sistemi) P1-S0,(dünya holo_member güneş sistemi) P1-S1,(dünya holo_member güneş sistemi) P2-S0,(dünya holo_member güneş sistemi) P2-S2,(dünya holo_member güneş sistemi) P2-S2,(dünya holo_member güneş sistemi) P4-S0,:7:28:6.0 122 | >- Zincirdeki kelime sayisi: 7 123 | >- Zincirin iliskisel puan degeri: 28 124 | >- Zincirin guc degeri: 6.0 125 | 126 | >- (dünya related_with astronomi) P0-S0,(yıldız holo_member astronomi) P1-S0,(yıldız hypernymy astronomi) P1-S0,(yıldız holo_member astronomi) P1-S0,(yıldız holo_member astronomi) P2-S0,(yıldız holo_member astronomi) P2-S1,(yıl related_with astronomi) P2-S2,(yıldız holo_member astronomi) P2-S2,(yıldız holo_member astronomi) P4-S0,(yıl related_with astronomi) P4-S1,(yıl related_with astronomi) P4-S2,:11:44:8.0 127 | >- Zincirdeki kelime sayisi: 11 128 | >- Zincirin iliskisel puan degeri: 44 129 | >- Zincirin guc degeri: 8.0 130 | 131 | >- (çin hypernymy ülke) P1-S0,(türkiye holo_member ülke) P1-S1,(türkiye holo_part ülke) P1-S1,(türkiye hypernymy ülke) P1-S1,(el synonymy ülke) P1-S1,(türkiye holo_member ülke) P2-S2,(meksika hypernymy ülke) P2-S2,(türkiye holo_member ülke) P3-S0,(brezilya hypernymy ülke) P4-S1,(kıta synonymy ülke) P4-S2,:10:52:4.0 132 | >- Zincirdeki kelime sayisi: 10 133 | >- Zincirin iliskisel puan degeri: 52 134 | >- Zincirin guc degeri: 4.0 135 | 136 | >- (voleybol related_with spor) P1-S0,(takım related_with spor) P1-S0,(final related_with spor) P1-S0,(voleybol related_with spor) P1-S1,(final related_with spor) P2-S0,(oyun related_with spor) P2-S1,(smaçör related_with spor) P2-S1,(oyun related_with spor) P2-S1,(final related_with spor) P2-S2,(set related_with spor) P2-S2,(voleybol related_with spor) P3-S0,(voleybol related_with spor) P4-S0,:12:48:6.0 137 | >- Zincirdeki kelime sayisi: 12 138 | >- Zincirin iliskisel puan degeri: 48 139 | >- Zincirin guc degeri: 6.0 140 | 141 | >- (dünya synonymy grup) P0-S0,(takım synonymy grup) P1-S0,(takım synonymy grup) P2-S0,(takım synonymy grup) P2-S0,(takım synonymy grup) P2-S1,(takım synonymy grup) P2-S1,(takım synonymy grup) P3-S1,(takım synonymy grup) P3-S2,(takım synonymy grup) P4-S2,:9:90:7.0 142 | >- Zincirdeki kelime sayisi: 9 143 | >- Zincirin iliskisel puan degeri: 90 144 | >- Zincirin guc degeri: 7.0 145 | 146 | >- (şampiyona synonymy bökelik) P1-S0,(şampiyona synonymy bökelik) P2-S2,(şampiyona synonymy bökelik) P4-S0,(şampiyona synonymy bökelik) P4-S0,(şampiyona synonymy bökelik) P4-S1,(şampiyona synonymy bökelik) P4-S2,:6:60:5.0 147 | >- Zincirdeki kelime sayisi: 6 148 | >- Zincirin iliskisel puan degeri: 60 149 | >- Zincirin guc degeri: 5.0 150 | 151 | > 152 | >- TOPLAM SONUCLAR 153 | >- Tüm zincirler: 429 154 | >- Benzersiz zincirler: 98 155 | >- Güçlü zincirler: 8 156 | >- Kelime zinciri ortalama puan değeri: 15.33673469387755 157 | >- Kelime zinciri ortalama güç değeri: 0.5918367346938775 158 | >- Kelime zinciri kriter değeri: 3.8724132730465493 159 | 160 | > **JSON API RESPOND:** 161 | >- {"result":"[Yıldız Kızlarımız Dünya Şampiyonu Dünya Yıldız Kızlar Voleybol Şampiyonası'nda Yıldız Milli Takım, final maçında Çin'i 3-0 yenerek şampiyon oldu., Türkiye, böylece voleybol tarihinin ilk Dünya şampiyonluğunu elde etti., Yıldız Milli Takım, TVF Başkent Salonu'nda yapılan final maçında baştan sona üstün bir performans sergileyerek, Dünyanın en iyi takımları arasında yer alan Çin'e adeta göz açtırmadı., Tüm oyuncuların iyi oynadığı Türk Milli Takımı'nda Kübra Akman performansıyla göz doldururken, Çin Milli Takımı'nın solak smaçörü Peiyi Liu, Yıldız kızları zorlayan en önemli oyuncu oldu.] " 162 | } 163 | 164 | ---------- 165 | ### API Kullanım 166 | 167 | >- [https://teaddict.net/ozetle](https://teaddict.net/ozetle) adresinden özetleme işlemini browser üzerinden yapabilirsiniz. 168 | >- [https://turkcemetinozetleme.teaddict.net](https://turkcemetinozetleme.teaddict.net/) adresinde swagger mevcut, sadece deneme amaçlı kullanıma açıktır. 169 | >- Örnek API kullanım için [bu dokümanları](https://github.com/teaddict/turkce-metin-ozetleme-scala/tree/master/ornek-api-kullanim) inceleyebilirsiniz. 170 | >- [Örnek metin dosyaları](https://github.com/teaddict/turkce-metin-ozetleme/tree/master/ornek-metinler) 171 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------