java – Separate sentences in paragraph that doesn’t have punctuation

How can I separate sentences in paragraph that doesn’t have punctuation?

For example, I have this paragraph:

The red glint of paint sparkled under the sun he had dreamed of
owning this car since he was ten and that dream had become a reality
less than a year ago it was his baby and he spent hours caring for
it pampering it and fondling over it she knew this all too well
and that’s exactly why she had taken a sludge hammer to it

I need the output to be something like this:

The red glint of paint sparkled under the sun. He had dreamed of
owning this car since he was ten and that dream had become a reality
less than a year ago. It was his baby and he spent hours caring for
it pampering it and fondling over it. She knew this all too well
and that’s exactly why she had taken a sludge hammer to it.

I just need to add punctuations to separate the sentences int the paragraph, I don’t need to add commas.

Is there any ideas or keywords that would help me with this problem?

No idea for CFG for those sentences

My goal is to find a grammar containing no more than four productions which:

  • Can generate words ${a, bab, cbcab, bacbc, bbacbc, cbbcabccb}$
  • Can’t generate words ${aa, ab, ba, aba, bcbacbc, cbcabcb}$

My current solution for this is:

S -> NaN
N -> bN
N -> cNcN
N -> λ

Sadly it can generate $ab$ and $ba$ and I don’t know how can I modify it to obtain only $4$ productions.

Finding a complete theory which contains the theory of sentences that hold for every finite field.

I am trying to make some exercises for a introductory course to mathematical logic.

Let $T$ be the theory consisting of all sentences that are true in every finite field. It is not that hard to see that this is a consistent, but not a complete theory. I am being asked to give a concrete example of theory which contains $T$, but which is complete.

I know that I will need to add a sentence for every cardinality, but I am unsure if this is enough to make the theory complete. If it is not I do not know how to give a concrete theory which is even larger.

I also thought about taking the set of all sentences that are true in a specific model of $T$, but again I do not know how to show completeness.

formal languages – Number of sentences and sentential forms generated by a grammar

In this question, I’m considering only “finite grammars”. A finite grammar can only produce a finite number of distinct sentences. The following grammar is finite in my definition:

S         → AB
A         → B | a 
B         → a | b

It can only generate the following finite number of sentences: aa, ab, ba, bb

On the other hand, the following grammar is not finite:

S         → AB
A         → AA | B | a 
B         → a | b

Because it can create an infinite number of sentences: aa, aaa, aaaa, aaaaa, …

Now to the actual question. Suppose the following finite grammar:

S         → variable = math_expr
variable  → a | b | c 
math_expr → INT | function
function  → func_1() | func_2(INT, INT, INT, INT)
INT       → 1 | 2 | 3 | 4 | 5

I want to know if there is some kind of formula that calculate the number of sentences and sentential forms that can be generated by a finite grammar.

Example of sentences: b = func_2(2,4,3,3), a = func_1()

Example of sentential forms: b = func_2(2,2,INT,INT), c = math_expr, S

At the moment, I am able to know the number of sentences and sentential forms by applying a Breadth-First Search (BFS) starting from the S node.

However, because I’m working with search in program synthesis, it would be great to know the size of the domain without the need of applying an exhaustive search on it.

Question: How can I find the number of sentences and sentential forms given only an arbitrary finite grammar?

For the first finite grammar I showed here, the answer is easy to calculate by hand:

Sentences: aa, ab, ba, bb
Sentential forms: S, AB, BB, aB, bB, Aa, Ab

So the final answer would be 4 + 7 = 11

However, for the second finite grammar I showed, it is not that easy to calculate it.

PS.: In my original problem, I am working with program synthesis with a Domain Specific Language (DSL). I tagged CFG with the hope that the same applies, granted I’m not 100% sure.

javascript – How to write a simple script to read text from a file and compute the number of sentences, number of unique words and punctuation/symbols? (NodeJS)

I just finished a challenge (noted above) and I was wondering how good is this approach or is there some simpler solution that I am not aware of?

If you have a different solution, try to explain the code for people less experienced than myself rather just than pasting a solution.

Here is an example text file to be read from:

This file has eight words in this sentence.
There are two sentences. In this paragraph.

And two paragraphs in total.
Lorem ispsum.
Lorem ispsum.
Lorem ispsum.
Lorem ispsum.
/**
 * Write a simple script to read text from a file and compute (approximately) the number of sentences, number of unique words and punctuation/symbols.
 * Run the code with node ./problem-2.js test.txt 
 */

 // Use Node's builtin api to read a file
const fs = require('fs');

//#1 count the number of words
const wordCount = (string) => string.split(" ").length;

//#2 count the number of unique words
const uniqueWords = txt => new Set(txt.toLowerCase().match(/w+/g)).size;

//#3 count the number of paragraphs
const paragraphCount = (paragraphString) =>{
  //seperate each sentence into a seperate string 
  paragraphString = paragraphString.split("nn");
  // console.table(paragraphString) // show as a table for better visual
  let paragraphArray = paragraphString.length; // length of paragraph array

  let paragraphCount = 0;
  let strip_whitespace = /s+/gi;
  while (paragraphArray >=0) {
    paragraphArray--;
    let tmp = paragraphString(paragraphArray);
    tmp = tmp ? tmp .replace(strip_whitespace,"") : tmp;
      
    if( tmp && tmp.length > 1 ) paragraphCount++;
  }
  return paragraphCount;
}

function countPunctuations(punctuationsStrings) {
  let punctuationsCount = 0;
  const punctuations = (".", ",", "!", "?");
  // const symbols = ("~","`","!","@","#","$","%","^","&","*","(",")","_","+","-","=","{","}","|","(",")","",":",";","'","<",">","?","/",)
  for (const ch of punctuationsStrings) {
    if (punctuations.includes(ch)) punctuationsCount++;
  }
  return punctuationsCount;
}

fs.readFile("test-2.txt", 'utf8', function(err, data) {
  if (err) throw err;
  console.log("The text in the file:nn", data,"n")
  // store results in an object to present the log better
  let result={
    "word count": wordCount(data),
    "unique words": uniqueWords(data),
    "paragraph count": paragraphCount(data),
    "punctuation count": countPunctuations(data),
  }
  console.table(result)
});
```

logic – Which of these formulas are sentences?

Let V be the vocabulary {+,<,1,2,3} where + is an arbitrary function, < is a binary relation, and 1,2, and 3 are constants. We write (x+y) for +(x,y) and x<y for <(x,y). Consider the following V-formulas:

  1. ∀x∃y((x+y)=1)
  2. ∀x¬(x<1)
  3. ((1+1)=2)
  4. 2<1
  5. ∀x(2<1) →(x+2<x+1)
  6. ∀x∀y∃z(x+y=z)
  7. ∀x∀y∀z(((x+3=y)∧(x+3=z))->(y=z))
  8. ∀x∀y∀z(((x+y=3)∧(x+z=3))->(y=z))
  9. ∀x∀y(((x+3)<(y+3))->(x<y))
  10. ∀x∀y((x<2)->((x+3)=4))

Question: Which of these 10 formulas are sentences?
I have the following definitions from the book:
Definition. A vocabulary is a set of function, relation and constant symbols.
Definition. A sentence of first-order logic is a formula having no free variables.
In contrast to the free variables of a formula p, the bound variables of p are those that have quantifiers, (∃,∀).
I tried to interpret this information and it seems that the formulas 1-10 have no free variables and each of them is therefore a sentence. Is this right or wrong?

type theory – Moving between expressions in the typed lambda calculus and sentences in higher order logic

In ‘An Introduction to Mathematical Logic through Type Theory’, Andrews describes a way of translating sentences in higher order logic into lambda terms in his version of the typed lambda calculus (see §51.) I am wondering if there is a uniform, neat way to do the opposite – convert a lambda term $X$ in his system back into a sentence of higher order logic (I’m happy to restrict attention to cases in which $X$ has type $o$.)

Basically, I am trying to figure out whether every expression (of type $o$) in the version of the typed lambda calculus in question can be read as an ordinary sentence of higher order logic in a natural and uniform way.

Some more information on Andrews’ setup: he has constants $Q_{((o alpha) alpha)}$ for each type $alpha$ and a constant $iota_{(i(oi))}$. (Here $i$ is the type of individuals and $o$ the type of truth values.) He then defines:

$$begin{array}{lcl}
A_{alpha} = B_{alpha} & mbox{stands for} & Q_{((o alpha) alpha)} A_{alpha} B_{alpha} \
A_{o} leftrightarrow B_{o} & mbox{stands for} & Q_{((oo)o)} A B \
T_{o} & mbox{stands for} & Q_{((oo)o)}=Q_{((oo)o)} \
F_{o} & mbox{stands for} & lambda x_{o} T = lambda x_{o} x_{o} \
Pi_{(o(o alpha))} & mbox{stands for} & Q_{(o(o alpha)(o alpha))} lambda x_{alpha} T_o \
forall x_{alpha} A_o & mbox{stands for} & Pi_{(o(o alpha))} lambda x_{alpha} T_o \
wedge_{(o(oo))} & mbox{stands for} & lambda v_1 lambda v_2 (lambda x_{(o(oo))} (x_{(o(oo))}TT) = lambda x_{(o(oo))} (x_{(o(oo))} v_1 v_2)) \
A_o wedge B_o & mbox{stands for} & wedge_{(o(oo))} A_o B_o \
supset_{(o(oo))} & mbox{stands for} & lambda x_0 lambda y_0 (x_0 = (x_0 wedge y_0)) \
A_o supset B_o & mbox{stands for} & supset_{(o(oo))} A_o B_o \
neg_{(oo)} & mbox{stands for} & Q_{(o(oo))} F \
vee_{(o(oo))} & mbox{stands for} & lambda x_0 lambda y_0 neg((neg x_0) wedge (neg y_0)) \
A_o vee B_o & mbox{stands for} & vee_{(o(oo))} A_o B_o \
exists x_{alpha} A & mbox{stands for} & neg forall x_{alpha} neg A \
A_{alpha} neq B_{alpha} & mbox{stands for} & neg (A_{alpha} = B_{alpha}) \
end{array}$$

Having spelled all that out, I should say that I don’t particularly care what formulation of the typed lambda calculus is used.

macos – Voice dictation repeats whole sentences in a big garbled chunk on Mac OS X High Sierra

Problem:
During macOS dictation, it sometimes repeat-types the sentence I have spoken multiple times in a row. This seems to happen randomly. Sometimes every minute or two, sometimes taking up to 20 minutes between occurrences.

Example:

  1. I said: I’m using Mac OS 10 dictation for this, and I’m very
    impressed with the quality period I had to fiddle with the settings to get it to work right at first period
  2. The computer immediately output an entire paragraph of garbled repeats of those sentences. See the results below:

I’m using Mac OS 10 dictation for this, and I’m very impressed with the quality. I hdI’m very impressed with the quality. and iI’m very impressed with the quality. Ifor ovI’m very impressed with the quality. I hfor ovI’m very impressed with the quality. I had to fiddle with thi setting tI’m very impressed with the quality. I had to fiddle with the settings to get to wtI’m very impressed with the quality. I had to fiddle with the settings to get to wortI’m very impressed with the quality. I had to fiddle with the settings to get to work tI’m very impressed with the quality. I had to fiddle with the settings to get to work ritI’m very impressed with the quality. I had to fiddle with the settings to get to work rightI’m very impressed with the quality. I had to fiddle with the settings to get to work righI’m very impressed with the quality. I had to fiddle with the settings to get to work rhI’m very impressed with the quality. I had to fiddle with the settings to get to workhI’m very impressed with the quality. I had to fiddle with the settings to get ito work rI’m very impressed with the quality. I had to fiddle with the settings to get it to work r I’m very impressed with the quality. I had to fiddle with the settings to get it to work right at first.

Troubleshooting so far:

  • Quit all other apps that might be using the microphone
  • Turned off advanced dictation commands
  • turned dictation on and off
  • Turned off “Enabled dictation keyword phrase”
  • Turned off “paste that” and “Copy that” dictation commands
  • Searched the web for others with this problem
  • Searched Ask Different for this problem in the past
  • Searched apple support site for dictation support articles (they have deleted all High Sierra support articles)

I’m using Mac OS X High Sierra 10.13.6, Enhanced Dictation is on, Language is English (United States) on a MacBook Pro 15″ Retina mid-2015. Application is Day One Journal. I just turned on dictation and this immediately started happening.

Thank you!

P.S. With great irony, I thought the problem was solved after 20 minutes of it not happening, and I tried to tell my journal I was happy about solving it. That really is the single sentence I tried to dictate, and it immediately spewed all that out.

output formatting – How can I prevent Mathematica from cutting sentences in the middle when printing strings?

I have a very simple but annoying problem. Consider the following example:

Print["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX 
XXXXXX XXXXXX XXXX X XXXXXXXXXXXXXX XXXX XXXX XXX XXXXXXXXXX XXXXXX 
XXXXXXXXXXX XX XXXXXXXXXX XX XXX XXXXXXXXXX XXXXXX XXXXXXXXXXX XX 
XXXXXXX XXXXXX"]

On my system, in a Mathematica notebook, the output looks on the screen as follows:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX XXXXXX XXXXXX XXXX X
XXXXXXXXXXXXXX XXXX XXXX XXX XXXXXXXXXX XXXXXX XXXXXXXXXXX XX XXXXXXXXXX XX XXX XXXXXXXXXX XXXXXX XXXXXXXXXXX XX XXXXXXX XXXXXX

This of course changes when the windows size changes, but the point is that for some reason, the second line is much longer than the first, and it looks ugly and unnatural.

What I would like instead is to have something like:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX XXXXXX XXXXXX XXXX X XXXXXXXXXXXXXX XXXX XXXX XXX
XXXXXXXXXX XXXXXX XXXXXXXXXXX XX XXXXXXXXXX XX XXX XXXXXXXXXX XXXXXX XXXXXXXXXXX XX XXXXXXX XXXXXX

with the first line being longer, and the full width of the window.

However, putting a new line at a particular position only solves this problem for a particular window size; when the window size changes, it no longer looks good. I want Mathematica to keep the first line longer than the second no matter what the window size is, and/or prevent it from splitting the string at an unnatural position.

  1. Why does Mathematica split the text at this very unnatural point in the first place? It doesn’t really make sense, unless I’m missing something.
  2. How can this be avoided, such that for any window size, the first line is always longer than the second?

Thanks in advance.

undecidability – Many-one reductions between the set of true sentences and a particular arithmetical set

Never used this site before so not sure the best way to get help. However, I’ve been looking at many-one reductions in relations to sentences in logic. I wondered if there was a way to prove the following:

TH(N) = {ϕ : ϕ is a first order sentence in the language of arithmetic and N |= ϕ} (Where N is the standard model of arithmetic – , x, <, +, 0, and the successor; S)

Let γ(x) be some formula with exactly one free variable, namely x. Then assume X = {n : γ(n)} to be the arithmetical subset of the natural numbers defined by γ(x).

Is there a way to show either of X or TH(N) many one-reduce to each other?