11<?php
22
3- namespace Model \Math ;
3+ declare (strict_types=1 );
4+
5+ namespace Mathematicator ;
6+
47
58use Mathematicator \Engine \QueryNormalizer ;
9+ use Mathematicator \Search \TextRenderer ;
610use Mathematicator \Tokenizer \Tokenizer ;
711use Nette \Utils \Strings ;
8- use Texy \Texy ;
912
1013class NaturalTextFormatter
1114{
1215
1316 /**
14- * @var Texy
17+ * @var string[]
1518 */
16- private $ texy ;
19+ private static $ allowedFunctions = [
20+ 'sin ' ,
21+ 'cos ' ,
22+ 'tan ' ,
23+ 'cotan ' ,
24+ 'tg ' ,
25+ 'log\d* ' ,
26+ 'sqrt ' ,
27+ ];
1728
1829 /**
1930 * @var QueryNormalizer
@@ -26,21 +37,11 @@ class NaturalTextFormatter
2637 private $ tokenizer ;
2738
2839 /**
29- * @var string[]
40+ * @param QueryNormalizer $queryNormalizer
41+ * @param Tokenizer $tokenizer
3042 */
31- private $ allowedFunctions = [
32- 'sin ' ,
33- 'cos ' ,
34- 'tan ' ,
35- 'cotan ' ,
36- 'tg ' ,
37- 'log\d* ' ,
38- 'sqrt ' ,
39- ];
40-
41- public function __construct (Texy $ texy , QueryNormalizer $ queryNormalizer , Tokenizer $ tokenizer )
43+ public function __construct (QueryNormalizer $ queryNormalizer , Tokenizer $ tokenizer )
4244 {
43- $ this ->texy = $ texy ;
4445 $ this ->queryNormalizer = $ queryNormalizer ;
4546 $ this ->tokenizer = $ tokenizer ;
4647 }
@@ -63,7 +64,7 @@ public function formatNaturalText(string $text): string
6364
6465 $ return .= '<div class="latex"><p>\( ' . $ latex . '\)</p><code> ' . $ line . '</code></div> ' ;
6566 } else {
66- $ return .= $ this -> texy -> process ($ line ) . "\n\n" ;
67+ $ return .= TextRenderer:: process ($ line ) . "\n\n" ;
6768 }
6869 }
6970 }
@@ -79,10 +80,10 @@ private function containsWords(string $text): bool
7980 {
8081 $ words = 0 ;
8182
82- $ text = preg_replace ('/\s+/ ' , ' ' , Strings::toAscii (Strings::lower ($ text )));
83+ $ text = ( string ) preg_replace ('/\s+/ ' , ' ' , Strings::toAscii (Strings::lower ($ text )));
8384
8485 while (true ) {
85- $ newText = preg_replace ('/([a-z0-9]{2,})\s+([a-z0-9]{1,})(\s+|[:.!?,]|$)/ ' , '$1$2 ' , $ text );
86+ $ newText = ( string ) preg_replace ('/([a-z0-9]{2,})\s+([a-z0-9]{1,})(\s+|[:.!?,]|$)/ ' , '$1$2 ' , $ text );
8687 if ($ newText === $ text ) {
8788 break ;
8889 }
@@ -110,7 +111,7 @@ private function containsWords(string $text): bool
110111 */
111112 private function wordInAllowedFunctions (string $ word ): bool
112113 {
113- foreach ($ this -> allowedFunctions as $ allowedFunction ) {
114+ foreach (self :: $ allowedFunctions as $ allowedFunction ) {
114115 if (preg_match ('/^ ' . $ allowedFunction . '$/ ' , $ word )) {
115116 return true ;
116117 }
0 commit comments