From 1c3d7fd3b4f0e423b8422802d51cb5bfa3779114 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Tue, 7 May 2024 11:47:48 +0200 Subject: [PATCH 1/2] start of Web - Summarizer --- .../MicElementSummerizeBlock.class.st | 55 +++++++++++++++++++ .../MicSummerizeBlock.class.st | 34 ++++++++++++ src/Web - Summarizer/package.st | 1 + 3 files changed, 90 insertions(+) create mode 100644 src/Web - Summarizer/MicElementSummerizeBlock.class.st create mode 100644 src/Web - Summarizer/MicSummerizeBlock.class.st create mode 100644 src/Web - Summarizer/package.st diff --git a/src/Web - Summarizer/MicElementSummerizeBlock.class.st b/src/Web - Summarizer/MicElementSummerizeBlock.class.st new file mode 100644 index 00000000..6003ac8e --- /dev/null +++ b/src/Web - Summarizer/MicElementSummerizeBlock.class.st @@ -0,0 +1,55 @@ +Class { + #name : 'MicElementSummerizeBlock', + #superclass : 'Object', + #instVars : [ + 'title', + 'resume' + ], + #category : 'Web - Summarizer', + #package : 'Web - Summarizer' +} + +{ #category : 'as yet unclassified' } +MicElementSummerizeBlock >> getFirstMicHeaderBlock: aMicRootBlock [ + + ^ (aMicRootBlock children select: [ :each | each isKindOf: MicHeaderBlock ]) at:1 +] + +{ #category : 'as yet unclassified' } +MicElementSummerizeBlock >> getFirstMicParagraphBlock: aMicRootBlock [ + + ^ (aMicRootBlock children select: [ :each | each isKindOf: MicParagraphBlock ]) at:1 +] + +{ #category : 'parsing' } +MicElementSummerizeBlock >> parseFile: aFileReference [ + + | p | + p := Microdown parse: aFileReference asFileReference contents. + title := self getFirstMicHeaderBlock: p. + resume := self getFirstMicParagraphBlock: p. +] + +{ #category : 'accessing' } +MicElementSummerizeBlock >> resume [ + + ^ resume +] + +{ #category : 'accessing' } +MicElementSummerizeBlock >> resume: aResume [ + + resume := aResume +] + +{ #category : 'accessing' } +MicElementSummerizeBlock >> title [ + + ^ title +] + +{ #category : 'accessing' } +MicElementSummerizeBlock >> title: aTitle [ + + title := aTitle +] diff --git a/src/Web - Summarizer/MicSummerizeBlock.class.st b/src/Web - Summarizer/MicSummerizeBlock.class.st new file mode 100644 index 00000000..bed884ff --- /dev/null +++ b/src/Web - Summarizer/MicSummerizeBlock.class.st @@ -0,0 +1,34 @@ +Class { + #name : 'MicSummerizeBlock', + #superclass : 'Object', + #category : 'Web - Summarizer', + #package : 'Web - Summarizer' +} + +{ #category : 'as yet unclassified' } +MicSummerizeBlock >> parseListOfElementSummerizeBlockToSummurizeBlock: aListOfElementSummerizeBlock [ + + | summarize | + + summarize := MicRootBlock new. + + aListOfElementSummerizeBlock do: [ :each | summarize addChild: each title ; addChild: each resume ]. + + ^ summarize +] + +{ #category : 'rendering' } +MicSummerizeBlock >> render: aMicSummerizeBlock [ + + | a q | + + a := (MicHTMLVisitor new visit: aMicSummerizeBlock ) at: 1. + + q := MicHTMLDocument new. + q configuration: a configuration. + q configuration document: q. + q setCharSetUTF8. + ^ q writeDocument: a contents; + writeToFile; + contents. +] diff --git a/src/Web - Summarizer/package.st b/src/Web - Summarizer/package.st new file mode 100644 index 00000000..1dc2f9ed --- /dev/null +++ b/src/Web - Summarizer/package.st @@ -0,0 +1 @@ +Package { #name : 'Web - Summarizer' } From b6331121e92dea11b42256c7d64e9e4fbdf63ae3 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Tue, 7 May 2024 18:22:14 +0200 Subject: [PATCH 2/2] add microdown-Blog with test --- .../MicSingleSummarizerTest.class.st | 74 +++++++++++++++++ .../MicSummerizeBlockTest.class.st | 18 +++++ src/Microdown-Blog-Tests/package.st | 1 + .../MicSingleSummarizer.class.st | 81 +++++++++++++++++++ src/Microdown-Blog/MicSummarizer.class.st | 40 +++++++++ src/Microdown-Blog/package.st | 1 + .../MicElementSummerizeBlock.class.st | 55 ------------- .../MicSummerizeBlock.class.st | 34 -------- src/Web - Summarizer/package.st | 1 - 9 files changed, 215 insertions(+), 90 deletions(-) create mode 100644 src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st create mode 100644 src/Microdown-Blog-Tests/MicSummerizeBlockTest.class.st create mode 100644 src/Microdown-Blog-Tests/package.st create mode 100644 src/Microdown-Blog/MicSingleSummarizer.class.st create mode 100644 src/Microdown-Blog/MicSummarizer.class.st create mode 100644 src/Microdown-Blog/package.st delete mode 100644 src/Web - Summarizer/MicElementSummerizeBlock.class.st delete mode 100644 src/Web - Summarizer/MicSummerizeBlock.class.st delete mode 100644 src/Web - Summarizer/package.st diff --git a/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st new file mode 100644 index 00000000..0933c624 --- /dev/null +++ b/src/Microdown-Blog-Tests/MicSingleSummarizerTest.class.st @@ -0,0 +1,74 @@ +Class { + #name : 'MicSingleSummarizerTest', + #superclass : 'TestCase', + #category : 'Microdown-Blog-Tests', + #package : 'Microdown-Blog-Tests' +} + +{ #category : 'enumerating' } +MicSingleSummarizerTest >> createMicRootBlock [ + + ^ Microdown parse: self generateFilesystemExample asFileReference contents +] + +{ #category : 'enumerating' } +MicSingleSummarizerTest >> generateFilesystemExample [ + + | file | + file := FileSystem disk workingDirectory / 'anExample1.md'. + file writeStreamDo: [ :stream | stream nextPutAll: '# A Cool Story +@sec1 + +Pharo is cool but _this is_ a superlong _paragraph_ Simple powerful language: No constructors, no types declaration, no interfaces, no primitive types. Yet a powerful and elegant language with a full syntax fitting in one postcard! Pharo is objects and messages all the way down. _Live_, immersive environment: Immediate feedback at any moment of your development: _Developing_, testing, debugging. Even in production environments, you will never be stuck in compiling and deploying steps again! + + +Amazing debugging experience: The Pharo environment includes a debugger unlike anything you''ve seen before. It allows you to step through code, restart the execution of methods, create methods on the fly, and much more! + +Pharo is yours: Pharo is made by an incredible community, with more than 100 contributors for the last revision of the platform and hundreds of people contributing constantly with frameworks and libraries. Fully open-source: Pharo full stack is released under MIT License and available on GitHub + + +``` +this is a code blu blu +``` +' ]. + + ^ file. +] + +{ #category : 'tests' } +MicSingleSummarizerTest >> testFirstHeaderBlock [ + + | header | + + header := MicSingleSummarizer new firstHeaderBlockOf: self createMicRootBlock. + self assert: ( header isKindOf: MicHeaderBlock). + self assert: header text equals: 'A Cool Story'. + + self assert: (header headerElements collect: [:each | each plainText ]) asArray equals: #('A Cool Story'). + header headerElements do: [ :each | self assert: each parent equals: header ] +] + +{ #category : 'tests' } +MicSingleSummarizerTest >> testFirstParagraphBlock [ + + | paragraph | + + paragraph := MicSingleSummarizer new + maximumWords: 3; + firstParagraphBlockOf: self createMicRootBlock. + self assert: ( paragraph isKindOf: MicParagraphBlock ). + + self assert: paragraph textElements size equals: 3. + self assert: (paragraph textElements collect: [:each | each plainText ]) asArray equals: #('Pharo is cool but ' 'this is' ' a superlong '). + paragraph textElements do: [ :each | self assert: each parent equals: paragraph ] +] + +{ #category : 'tests' } +MicSingleSummarizerTest >> testSummarizeFile [ + + | root | + root := MicSingleSummarizer new summarizeFile: self generateFilesystemExample. + self assert: (root isKindOf: MicRootBlock) + + +] diff --git a/src/Microdown-Blog-Tests/MicSummerizeBlockTest.class.st b/src/Microdown-Blog-Tests/MicSummerizeBlockTest.class.st new file mode 100644 index 00000000..4ac86031 --- /dev/null +++ b/src/Microdown-Blog-Tests/MicSummerizeBlockTest.class.st @@ -0,0 +1,18 @@ +Class { + #name : 'MicSummerizeBlockTest', + #superclass : 'TestCase', + #category : 'Microdown-Blog-Tests', + #package : 'Microdown-Blog-Tests' +} + +{ #category : 'tests' } +MicSummerizeBlockTest >> testCreateSummerize [ + + self assert: 1 equals: 0. +] + +{ #category : 'tests' } +MicSummerizeBlockTest >> testRender [ + + self assert: 1 equals: 0. +] diff --git a/src/Microdown-Blog-Tests/package.st b/src/Microdown-Blog-Tests/package.st new file mode 100644 index 00000000..96127839 --- /dev/null +++ b/src/Microdown-Blog-Tests/package.st @@ -0,0 +1 @@ +Package { #name : 'Microdown-Blog-Tests' } diff --git a/src/Microdown-Blog/MicSingleSummarizer.class.st b/src/Microdown-Blog/MicSingleSummarizer.class.st new file mode 100644 index 00000000..19a6234a --- /dev/null +++ b/src/Microdown-Blog/MicSingleSummarizer.class.st @@ -0,0 +1,81 @@ +Class { + #name : 'MicSingleSummarizer', + #superclass : 'Object', + #instVars : [ + 'maximumWords' + ], + #category : 'Microdown-Blog', + #package : 'Microdown-Blog' +} + +{ #category : 'accessing' } +MicSingleSummarizer >> firstHeaderBlockOf: aMicRootBlock [ + + + | header newHeader | + header := aMicRootBlock children + detect: [ :each | each isKindOf: MicHeaderBlock ] + ifNone: [ + | h t | + h := MicHeaderBlock new. + t := MicTextBlock new bodyString: 'Please define a header'. + h headerElements: { t }. + t parent: h. + ^ h ]. + newHeader := MicHeaderBlock new. + header headerElements do: [ :t | t copy parent: newHeader ]. + ^ newHeader +] + +{ #category : 'accessing' } +MicSingleSummarizer >> firstParagraphBlockOf: aMicRootBlock [ + + | p textElements newParagraph selectionSize t | + p := aMicRootBlock children + detect: [ :each | each isKindOf: MicParagraphBlock ] + ifNone: [ + p := MicParagraphBlock new. + t := MicTextBlock new bodyString: 'Please add a paragraph'. + p textElements: { t }. + t parent: p. + ^ p ]. + selectionSize := maximumWords min: p textElements size. + textElements := (p textElements first: selectionSize). + newParagraph := MicParagraphBlock new. + textElements do: [ :t | + newParagraph addChild: t copy ]. + ^ newParagraph +] + +{ #category : 'initialization' } +MicSingleSummarizer >> initialize [ + + super initialize. + maximumWords := 15 +] + +{ #category : 'accessing' } +MicSingleSummarizer >> maximumWords: anInteger [ + maximumWords := anInteger +] + +{ #category : 'parsing' } +MicSingleSummarizer >> summarize: aMicRootBlock [ + + + | element | + element := MicRootBlock new. + element + addChild: (self firstHeaderBlockOf: aMicRootBlock); + addChild: (self firstParagraphBlockOf: aMicRootBlock). + + ^ element. +] + +{ #category : 'parsing' } +MicSingleSummarizer >> summarizeFile: aFileReference [ + + | p | + p := Microdown parse: aFileReference asFileReference contents. + ^ self summarize: p +] diff --git a/src/Microdown-Blog/MicSummarizer.class.st b/src/Microdown-Blog/MicSummarizer.class.st new file mode 100644 index 00000000..16e21cc7 --- /dev/null +++ b/src/Microdown-Blog/MicSummarizer.class.st @@ -0,0 +1,40 @@ +Class { + #name : 'MicSummarizer', + #superclass : 'Object', + #category : 'Microdown-Blog', + #package : 'Microdown-Blog' +} + +{ #category : 'as yet unclassified' } +MicSummarizer >> createSummerize: aListOfElementSummerizeBlock [ + + | summarize | + + summarize := MicRootBlock new. + + (aListOfElementSummerizeBlock copyFrom: 1 to: 10) do:[ :each | summarize addChild: each title ; addChild: each resume ]. + + ^ summarize +] + +{ #category : 'as yet unclassified' } +MicSummarizer >> group: aListOfElementSummerizeBlock byDate: aDate [ + + ^ aListOfElementSummerizeBlock select: [ :each | ( each children at:1 ) at: #Date = aDate ] +] + +{ #category : 'rendering' } +MicSummarizer >> render: aMicSummerizeBlock [ + + | a q | + + a := (MicHTMLVisitor new visit: aMicSummerizeBlock ) at: 1. + + q := MicHTMLDocument new. + q configuration: a configuration. + q configuration document: q. + q setCharSetUTF8. + ^ q writeDocument: a contents; + writeToFile; + contents. +] diff --git a/src/Microdown-Blog/package.st b/src/Microdown-Blog/package.st new file mode 100644 index 00000000..c8c0d29c --- /dev/null +++ b/src/Microdown-Blog/package.st @@ -0,0 +1 @@ +Package { #name : 'Microdown-Blog' } diff --git a/src/Web - Summarizer/MicElementSummerizeBlock.class.st b/src/Web - Summarizer/MicElementSummerizeBlock.class.st deleted file mode 100644 index 6003ac8e..00000000 --- a/src/Web - Summarizer/MicElementSummerizeBlock.class.st +++ /dev/null @@ -1,55 +0,0 @@ -Class { - #name : 'MicElementSummerizeBlock', - #superclass : 'Object', - #instVars : [ - 'title', - 'resume' - ], - #category : 'Web - Summarizer', - #package : 'Web - Summarizer' -} - -{ #category : 'as yet unclassified' } -MicElementSummerizeBlock >> getFirstMicHeaderBlock: aMicRootBlock [ - - ^ (aMicRootBlock children select: [ :each | each isKindOf: MicHeaderBlock ]) at:1 -] - -{ #category : 'as yet unclassified' } -MicElementSummerizeBlock >> getFirstMicParagraphBlock: aMicRootBlock [ - - ^ (aMicRootBlock children select: [ :each | each isKindOf: MicParagraphBlock ]) at:1 -] - -{ #category : 'parsing' } -MicElementSummerizeBlock >> parseFile: aFileReference [ - - | p | - p := Microdown parse: aFileReference asFileReference contents. - title := self getFirstMicHeaderBlock: p. - resume := self getFirstMicParagraphBlock: p. -] - -{ #category : 'accessing' } -MicElementSummerizeBlock >> resume [ - - ^ resume -] - -{ #category : 'accessing' } -MicElementSummerizeBlock >> resume: aResume [ - - resume := aResume -] - -{ #category : 'accessing' } -MicElementSummerizeBlock >> title [ - - ^ title -] - -{ #category : 'accessing' } -MicElementSummerizeBlock >> title: aTitle [ - - title := aTitle -] diff --git a/src/Web - Summarizer/MicSummerizeBlock.class.st b/src/Web - Summarizer/MicSummerizeBlock.class.st deleted file mode 100644 index bed884ff..00000000 --- a/src/Web - Summarizer/MicSummerizeBlock.class.st +++ /dev/null @@ -1,34 +0,0 @@ -Class { - #name : 'MicSummerizeBlock', - #superclass : 'Object', - #category : 'Web - Summarizer', - #package : 'Web - Summarizer' -} - -{ #category : 'as yet unclassified' } -MicSummerizeBlock >> parseListOfElementSummerizeBlockToSummurizeBlock: aListOfElementSummerizeBlock [ - - | summarize | - - summarize := MicRootBlock new. - - aListOfElementSummerizeBlock do: [ :each | summarize addChild: each title ; addChild: each resume ]. - - ^ summarize -] - -{ #category : 'rendering' } -MicSummerizeBlock >> render: aMicSummerizeBlock [ - - | a q | - - a := (MicHTMLVisitor new visit: aMicSummerizeBlock ) at: 1. - - q := MicHTMLDocument new. - q configuration: a configuration. - q configuration document: q. - q setCharSetUTF8. - ^ q writeDocument: a contents; - writeToFile; - contents. -] diff --git a/src/Web - Summarizer/package.st b/src/Web - Summarizer/package.st deleted file mode 100644 index 1dc2f9ed..00000000 --- a/src/Web - Summarizer/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : 'Web - Summarizer' }