├── .gitignore
├── Config
├── CONFIG
├── Grammar
│ ├── mathexp.gram
│ ├── sparels.gmm
│ └── symbol.types
└── SymRec
│ ├── OFF.blstm
│ ├── ON.blstm
│ ├── duration.counts
│ ├── off.mav
│ ├── on.mav
│ └── segmentation.gmm
├── LICENSE
├── Makefile
├── README
├── README.md
├── SampleMathExps
├── exp.inkml
└── exp.scgink
├── cellcyk.cc
├── cellcyk.h
├── duration.cc
├── duration.h
├── featureson.cc
├── featureson.h
├── gmm.cc
├── gmm.h
├── gparser.cc
├── gparser.h
├── grammar.cc
├── grammar.h
├── hypothesis.cc
├── hypothesis.h
├── logspace.cc
├── logspace.h
├── meparser.cc
├── meparser.h
├── online.cc
├── online.h
├── production.cc
├── production.h
├── rnnlib4seshat
├── ActivationFunctions.hpp
├── BiasLayer.hpp
├── BlockLayer.hpp
├── ClassificationLayer.cpp
├── ClassificationLayer.hpp
├── CollapseLayer.hpp
├── ConfigFile.hpp
├── Connection.hpp
├── Container.hpp
├── CopyConnection.hpp
├── DataExporter.cpp
├── DataExporter.hpp
├── DataSequence.hpp
├── FullConnection.hpp
├── GatherLayer.hpp
├── Helpers.hpp
├── IdentityLayer.hpp
├── InputLayer.hpp
├── Layer.cpp
├── Layer.hpp
├── Log.hpp
├── LstmLayer.hpp
├── Matrix.hpp
├── Mdrnn.cpp
├── Mdrnn.hpp
├── MultiArray.hpp
├── MultilayerNet.hpp
├── Named.hpp
├── NetcdfDataset.hpp
├── NetworkOutput.hpp
├── NeuronLayer.hpp
├── Optimiser.cpp
├── Optimiser.hpp
├── Random.cpp
├── Random.hpp
├── Rprop.hpp
├── SeqBuffer.hpp
├── SoftmaxLayer.hpp
├── SteepestDescent.hpp
├── String.hpp
├── StringAlignment.hpp
├── Trainer.hpp
├── TranscriptionLayer.hpp
├── WeightContainer.cpp
└── WeightContainer.hpp
├── sample.cc
├── sample.h
├── segmentation.cc
├── segmentation.h
├── seshat.cc
├── sparel.cc
├── sparel.h
├── stroke.cc
├── stroke.h
├── symfeatures.cc
├── symfeatures.h
├── symrec.cc
├── symrec.h
├── tablecyk.cc
└── tablecyk.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 | *.obj
6 |
7 | # Compiled Dynamic libraries
8 | *.so
9 | *.dylib
10 | *.dll
11 |
12 | # Compiled Static libraries
13 | *.lai
14 | *.la
15 | *.a
16 | *.lib
17 |
18 | # Executables
19 | *.exe
20 | *.out
21 | *.app
22 |
--------------------------------------------------------------------------------
/Config/CONFIG:
--------------------------------------------------------------------------------
1 | GRAMMAR Config/Grammar/mathexp.gram
2 | SymbolTypes Config/Grammar/symbol.types
3 | SpatialRels Config/Grammar/sparels.gmm
4 | Duration Config/SymRec/duration.counts
5 | Segmentation Config/SymRec/segmentation.gmm
6 | RNNon Config/SymRec/ON.blstm
7 | RNNmavON Config/SymRec/on.mav
8 | RNNoff Config/SymRec/OFF.blstm
9 | RNNmavOFF Config/SymRec/off.mav
10 | RNNalpha 0.50
11 | MaxStrokes 4
12 | SegmentsTH 0.69474973
13 | InsPenalty 2.11917745
14 | SymbolSF 1.88593577
15 | DurationSF 0.93889491
16 | SegmentationSF 2.77746769
17 | RelationSF 0.63225349
18 | ProductionTSF 0.37846575
19 | ProductionBSF 0.14864657
20 | ClusterF 0.15680604
21 |
--------------------------------------------------------------------------------
/Config/Grammar/sparels.gmm:
--------------------------------------------------------------------------------
1 | 6 9 5
2 | 0.718383234419 0.055574466826 0.078203856912 0.120754214335 0.025145411221 0.001938816286
3 | 0.0400465 0.0462119 0.158954 0.119728 0.338147 0.650734 0.0257464 0.0207452 0.0500226
4 | 6.38977e-29 0.0306662 3.11926 0.0920412 0.209213 12.3927 0.025514 0.035705 0.0255653
5 | 0.00471493 0.0423204 0.760158 0.10667 0.259005 2.78825 3.65786e-05 0.0447119 0.00472035
6 | 0.0153037 0.0569341 2.31413 1.11035 1.47678 10.5612 0.0245617 0.0298914 0.0315428
7 | 0.0650266 0.0394849 0.0599804 0.0243055 0.107061 0.13888 0.0461497 0.0425307 0.0662506
8 | 0.754189 -0.0702447 -1.61337 0.433981 1.18366 2.04308 -0.780692 0.133713 -0.0339323
9 | 1 0.0211677 -2.4223 0.3209 0.755544 4.08905 -0.759212 -0.293398 0.23767
10 | 0.911813 0.117074 -1.73303 0.395061 0.981709 2.48436 -0.996298 -0.248554 -0.0877496
11 | 0.875886 -0.0548455 -3.70841 0.906565 1.66987 5.74695 -0.838009 0.0188168 0.0312145
12 | 0.617975 -0.0592687 -0.753022 0.160156 0.661045 0.845 -0.70423 0.213682 -0.0935981
13 | 0.114239 0.599775 0.1071 0.0580644 0.120821
14 | 0.00828608 0.015773 0.0118063 0.0110558 0.041533 0.0242046 0.0172115 0.00612675 0.0252167
15 | 0.0365525 0.0351008 0.205108 0.0887008 0.274506 0.462619 0.0513276 0.0421679 0.061057
16 | 0.0351226 0.0342489 0.0144722 0.0132679 0.0315408 0.0226689 0.0459325 0.016168 0.105993
17 | 0.0137349 0.0104148 0.03013 0.0261673 0.0972631 0.0898623 0.0251939 0.0126444 0.0289874
18 | 0.0152452 0.0199651 0.0132074 0.0233409 0.030481 0.0229981 0.0145562 0.0144918 0.0224842
19 | 0.363074 -0.372596 -0.622582 0.137781 0.79348 0.451685 -0.2065 0.619659 0.150917
20 | 0.764614 -0.193784 -1.16842 0.283389 1.14608 1.19075 -0.617145 0.161704 0.144741
21 | 0.530155 -0.27583 -0.540513 0.0911176 0.632953 0.448073 -0.43841 0.366114 0.0877896
22 | 0.515078 -0.366387 -0.940781 0.232304 1.06029 0.821276 -0.279965 0.476539 0.230442
23 | 0.314098 -0.410848 -0.302712 -0.0575113 0.411066 0.194358 -0.130819 0.677469 0.177394
24 | 0.288838 0.127026 0.191728 0.216489 0.17592
25 | 0.00416017 0.0144403 0.00849072 0.0100371 0.0209229 0.0139464 7.40093e-05 0.0256097 0.0041528
26 | 0.00692202 0.00897028 0.0481703 0.0250189 0.209415 0.0869749 2.14762e-05 0.0241996 0.00692406
27 | 0.00644034 0.0132445 0.0438229 0.0221977 0.0655353 0.114342 6.61175e-05 0.0224242 0.0064378
28 | 0.0555328 0.042701 0.311197 0.0605234 0.330936 1.00043 0.0092768 0.0875441 0.057176
29 | 0.00695217 0.0206648 0.00817966 0.0136203 0.0182913 0.0136939 3.53137e-05 0.0237944 0.00693021
30 | 0.394356 0.509785 -0.554344 0.124304 0.635004 0.473684 -0.992665 -0.344988 -0.605484
31 | 0.327123 0.479743 -0.851251 0.170694 1.12427 0.57823 -0.996442 -0.268476 -0.672745
32 | 0.561281 0.447368 -0.706288 0.142201 0.697138 0.715438 -0.994889 -0.448858 -0.438695
33 | 0.530929 0.400142 -0.993652 0.144152 0.871201 1.1161 -0.947414 -0.21008 -0.423558
34 | 0.29066 0.483209 -0.331066 0.0143939 0.40378 0.258352 -0.994437 -0.255033 -0.709083
35 | 0.321126 0.149946 0.197312 0.0531342 0.278482
36 | 0.00877008 0.00682758 0.0945141 1.81377 0.799243 1.09448 0.0110191 0.00877008 0.00505034
37 | 0.00416901 0.00432588 0.00555767 0.310816 0.0172927 0.0265241 0.00382397 0.00416901 0.00680665
38 | 0.0239008 0.0174781 0.0628267 1.17046 0.24055 0.297461 0.0260537 0.0366781 0.0342021
39 | 0.00534745 0.0172469 0.015744 0.979295 0.0649992 0.0831585 0.00708846 0.00535608 0.00272675
40 | 0.00746677 0.0117582 0.00723016 0.0874107 0.0148005 0.0277919 0.00458986 0.00746677 0.0132412
41 | 0.579844 -0.662653 0.054634 -1.93479 0.759049 -0.868317 0.308506 0.420156 0.881954
42 | 0.520092 -0.310529 -0.0247561 -0.757472 -0.143297 0.192809 0.0996578 0.479908 0.616369
43 | 0.626503 -0.277981 -0.130995 -1.21765 -0.296303 0.558293 0.0276018 0.360311 0.650138
44 | 0.771504 -0.525694 -0.0108321 -1.29866 0.151349 -0.129685 0.138743 0.228479 0.90407
45 | 0.238862 -0.48239 -0.0176388 -0.594242 0.00578284 0.0294948 0.0981891 0.761138 0.332962
46 | 0.17711 0.323635 0.110824 0.287623 0.100808
47 | 0.00456953 0.014898 0.0179596 0.868124 0.0261201 0.0543883 0.00179963 0.00124693 0.00654775
48 | 0.0129368 0.00724917 0.0143949 0.198237 0.0327926 0.043634 0.00889696 0.00600127 0.021581
49 | 0.00308949 0.0103752 0.011871 0.832984 0.0197477 0.035784 0.0206501 0.00362518 0.0161138
50 | 0.030959 0.0298858 0.135843 2.08635 0.0898216 0.389771 0.0194944 0.0146531 0.0482674
51 | 0.00475755 0.0169366 0.024385 1.38767 0.0368425 0.0799561 0.000944127 0.00087138 0.0047204
52 | 0.632769 -0.108718 -0.213422 -1.52021 0.59879 -0.171946 -0.678616 0.304422 -0.0491304
53 | 0.510484 -0.187248 -0.191699 -0.883437 0.603435 -0.220038 -0.518879 0.421686 -0.0126336
54 | 0.812849 -0.0800241 -0.155431 -1.75566 0.429507 -0.118646 -0.70112 0.175381 0.108576
55 | 0.632944 -0.0152174 -0.0677986 -2.92811 0.635803 -0.500205 -0.709891 0.241568 -0.0821234
56 | 0.70463 -0.0262242 -0.218145 -2.13502 0.576373 -0.140083 -0.793266 0.20121 -0.0923016
57 | 0.24826 0.266405 0.243034 0.0933728 0.148928
58 | 0.00786919 0.0102346 0.0270097 0.10339 0.00603527 0.0910677 0.00591163 0.0146196 0.012015
59 | 0.00733458 0.00576684 0.0132222 0.053173 0.00452787 0.0446252 0.00949105 0.0099381 0.00616056
60 | 0.00332344 0.00334341 0.0204401 0.0517023 0.0188001 0.0550334 0.00337059 0.0048259 0.0030544
61 | 0.0018621 0.0066091 0.0110949 0.0415123 0.00531947 0.0404361 0.00601645 0.00610832 0.00610636
62 | 0.0151138 0.00159216 0.00885645 0.115227 0.0206761 0.0203693 0.00292855 0.00346035 0.00906875
63 | 0.305245 0.3179 1.06157 -2.31918 -0.0453983 -2.07774 -0.941775 0.00133904 -0.646647
64 | 0.234649 0.093974 0.798506 -1.76711 -0.0250409 -1.57197 -0.707962 0.283856 -0.481494
65 | 0.262252 0.281145 0.682458 -1.56305 -0.0506481 -1.31427 -0.90568 0.0789939 -0.653442
66 | 0.194612 0.100877 0.472739 -1.16295 0.0465906 -0.992069 -0.703561 0.288808 -0.51658
67 | 0.58627 -0.0425914 -0.167828 -0.875758 0.552609 -0.216952 -0.736717 0.252042 -0.156716
68 | 0.13359 0.284972 0.270771 0.226698 0.0839695
69 |
--------------------------------------------------------------------------------
/Config/Grammar/symbol.types:
--------------------------------------------------------------------------------
1 | 102
2 | | n
3 | - n
4 | ! n
5 | + n
6 | 0 m
7 | 1 m
8 | 2 m
9 | 3 m
10 | 4 m
11 | 5 m
12 | 6 m
13 | 7 m
14 | 8 m
15 | 9 m
16 | a n
17 | A m
18 | \alpha n
19 | b a
20 | B m
21 | \beta d
22 | c n
23 | C m
24 | comma n
25 | \cos n
26 | d a
27 | \Delta n
28 | \div n
29 | dbar n
30 | dot n
31 | dots n
32 | e n
33 | E m
34 | equal n
35 | \exists n
36 | f a
37 | F m
38 | \forall n
39 | g d
40 | G m
41 | \gamma n
42 | \geq n
43 | \gt n
44 | h a
45 | H m
46 | i n
47 | I m
48 | \in n
49 | \infty n
50 | \int n
51 | j d
52 | k n
53 | l a
54 | L m
55 | \lambda a
56 | \leq n
57 | \lim a
58 | \log n
59 | lbrace n
60 | lbracket n
61 | lpar m
62 | \lt n
63 | m n
64 | M m
65 | \mu d
66 | n n
67 | N m
68 | \neq n
69 | o n
70 | p d
71 | P m
72 | \phi n
73 | \pi n
74 | \pm n
75 | \prime n
76 | q d
77 | r n
78 | R m
79 | \rightarrow n
80 | rbrace n
81 | rbracket n
82 | rpar m
83 | s n
84 | S m
85 | \sigma n
86 | \sin n
87 | \sqrt m
88 | \sum n
89 | t a
90 | T m
91 | \tan a
92 | \tg n
93 | \theta n
94 | \times n
95 | u n
96 | v n
97 | V m
98 | w n
99 | x n
100 | X m
101 | y d
102 | Y m
103 | z n
104 |
--------------------------------------------------------------------------------
/Config/SymRec/off.mav:
--------------------------------------------------------------------------------
1 | 7.02993124128 3.52505419111 2.40995287827 15.6933348012 25.9197746971 0.23328943032 -0.258304657176 2.39074069548 5.09417326893
2 | 6.33958932556 3.52067357357 2.51277605056 13.8040159364 14.0999303426 4.40930100559 4.41952702215 1.2427974007 6.27785917011
3 |
--------------------------------------------------------------------------------
/Config/SymRec/on.mav:
--------------------------------------------------------------------------------
1 | 172.117024448 50.2455044567 0.210231937573 0.22706088601 0.00253827353868 0.00101277453039 -0.00624285481303
2 | 992.792362035 34.5984455584 0.652141168602 0.691247480093 0.144491332862 0.154175388881 0.163523232241
3 |
--------------------------------------------------------------------------------
/Config/SymRec/segmentation.gmm:
--------------------------------------------------------------------------------
1 | 2 4 5
2 | 0.50 0.50
3 | 0.033161 0.0786581 0.392137 0.137392
4 | 0.0365729 0.0731591 0.0871862 0.0876254
5 | 0.0222252 0.0493807 0.0393027 0.0134685
6 | 0.0554554 0.298172 1.73159 0.074029
7 | 0.243548 1.54521 13.7089 0.397415
8 | 0.488604 0.598039 0.981182 0.622963
9 | 0.837157 1.24887 0.460718 0.396426
10 | 0.422674 0.748496 0.303515 0.159743
11 | 0.597509 1.12518 2.82888 0.455837
12 | 1.02212 1.85958 4.31523 0.908786
13 | 0.281137 0.220711 0.25993 0.152835 0.0853858
14 | 0.00040065 0.00164303 0.0186928 0.0017177
15 | 0.00257013 0.0449728 0.00873153 0.0022907
16 | 0.0761435 0.233879 0.436473 0.162027
17 | 0.016679 0.0112306 0.0737718 0.0313773
18 | 1.20403e-06 4.51055 16.0136 0.568196
19 | 0.0306131 0.0551428 0.15828 0.052466
20 | 0.0653452 0.301276 0.12245 0.0623376
21 | 0.395353 0.589039 0.72823 0.509573
22 | 0.157565 0.134665 0.321965 0.303616
23 | 4.90522e-05 1.13667 3.36801 0.723376
24 | 0.234553 0.17369 0.18201 0.395828 0.0139184
25 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CC=g++
2 | LINK=-lxerces-c -lm
3 | FLAGS = -O3 -Wno-unused-result #-I/path/to/boost/
4 |
5 | OBJFEAS=symfeatures.o featureson.o online.o
6 | OBJMUESTRA=sample.o stroke.o
7 | OBJPARSE=seshat.o meparser.o gparser.o grammar.o production.o symrec.o duration.o segmentation.o sparel.o gmm.o
8 | OBJTABLA=tablecyk.o cellcyk.o hypothesis.o logspace.o
9 | OBJRNNLIB=Random.o DataExporter.o WeightContainer.o ClassificationLayer.o Layer.o Mdrnn.o Optimiser.o
10 | RNNLIBHEADERS=rnnlib4seshat/DataSequence.hpp rnnlib4seshat/NetcdfDataset.hpp rnnlib4seshat/Mdrnn.hpp rnnlib4seshat/MultilayerNet.hpp rnnlib4seshat/Rprop.hpp rnnlib4seshat/SteepestDescent.hpp rnnlib4seshat/Trainer.hpp rnnlib4seshat/WeightContainer.hpp
11 | OBJS=$(OBJFEAS) $(OBJMUESTRA) $(OBJPARSE) $(OBJTABLA) $(OBJRNNLIB)
12 |
13 | seshat: $(OBJS)
14 | $(CC) -o seshat $(OBJS) $(FLAGS) $(LINK)
15 |
16 | seshat.o: seshat.cc grammar.o sample.o meparser.o
17 | $(CC) -c seshat.cc $(FLAGS)
18 |
19 | production.o: production.h production.cc symrec.o
20 | $(CC) -c production.cc $(FLAGS)
21 |
22 | grammar.o: grammar.h grammar.cc production.o gparser.o symrec.o
23 | $(CC) -c grammar.cc $(FLAGS)
24 |
25 | meparser.o: meparser.h meparser.cc grammar.o production.o symrec.o tablecyk.o cellcyk.o logspace.o duration.o segmentation.o sparel.o sample.o hypothesis.o
26 | $(CC) -c meparser.cc $(FLAGS)
27 |
28 | gparser.o: gparser.h gparser.cc
29 | $(CC) -c gparser.cc $(FLAGS)
30 |
31 | sample.o: sample.h sample.cc tablecyk.o cellcyk.o stroke.o grammar.o
32 | $(CC) -c sample.cc $(FLAGS)
33 |
34 | symrec.o: symrec.h symrec.cc symfeatures.o $(RNNLIBHEADERS)
35 | $(CC) -c symrec.cc $(FLAGS)
36 |
37 | duration.o: duration.h duration.cc symrec.o
38 | $(CC) -c duration.cc $(FLAGS)
39 |
40 | segmentation.o: segmentation.h segmentation.cc cellcyk.o sample.o gmm.o
41 | $(CC) -c segmentation.cc $(FLAGS)
42 |
43 | tablecyk.o: tablecyk.h tablecyk.cc cellcyk.o hypothesis.o
44 | $(CC) -c tablecyk.cc $(FLAGS)
45 |
46 | cellcyk.o: cellcyk.h cellcyk.cc hypothesis.o
47 | $(CC) -c cellcyk.cc $(FLAGS)
48 |
49 | hypothesis.o: hypothesis.h hypothesis.cc production.o grammar.o
50 | $(CC) -c hypothesis.cc $(FLAGS)
51 |
52 | logspace.o: logspace.h logspace.cc cellcyk.o
53 | $(CC) -c logspace.cc $(FLAGS)
54 |
55 | sparel.o: sparel.h sparel.cc hypothesis.o cellcyk.o gmm.o sample.o
56 | $(CC) -c sparel.cc $(FLAGS)
57 |
58 | gmm.o: gmm.cc gmm.h
59 | $(CC) -c gmm.cc $(FLAGS)
60 |
61 | stroke.o: stroke.cc stroke.h
62 | $(CC) -c stroke.cc $(FLAGS)
63 |
64 | symfeatures.o: symfeatures.cc online.o featureson.o
65 | $(CC) -c symfeatures.cc $(FLAGS)
66 |
67 | featureson.o: featureson.cc featureson.h online.o
68 | $(CC) -c featureson.cc $(FLAGS)
69 |
70 | online.o: online.cc online.h
71 | $(CC) -c online.cc $(FLAGS)
72 |
73 | #rnnlib4seshat
74 | Random.o: rnnlib4seshat/Random.cpp
75 | $(CC) -c rnnlib4seshat/Random.cpp $(FLAGS)
76 |
77 | DataExporter.o: rnnlib4seshat/DataExporter.cpp
78 | $(CC) -c rnnlib4seshat/DataExporter.cpp $(FLAGS)
79 |
80 | WeightContainer.o: rnnlib4seshat/WeightContainer.cpp
81 | $(CC) -c rnnlib4seshat/WeightContainer.cpp $(FLAGS)
82 |
83 | ClassificationLayer.o: rnnlib4seshat/ClassificationLayer.cpp
84 | $(CC) -c rnnlib4seshat/ClassificationLayer.cpp $(FLAGS)
85 |
86 | Layer.o: rnnlib4seshat/Layer.cpp
87 | $(CC) -c rnnlib4seshat/Layer.cpp $(FLAGS)
88 |
89 | Mdrnn.o: rnnlib4seshat/Mdrnn.cpp
90 | $(CC) -c rnnlib4seshat/Mdrnn.cpp $(FLAGS)
91 |
92 | Optimiser.o: rnnlib4seshat/Optimiser.cpp
93 | $(CC) -c rnnlib4seshat/Optimiser.cpp $(FLAGS)
94 |
95 | clean:
96 | rm -f *.o *~ \#*\#
97 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | ------------------------------------------------------------------------
2 | SESHAT - Handwritten math expression parser
3 | Copyright (C) 2014, Francisco Alvaro
4 | ------------------------------------------------------------------------
5 |
6 | More information at https://github.com/falvaro/seshat
7 |
8 | ----------------
9 | License: Seshat is released under the license GPLv3 (see LICENSE file)
10 |
11 | ----------------
12 | Requirements:
13 | - Compilation tools: makefile and g++
14 | - Xerces-c library for parsing XML.
15 | - Boost libraries for RNNLIB (must be in include path or it should be added
16 | in the FLAGS variable of Makefile file).
17 |
18 | ----------------
19 | Usage: ./seshat -c config -i input [-o output] [-r render.pgm]
20 |
21 | -c config: set the configuration file
22 | -i input: set the input math expression file
23 | -o output: save recognized expression to 'output' file (InkML format)
24 | -r render: save in 'render' the image representing the input expression (PGM format)
25 | -d graph: save in 'graph' the description of the recognized tree (DOT format)
26 |
27 | ----------------
28 | Example:
29 | There are two example math expressions in folder "SampleMathExps". The following command
30 | will recognize the expression (x+y)^2 encoded in "exp.scgink"
31 |
32 | $ ./seshat -c Config/CONFIG -i SampleMathExps/exp.scgink -o out.inkml -r render.pgm -d out.dot
33 |
34 | This command outputs several information through the standard output, where the last line will
35 | provide the LaTeX string of the recognized math expression.
36 |
37 | An image representation of the input strokes will be rendered in "render.pgm".
38 |
39 | The InkML file of the recognized math expression will be saved in "out.inkml".
40 |
41 | The derivation tree of the expression provided as a graph in DOT format will be saved in "out.dot".
42 | The representation of the graph in, for example, postscript format can be obtained as follows
43 |
44 | $ dot -o out.ps out.dot -Tps
45 |
46 | It should be noted that only options "-c" and "-i" are mandatory.
47 |
--------------------------------------------------------------------------------
/SampleMathExps/exp.scgink:
--------------------------------------------------------------------------------
1 | SCG_INK
2 | 8
3 | 27
4 | 78 54
5 | 80 55
6 | 80 57
7 | 82 58
8 | 83 60
9 | 85 63
10 | 86 65
11 | 89 68
12 | 91 70
13 | 96 75
14 | 100 78
15 | 104 82
16 | 108 86
17 | 112 90
18 | 113 94
19 | 117 98
20 | 121 101
21 | 125 105
22 | 128 109
23 | 132 111
24 | 136 113
25 | 140 115
26 | 144 119
27 | 145 121
28 | 147 122
29 | 148 122
30 | 149 122
31 | 24
32 | 136 64
33 | 134 66
34 | 133 68
35 | 131 71
36 | 130 73
37 | 128 77
38 | 124 82
39 | 120 87
40 | 117 93
41 | 113 98
42 | 109 104
43 | 105 108
44 | 103 112
45 | 102 115
46 | 99 117
47 | 97 119
48 | 96 121
49 | 94 123
50 | 93 124
51 | 92 124
52 | 92 125
53 | 92 126
54 | 91 126
55 | 91 127
56 | 20
57 | 188 87
58 | 190 87
59 | 192 88
60 | 194 88
61 | 196 88
62 | 199 88
63 | 202 88
64 | 205 88
65 | 210 89
66 | 214 89
67 | 219 89
68 | 226 89
69 | 233 89
70 | 238 89
71 | 244 89
72 | 249 89
73 | 253 89
74 | 254 89
75 | 255 89
76 | 256 89
77 | 85
78 | 297 65
79 | 297 66
80 | 298 68
81 | 298 71
82 | 299 73
83 | 301 75
84 | 302 79
85 | 304 85
86 | 306 90
87 | 309 95
88 | 311 101
89 | 313 106
90 | 317 112
91 | 321 113
92 | 325 115
93 | 329 116
94 | 331 116
95 | 334 116
96 | 336 116
97 | 338 116
98 | 340 116
99 | 342 115
100 | 344 114
101 | 345 112
102 | 346 110
103 | 347 109
104 | 347 107
105 | 347 105
106 | 347 103
107 | 347 102
108 | 346 100
109 | 345 99
110 | 345 98
111 | 344 97
112 | 343 96
113 | 342 95
114 | 341 95
115 | 341 97
116 | 341 99
117 | 341 102
118 | 341 106
119 | 341 111
120 | 341 116
121 | 341 121
122 | 341 126
123 | 341 131
124 | 341 137
125 | 341 141
126 | 341 143
127 | 340 145
128 | 340 146
129 | 340 148
130 | 340 150
131 | 340 151
132 | 340 153
133 | 340 154
134 | 339 155
135 | 339 156
136 | 338 157
137 | 337 157
138 | 336 157
139 | 334 155
140 | 332 154
141 | 332 152
142 | 331 150
143 | 330 147
144 | 329 145
145 | 329 142
146 | 329 140
147 | 329 138
148 | 330 136
149 | 330 135
150 | 331 133
151 | 333 132
152 | 335 132
153 | 336 131
154 | 338 130
155 | 340 130
156 | 342 130
157 | 344 130
158 | 345 130
159 | 347 130
160 | 348 130
161 | 349 130
162 | 349 131
163 | 44
164 | 69 45
165 | 68 46
166 | 67 48
167 | 66 49
168 | 64 51
169 | 63 53
170 | 62 55
171 | 61 57
172 | 59 60
173 | 58 62
174 | 58 64
175 | 56 67
176 | 55 68
177 | 55 70
178 | 54 72
179 | 54 75
180 | 54 77
181 | 53 79
182 | 53 81
183 | 53 84
184 | 53 86
185 | 53 89
186 | 53 92
187 | 53 94
188 | 54 97
189 | 55 98
190 | 56 100
191 | 56 102
192 | 56 103
193 | 58 105
194 | 58 107
195 | 59 108
196 | 59 110
197 | 60 111
198 | 61 113
199 | 63 114
200 | 64 116
201 | 65 117
202 | 65 120
203 | 66 121
204 | 67 122
205 | 67 123
206 | 68 123
207 | 69 124
208 | 52
209 | 361 45
210 | 361 46
211 | 362 47
212 | 363 48
213 | 364 49
214 | 365 51
215 | 366 53
216 | 368 55
217 | 369 57
218 | 370 59
219 | 372 60
220 | 373 63
221 | 374 66
222 | 375 68
223 | 375 70
224 | 377 73
225 | 378 75
226 | 379 77
227 | 379 80
228 | 379 82
229 | 379 84
230 | 379 86
231 | 379 88
232 | 379 89
233 | 379 91
234 | 379 93
235 | 379 95
236 | 379 97
237 | 379 99
238 | 379 101
239 | 379 103
240 | 378 104
241 | 377 106
242 | 375 108
243 | 375 109
244 | 374 110
245 | 373 111
246 | 372 113
247 | 372 115
248 | 371 117
249 | 370 119
250 | 369 120
251 | 368 121
252 | 368 122
253 | 367 122
254 | 366 123
255 | 365 123
256 | 364 123
257 | 364 124
258 | 363 124
259 | 362 124
260 | 362 125
261 | 69
262 | 395 19
263 | 396 19
264 | 397 19
265 | 398 18
266 | 399 17
267 | 401 17
268 | 402 17
269 | 404 17
270 | 406 17
271 | 407 17
272 | 410 17
273 | 412 17
274 | 414 17
275 | 416 18
276 | 418 18
277 | 419 18
278 | 420 19
279 | 421 20
280 | 421 21
281 | 421 22
282 | 421 23
283 | 421 24
284 | 420 26
285 | 419 27
286 | 419 29
287 | 417 31
288 | 416 32
289 | 415 32
290 | 413 33
291 | 412 33
292 | 411 34
293 | 409 34
294 | 408 34
295 | 407 34
296 | 405 34
297 | 404 34
298 | 403 34
299 | 402 34
300 | 401 34
301 | 400 34
302 | 400 33
303 | 399 33
304 | 399 32
305 | 399 31
306 | 400 31
307 | 401 31
308 | 402 31
309 | 403 32
310 | 405 33
311 | 406 34
312 | 408 34
313 | 409 35
314 | 410 35
315 | 411 36
316 | 413 36
317 | 415 37
318 | 417 37
319 | 419 38
320 | 420 38
321 | 421 38
322 | 423 39
323 | 424 39
324 | 425 39
325 | 426 39
326 | 427 39
327 | 428 39
328 | 429 39
329 | 430 39
330 | 431 39
331 | 36
332 | 221 52
333 | 222 52
334 | 222 53
335 | 222 54
336 | 222 57
337 | 223 59
338 | 223 61
339 | 223 63
340 | 223 66
341 | 223 68
342 | 223 71
343 | 223 73
344 | 223 76
345 | 223 79
346 | 223 83
347 | 223 86
348 | 223 89
349 | 223 92
350 | 223 96
351 | 223 99
352 | 223 101
353 | 223 103
354 | 223 104
355 | 223 106
356 | 223 107
357 | 223 108
358 | 223 110
359 | 223 111
360 | 223 112
361 | 223 113
362 | 223 114
363 | 223 115
364 | 223 116
365 | 223 117
366 | 224 118
367 | 225 118
368 |
--------------------------------------------------------------------------------
/cellcyk.cc:
--------------------------------------------------------------------------------
1 | /*Copyright 2014 Francisco Alvaro
2 |
3 | This file is part of SESHAT.
4 |
5 | SESHAT is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | SESHAT is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with SESHAT. If not, see .
17 | */
18 | #include "cellcyk.h"
19 | #include
20 |
21 | CellCYK::CellCYK(int n, int ncc) {
22 | sig = NULL;
23 | nnt = n;
24 | nc = ncc;
25 | talla = 0;
26 |
27 | //Create (empty) hypotheses
28 | noterm = new Hypothesis*[nnt];
29 | for(int i=0; iccc[i] || B->ccc[i] ) ? true : false;
70 | }
71 |
72 | //Check if cell H covers the same strokes that this
73 | bool CellCYK::ccEqual(CellCYK *H) {
74 | if( talla != H->talla )
75 | return false;
76 |
77 | for(int i=0; iccc[i] )
79 | return false;
80 |
81 | return true;
82 | }
83 |
84 | //Check if the intersection between the strokes of this cell and H is empty
85 | bool CellCYK::compatible(CellCYK *H) {
86 | for(int i=0; iccc[i] )
88 | return false;
89 |
90 | return true;
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/cellcyk.h:
--------------------------------------------------------------------------------
1 | /*Copyright 2014 Francisco Alvaro
2 |
3 | This file is part of SESHAT.
4 |
5 | SESHAT is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | SESHAT is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with SESHAT. If not, see .
17 | */
18 | #ifndef _CELLCYK_
19 | #define _CELLCYK_
20 |
21 | struct Hypothesis;
22 |
23 | #include
24 | #include "hypothesis.h"
25 |
26 | using namespace std;
27 |
28 | struct CellCYK{
29 | //Bounding box spatial region coordinates
30 | int x,y; //top-left
31 | int s,t; //bottom-right
32 |
33 | //Hypotheses for every non-terminals
34 | int nnt;
35 | Hypothesis **noterm;
36 |
37 | //Strokes covered in this cell
38 | int nc;
39 | bool *ccc;
40 | int talla; //total number of strokes
41 |
42 | //Next cell in linked list (CYK table of same size)
43 | CellCYK *sig;
44 |
45 |
46 | //Methods
47 | CellCYK(int n, int ncc);
48 | ~CellCYK();
49 |
50 | bool operator<(const CellCYK &C);
51 | void ccUnion(CellCYK *A, CellCYK *B);
52 | bool ccEqual(CellCYK *H);
53 | bool compatible(CellCYK *H);
54 | };
55 |
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/duration.cc:
--------------------------------------------------------------------------------
1 | /*Copyright 2014 Francisco Alvaro
2 |
3 | This file is part of SESHAT.
4 |
5 | SESHAT is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | SESHAT is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with SESHAT. If not, see .
17 | */
18 | #include "duration.h"
19 |
20 |
21 | DurationModel::DurationModel(char *str, int mxs, SymRec *sr) {
22 | FILE *fd = fopen(str,"r");
23 | if( !fd ) {
24 | fprintf(stderr, "Error loading duration model '%s'\n", str);
25 | exit(-1);
26 | }
27 |
28 | max_strokes = mxs;
29 | Nsyms = sr->getNClases();
30 |
31 | duration_prob = new float*[Nsyms];
32 | for(int i=0; ikeyClase(str) ][nums-1] = count;
51 | }
52 |
53 | //Compute probabilities
54 | for(int i=0; i.
17 | */
18 | #ifndef _DURATION_MODEL_
19 | #define _DURATION_MODEL_
20 |
21 | #include
22 | #include
23 | #include "symrec.h"
24 |
25 | using namespace std;
26 |
27 | class DurationModel{
28 | int max_strokes;
29 | int Nsyms;
30 | float **duration_prob;
31 |
32 | void loadModel(FILE *fd, SymRec *sr);
33 |
34 | public:
35 | DurationModel(char *str, int mxs, SymRec *sr);
36 | ~DurationModel();
37 |
38 | float prob(int symclas, int size);
39 | };
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/featureson.h:
--------------------------------------------------------------------------------
1 | /*Copyright 2014 Francisco Alvaro
2 |
3 | This file is part of SESHAT.
4 |
5 | SESHAT is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | SESHAT is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with SESHAT. If not, see .
17 |
18 | This file is a modification of the online features original software
19 | covered by the following copyright and permission notice:
20 |
21 | */
22 | /*
23 | Copyright (C) 2006,2007 Moisés Pastor
24 |
25 | This program is free software: you can redistribute it and/or modify
26 | it under the terms of the GNU General Public License as published by
27 | the Free Software Foundation, either version 3 of the License, or
28 | (at your option) any later version.
29 |
30 | This program is distributed in the hope that it will be useful,
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 | GNU General Public License for more details.
34 |
35 | You should have received a copy of the GNU General Public License
36 | along with this program. If not, see .
37 | */
38 | #ifndef FEATURES_H
39 | #define FEATURES_H
40 |
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include "online.h"
47 |
48 | #define MAXNUMHATS 200
49 | #define OFFSET_INS 20
50 |
51 | using namespace std;
52 |
53 | class frame {
54 | public:
55 | double x,y,dx,dy,ax,ay,k;
56 |
57 | void print(ostream & fd);
58 | int get_fr_dim();
59 |
60 | double getFea(int i){
61 | switch (i){
62 | case 0: return x;
63 | case 1: return y;
64 | case 2: return dx;
65 | case 3: return dy;
66 | case 4: return ax;
67 | case 5: return ay;
68 | case 6: return k;
69 | default:
70 | fprintf(stderr, "Error: getFea(%d)\n", i);
71 | exit(-1);
72 | }
73 | }
74 | };
75 |
76 | class sentenceF {
77 | public:
78 | string transcrip;
79 | int n_frames;
80 | frame * frames;
81 |
82 | sentenceF();
83 | ~sentenceF();
84 |
85 | bool data_plot(ostream & fd);
86 | bool print(ostream & fd);
87 |
88 | void calculate_features(sentence &s);
89 |
90 | private:
91 | vector normalizaAspect(vector & puntos);
92 | void calculate_derivatives(vector & points, bool norm=true);
93 | void calculate_kurvature();
94 | };
95 |
96 |
97 | #endif
98 |
--------------------------------------------------------------------------------
/gmm.cc:
--------------------------------------------------------------------------------
1 | /*Copyright 2014 Francisco Alvaro
2 |
3 | This file is part of SESHAT.
4 |
5 | SESHAT is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | SESHAT is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with SESHAT. If not, see .
17 | */
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include "gmm.h"
23 |
24 | #define PI 3.14159265359
25 |
26 | using namespace std;
27 |
28 | GMM::GMM( char *model ) {
29 | loadModel( model );
30 | }
31 |
32 | void GMM::loadModel( char *str ) {
33 | FILE *fd = fopen(str, "r");
34 | if( !fd ) {
35 | fprintf(stderr, "Error loading GMM model file '%s'\n", str);
36 | exit(-1);
37 | }
38 |
39 | //Read parameters
40 | fscanf(fd, "%d %d %d", &C, &D, &G);
41 |
42 | //Read prior probabilities
43 | prior = new float[C];
44 | for(int i=0; i.
17 | */
18 | #ifndef __GMM__
19 | #define __GMM__
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 |
27 | class GMM{
28 | int C, D, G;
29 | float **invcov, **mean, **weight, *prior, *det;
30 |
31 | void loadModel( char *str );
32 | float pdf(int c, float *v);
33 |
34 | public:
35 |
36 | GMM(char *model);
37 | ~GMM();
38 |
39 | void posterior(float *x, float *pr);
40 | };
41 |
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/gparser.cc:
--------------------------------------------------------------------------------
1 | /*Copyright 2014 Francisco Alvaro
2 |
3 | This file is part of SESHAT.
4 |
5 | SESHAT is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | SESHAT is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with SESHAT. If not, see .
17 | */
18 | #include "gparser.h"
19 | #include
20 | #include
21 |
22 | #define SIZE 1024
23 |
24 | gParser::gParser(Grammar *gram, FILE *fd, char *path) {
25 | g = gram;
26 |
27 | int n = strlen(path);
28 |
29 | if( n > 0 ) {
30 | pre = new char[n+1];
31 | strcpy(pre, path);
32 | }
33 | else {
34 | pre = new char[1];
35 | pre[0] = 0;
36 | }
37 |
38 | parse( fd );
39 | }
40 |
41 | gParser::~gParser() {
42 | delete[] pre;
43 | }
44 |
45 | bool gParser::isFillChar(char c) {
46 | switch(c) {
47 | case ' ':
48 | case '\t':
49 | case '\n':
50 | case '\r':
51 | return true;
52 | default:
53 | return false;
54 | }
55 | }
56 |
57 | int gParser::split(char *str,char ***res){
58 | char tokensaux[2*SIZE];
59 | int n=0, i=0, j=0;
60 |
61 | while( isFillChar(str[i]) ) i++;
62 |
63 | while( str[i] ) {
64 | if( str[i] == '\"' ) {
65 | i++;
66 | while( str[i] && str[i] != '\"' ) {
67 | tokensaux[j] = str[i];
68 | i++; j++;
69 | }
70 | i++;
71 | }
72 | else {
73 | while( str[i] && !isFillChar(str[i]) ) {
74 | tokensaux[j] = str[i];
75 | i++; j++;
76 | }
77 | }
78 | tokensaux[j++] = 0;
79 | n++;
80 | while( str[i] && isFillChar(str[i]) ) i++;
81 | }
82 |
83 | char **toks=new char*[n];
84 | for(i=0, j=0; iaddNoTerminal(tok1);
119 | }
120 |
121 | //Read start symbol(s) of the grammar
122 | while( nextLine(fd, linea) && strcmp(linea, "PTERM\n") ) {
123 | sscanf(linea, "%s", tok1);
124 | g->addInitSym(tok1);
125 | }
126 |
127 | //Read terminal productions
128 | while( nextLine(fd, linea) && strcmp(linea, "PBIN\n") ) {
129 | float pr;
130 |
131 | sscanf(linea, "%f %s %s %s", &pr, tok1, tok2, aux);
132 |
133 | g->addTerminal(pr, tok1, tok2, aux);
134 | }
135 |
136 | //Read binary productions
137 | while( nextLine(fd, linea) ) {
138 | char **tokens;
139 | int ntoks = split(linea, &tokens);
140 |
141 | if( ntoks != 7 ) {
142 | fprintf(stderr, "Error: Grammar not valid (PBIN)\n");
143 | exit(-1);
144 | }
145 |
146 | if( !strcmp(tokens[1], "H") )
147 | g->addRuleH(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
148 | else if( !strcmp(tokens[1], "V") )
149 | g->addRuleV(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
150 | else if( !strcmp(tokens[1], "Ve") )
151 | g->addRuleVe(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
152 | else if( !strcmp(tokens[1], "Sup") )
153 | g->addRuleSup(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
154 | else if( !strcmp(tokens[1], "Sub") )
155 | g->addRuleSub(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
156 | else if( !strcmp(tokens[1], "SSE") )
157 | g->addRuleSSE(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
158 | else if( !strcmp(tokens[1], "Ins") )
159 | g->addRuleIns(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
160 | else if( !strcmp(tokens[1], "Mrt") )
161 | g->addRuleMrt(atof(tokens[0]), tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]);
162 | else {
163 | fprintf(stderr, "Error: Binary rule type '%s' nor valid\n", tokens[1]);
164 | exit(-1);
165 | }
166 |
167 | //Free memory
168 | for(int j=0; j.
17 | */
18 | #ifndef _G_PARSER_
19 | #define _G_PARSER_
20 |
21 | struct Grammar;
22 |
23 | #include
24 | #include
25 | #include "grammar.h"
26 |
27 | class gParser{
28 | Grammar *g;
29 | char *pre;
30 |
31 | bool isFillChar(char c);
32 | int split(char *str,char ***res);
33 | bool nextLine(FILE *fd, char *lin);
34 | void solvePath(char *in, char *out);
35 | public:
36 | gParser(Grammar *gram, FILE *fd, char *path);
37 | ~gParser();
38 |
39 | void parse(FILE *fd);
40 | };
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/grammar.h:
--------------------------------------------------------------------------------
1 | /*Copyright 2014 Francisco Alvaro
2 |
3 | This file is part of SESHAT.
4 |
5 | SESHAT is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | SESHAT is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with SESHAT. If not, see .
17 | */
18 | #ifndef _GRAMMAR_
19 | #define _GRAMMAR_
20 |
21 | class gParser;
22 |
23 | #include
24 | #include
25 | #include