The system will be a simple webapp exposing REST API acting as a generator of the sentences from the words inserted to it by rules described below.
You can input any word to the system but you need to specify its part of speech - NOUN or VERB or OBJECTIVE. The system must be able to generate a sentence from the words according to the rule that sentence is in the form of NOUN VERB ADJECTIVE. Further description of resources / functionality is available in the next part - API proposal (api proposal omitted for brevity as solution api reference exactly reflects what was required).
Optionals
- Get list of forbidden words from file and reject them on API
- Track number and id of exactly the same generated sentences (separate resource - introduce one)
- You can see the number of view of the specific sentence
- Docker
- JDK 11
gradlew test bootJar
Run using docker compose
docker-compose build
docker-compose up
Or run using docker compose with three api service replicas
docker-compose -f docker-compose-ha.yml build
docker-compose -f docker-compose-ha.yml up --scale api=3
Or run jar directly (Docker still needed for Postgres)
docker run --name db -p 5432:5432 -e POSTGRES_PASSWORD=pass -e POSTGRES_DB=db -d postgres:13.0
java -jar build\libs\sentenceGenerator-0.0.1-SNAPSHOT.jar
Forbidden words loaded during startup from a file forbidden.txt located in project root directory (file also copied to Docker image). Words should be in following csv format:
trump;noun
seems;verb
sad;adjective
These words are also forbidden by default.
{
"message": "Service alive! Ready to generate sentences based on rules : 3 words total with given types of words in order: noun, verb, adjective"
}
Response
[
{
"word": {
"text": "cat",
"wordCategory": "NOUN"
}
},
{
"word": {
"text": "drinks",
"wordCategory": "VERB"
}
}
]
Same as /words but pageable
Response
{
"word": {
"text": {word},
"wordCategory": "NOUN"
}
}
Request
{
"word": {
"wordCategory": "NOUN"
}
}
Response
{
"word": {
"text": {word},
"wordCategory": "NOUN"
}
}
Response
[
{
"sentence": {
"id": 6,
"text": "cat drinks very",
"created": "2020-11-10T21:20:49.884741"
}
},
{
"sentence": {
"id": 7,
"text": "dog walks slowly",
"created": "2020-11-10T21:20:53.457476"
}
}
}
Same as /sentences but pageable
Response
{
"sentence": {
"id": 6,
"text": "cat drinks very",
"created": "2020-11-10T21:20:49.884741",
"showDisplayCount": 2
}
}
Response
{
"sentence": {
"text": "drinks very cat"
}
}
Response
{
"sentence": {
"id": 1,
"text": "cat drinks slowly",
"created": "2020-11-10T21:19:01.9593459",
"showDisplayCount": 1
}
}
Response
[
{
"duplicateSentence": {
"text": "dog walks slowly",
"duplicateCount": 2,
"duplicateSentencesIds": [7, 8]
}
},
{
"duplicateSentence": {
"text": "cat drinks slowly",
"duplicateCount": 3,
"duplicateSentencesIds": [2, 3, 4]
}
}
]