Skip to content

Commit 6ed2a58

Browse files
committed
First commit
0 parents  commit 6ed2a58

12 files changed

+378
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.stack-work/
2+
*~

ChangeLog.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog for `Syllable`
2+
3+
## [Unreleased changes]
4+
- Use `overloaded strings`
5+
- Syllabify the words of a file piped from `stdin` in the command line
6+
- Write tests for the library
7+
- Write haddock documentation
8+
9+
## [0.1.0.0] - 2018-01-10
10+
### Added
11+
- The github repository `jjunho/Syllable`
12+
- A basic `README` file
13+
- The first working version of the Syllable library with a basic `Main` that syllabifies my name

LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright Juliano Paiva Junho (c) 2018
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Juliano Paiva Junho nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# `Syllable` - A haskell library for syllabification of words in Portuguese
2+
3+
Syllables in Portuguese follow basically the following scheme:
4+
5+
(C)(L)V(S)(N)(C)
6+
7+
where:
8+
C = consonant
9+
L = liquid (/l/ or /r/)
10+
V = vowel
11+
S = semivowel (<i> /j/ or <u> /w/)
12+
N = nasal (/n/)
13+
14+
There are still some exceptions that need to be taken care of but, overall, it is a functioning library.

Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

Syllable.cabal

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
-- This file has been generated from package.yaml by hpack version 0.20.0.
2+
--
3+
-- see: https://github.com/sol/hpack
4+
--
5+
-- hash: 1dafeca7616aa8f47ac00635da7d3435bfed6b30c34365f729e98ae1f279aae3
6+
7+
name: Syllable
8+
version: 0.1.0.0
9+
synopsis: Syllabification in Portuguese
10+
description: Please see the README on Github at <https://github.com/jjunho/Syllable#readme>
11+
category: Natural Language Processing
12+
homepage: https://github.com/jjunho/Syllable#readme
13+
bug-reports: https://github.com/jjunho/Syllable/issues
14+
author: Juliano Paiva Junho
15+
maintainer: [email protected]
16+
copyright: Copyright © 2018 Juliano Paiva Junho
17+
license: BSD3
18+
license-file: LICENSE
19+
build-type: Simple
20+
cabal-version: >= 1.10
21+
22+
extra-source-files:
23+
ChangeLog.md
24+
README.md
25+
26+
source-repository head
27+
type: git
28+
location: https://github.com/jjunho/Syllable
29+
30+
library
31+
hs-source-dirs:
32+
src
33+
build-depends:
34+
base >=4.7 && <5
35+
exposed-modules:
36+
Syllable.Base
37+
Syllable.Port
38+
other-modules:
39+
Paths_Syllable
40+
default-language: Haskell2010
41+
42+
executable Syllable-exe
43+
main-is: Main.hs
44+
hs-source-dirs:
45+
app
46+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
47+
build-depends:
48+
Syllable
49+
, base >=4.7 && <5
50+
other-modules:
51+
Paths_Syllable
52+
default-language: Haskell2010
53+
54+
test-suite Syllable-test
55+
type: exitcode-stdio-1.0
56+
main-is: Spec.hs
57+
hs-source-dirs:
58+
test
59+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
60+
build-depends:
61+
Syllable
62+
, base >=4.7 && <5
63+
other-modules:
64+
Paths_Syllable
65+
default-language: Haskell2010

app/Main.hs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main where
3+
4+
import Syllable.Port
5+
6+
main :: IO ()
7+
main = putStrLn $ strSyllables "juliano"

package.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Syllable
2+
version: 0.1.0.0
3+
github: "jjunho/Syllable"
4+
license: BSD3
5+
author: "Juliano Paiva Junho"
6+
maintainer: "[email protected]"
7+
copyright: "Copyright © 2018 Juliano Paiva Junho"
8+
9+
extra-source-files:
10+
- README.md
11+
- ChangeLog.md
12+
13+
# Metadata used when publishing your package
14+
synopsis: Syllabification in Portuguese
15+
category: Natural Language Processing
16+
17+
# To avoid duplicated efforts in documentation and dealing with the
18+
# complications of embedding Haddock markup inside cabal files, it is
19+
# common to point users to the README.md file.
20+
description: Please see the README on Github at <https://github.com/jjunho/Syllable#readme>
21+
22+
dependencies:
23+
- base >= 4.7 && < 5
24+
25+
library:
26+
source-dirs: src
27+
28+
executables:
29+
Syllable-exe:
30+
main: Main.hs
31+
source-dirs: app
32+
ghc-options:
33+
- -threaded
34+
- -rtsopts
35+
- -with-rtsopts=-N
36+
dependencies:
37+
- Syllable
38+
39+
tests:
40+
Syllable-test:
41+
main: Spec.hs
42+
source-dirs: test
43+
ghc-options:
44+
- -threaded
45+
- -rtsopts
46+
- -with-rtsopts=-N
47+
dependencies:
48+
- Syllable

src/Syllable/Base.hs

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module Syllable.Base where
2+
3+
data Syllable = Syllable { sylOnset :: String
4+
, sylNucleus :: String
5+
, sylCoda :: String }
6+
deriving (Show)
7+
8+
data CV = V { cv :: String } | C { cv :: String }
9+
deriving Show
10+
11+
vowels :: String
12+
vowels = "aeiouáéíóúàâêôãõüAEIOUÁÉÍÓÚÀÂÊÔÃÕÜ"
13+
14+
digraphs :: String
15+
digraphs = "ss rr ch lh nh gu qu SS RR CH LH NH GU QU"
16+
17+
semivowels :: String
18+
semivowels = "iuIU"
19+
20+
nasalDiphtongs :: String
21+
nasalDiphtongs = "ão ãe õe ÃO ÃE ÕE"
22+
23+
isNucleus :: String -> Bool
24+
isNucleus [s] = isVowel [s]
25+
isNucleus [s1,s2] = isDiphtong [s1,s2]
26+
27+
isOnset :: String -> Bool
28+
isOnset [s] = isConsonant [s]
29+
isOnset [s1,s2] = isCluster [s1,s2] || isDigraph [s1,s2]
30+
31+
isCoda :: String -> Bool
32+
isCoda [s] = isConsonant [s]
33+
isCoda [s1,s2] = s1 `elem` "nN" && isConsonant [s2]
34+
35+
isVowel :: String -> Bool
36+
isVowel [x] = x `elem` vowels
37+
38+
isConsonant :: String -> Bool
39+
isConsonant = not . isVowel
40+
41+
isDigraph :: String -> Bool
42+
isDigraph [c1,c2] = [c1, c2] `elem` words digraphs
43+
44+
isDiphtong :: String -> Bool
45+
isDiphtong vs@[v1,v2]
46+
| isVowel [v1] && v2 `elem` semivowels = True
47+
| vs `elem` words nasalDiphtongs = True
48+
| otherwise = False
49+
50+
isCluster :: String -> Bool
51+
isCluster c = c `elem` [[x, y] | x <- "ctpfgdbv", y <- "lr"]
52+
53+
mkDiphtong :: String -> [String]
54+
mkDiphtong [v1, v2] =
55+
if isDiphtong [v1,v2]
56+
then [[v1,v2]]
57+
else [[v1],[v2]]
58+
59+
mkDigraph :: String -> [String]
60+
mkDigraph [c1, c2] =
61+
if isDigraph [c1,c2]
62+
then [[c1,c2]]
63+
else [[c1],[c2]]

src/Syllable/Port.hs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module Syllable.Port (mkSyllables,strSyllables) where
2+
3+
import Syllable.Base
4+
5+
groupLetters :: String -> [CV]
6+
groupLetters (c1:'u':c3:cs)
7+
| isDiphtong [c1,'u'] = V [c1, 'u'] : groupLetters (c3:cs)
8+
| c1 `elem` "qg" = C [c1, 'u'] : groupLetters (c3:cs)
9+
| isConsonant [c3] = [C [c1], V "u"] ++ groupLetters (c3:cs)
10+
| isDiphtong [c1,'U'] = V [c1, 'U'] : groupLetters (c3:cs)
11+
| c1 `elem` "QG" = C [c1, 'U'] : groupLetters (c3:cs)
12+
| isConsonant [c3] = [C [c1], V "U"] ++ groupLetters (c3:cs)
13+
groupLetters (c1:c2:cs)
14+
| isCluster [c1,c2] = C [c1, c2] : groupLetters cs
15+
| isDiphtong [c1,c2] = V [c1, c2] : groupLetters cs
16+
| isDigraph [c1,c2] = C [c1, c2] : groupLetters cs
17+
| isVowel [c1] = V [c1] : groupLetters (c2:cs)
18+
| isConsonant [c1] = C [c1] : groupLetters (c2:cs)
19+
groupLetters (c1:cs)
20+
| isVowel [c1] = V [c1] : groupLetters cs
21+
| isConsonant [c1] = C [c1] : groupLetters cs
22+
groupLetters [] = []
23+
24+
groupSyllables :: [CV] -> [[CV]]
25+
groupSyllables [] = []
26+
groupSyllables [C a , V b , C c ] = [[C a, V b, C c] ]
27+
groupSyllables [ V b , C c ] = [[ V b, C c] ]
28+
groupSyllables (C a : V b : C "n" : C "s" : V e : cvs) = [C a, V b, C "n" ] : groupSyllables (C "s" : V e : cvs)
29+
groupSyllables (C a : V b : C "ss" : V e : cvs) = [C a, V b, C "s" ] : groupSyllables (C "s" : V e : cvs)
30+
groupSyllables (C a : V b : C "rr" : V e : cvs) = [C a, V b, C "r" ] : groupSyllables (C "r" : V e : cvs)
31+
groupSyllables ( V b : C "ss" : V e : cvs) = [ V b, C "s" ] : groupSyllables (C "s" : V e : cvs)
32+
groupSyllables ( V b : C "rr" : V e : cvs) = [ V b, C "r" ] : groupSyllables (C "r" : V e : cvs)
33+
groupSyllables (C a : V b : C "n" : C "s" : cvs) = [C a, V b, C "n", C "s"] : groupSyllables cvs
34+
groupSyllables (C a : V b : C "N" : C "S" : V e : cvs) = [C a, V b, C "N" ] : groupSyllables (C "S" : V e : cvs)
35+
groupSyllables (C a : V b : C "SS" : V e : cvs) = [C a, V b, C "S" ] : groupSyllables (C "S" : V e : cvs)
36+
groupSyllables (C a : V b : C "RR" : V e : cvs) = [C a, V b, C "R" ] : groupSyllables (C "R" : V e : cvs)
37+
groupSyllables ( V b : C "SS" : V e : cvs) = [ V b, C "S" ] : groupSyllables (C "S" : V e : cvs)
38+
groupSyllables ( V b : C "RR" : V e : cvs) = [ V b, C "R" ] : groupSyllables (C "R" : V e : cvs)
39+
groupSyllables (C a : V b : C "N" : C "S" : cvs) = [C a, V b, C "N", C "S"] : groupSyllables cvs
40+
groupSyllables (C a : V b : C c : C d : cvs) = [C a, V b, C c ] : groupSyllables (C d : cvs)
41+
groupSyllables ( V b : C c : C d : cvs) = [ V b, C c ] : groupSyllables (C d : cvs)
42+
groupSyllables (C a : V b : C c : V d : cvs) = [C a, V b ] : groupSyllables (C c : V d : cvs)
43+
groupSyllables ( V b : C c : V d : cvs) = [ V b ] : groupSyllables (C c : V d : cvs)
44+
groupSyllables (C a : V b : V c : cvs) = [C a, V b ] : groupSyllables (V c : cvs)
45+
groupSyllables ( V b : V c : cvs) = [ V b ] : groupSyllables (V c : cvs)
46+
groupSyllables (C a : V b : cvs) = [C a, V b ] : groupSyllables cvs
47+
groupSyllables ( V b : cvs) = [ V b ] : groupSyllables cvs
48+
49+
showSyllables :: String -> [[CV]]
50+
showSyllables = groupSyllables . groupLetters
51+
52+
mkSyllable :: [CV] -> Syllable
53+
mkSyllable [C a, V b, C c, C d] = Syllable a b (c ++ d)
54+
mkSyllable [C a, V b, C c ] = Syllable a b c
55+
mkSyllable [C a, V b ] = Syllable a b ""
56+
mkSyllable [ V b, C c ] = Syllable "" b c
57+
mkSyllable [ V b ] = Syllable "" b ""
58+
59+
mkSyllables :: String -> [Syllable]
60+
mkSyllables s = map mkSyllable x
61+
where x = showSyllables s
62+
63+
strSyllable :: Syllable -> String
64+
strSyllable (Syllable a b c) = a ++ b ++ c
65+
66+
strSyllables :: String -> String
67+
strSyllables s = unwords $ map strSyllable $ mkSyllables s

stack.yaml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This file was automatically generated by 'stack init'
2+
#
3+
# Some commonly used options have been documented as comments in this file.
4+
# For advanced use and comprehensive documentation of the format, please see:
5+
# https://docs.haskellstack.org/en/stable/yaml_configuration/
6+
7+
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8+
# A snapshot resolver dictates the compiler version and the set of packages
9+
# to be used for project dependencies. For example:
10+
#
11+
# resolver: lts-3.5
12+
# resolver: nightly-2015-09-21
13+
resolver: ghc-8.0.2
14+
# resolver: ghcjs-0.1.0_ghc-7.10.2
15+
# resolver:
16+
# name: custom-snapshot
17+
# location: "./custom-snapshot.yaml"
18+
19+
# User packages to be built.
20+
# Various formats can be used as shown in the example below.
21+
#
22+
# packages:
23+
# - some-directory
24+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
25+
# - location:
26+
# git: https://github.com/commercialhaskell/stack.git
27+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
28+
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
29+
# extra-dep: true
30+
# subdirs:
31+
# - auto-update
32+
# - wai
33+
#
34+
# A package marked 'extra-dep: true' will only be built if demanded by a
35+
# non-dependency (i.e. a user package), and its test suites and benchmarks
36+
# will not be run. This is useful for tweaking upstream packages.
37+
packages:
38+
- .
39+
# Dependency packages to be pulled from upstream that are not in the resolver
40+
# (e.g., acme-missiles-0.3)
41+
extra-deps: []
42+
43+
# Override default flag values for local packages and extra-deps
44+
flags: {}
45+
46+
# Extra package databases containing global packages
47+
extra-package-dbs: []
48+
49+
# Control whether we use the GHC we find on the path
50+
# system-ghc: true
51+
#
52+
# Require a specific version of stack, using version ranges
53+
# require-stack-version: -any # Default
54+
# require-stack-version: ">=1.5"
55+
#
56+
# Override the architecture used by stack, especially useful on Windows
57+
# arch: i386
58+
# arch: x86_64
59+
#
60+
# Extra directories used by stack for building
61+
# extra-include-dirs: [/path/to/dir]
62+
# extra-lib-dirs: [/path/to/dir]
63+
#
64+
# Allow a newer minor version of GHC than the snapshot specifies
65+
# compiler-check: newer-minor

test/Spec.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main :: IO ()
2+
main = putStrLn "Test suite not yet implemented"

0 commit comments

Comments
 (0)