Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: toResponse() #1118

Closed
Ocean-OS opened this issue Jun 15, 2024 · 2 comments
Closed

Feature Request: toResponse() #1118

Ocean-OS opened this issue Jun 15, 2024 · 2 comments

Comments

@Ocean-OS
Copy link

We already have a way to detect if a group of sentences is a question. Is it possible to make a function that could take a question, and return the beginning of a response to the question? (eg "What was World War II?" becomes "World War II was").

@MarketingPip
Copy link
Contributor

@Ocean-OS - you could... But it's the matter of how long you want to take to determine the structure of how questions can start etc as they are in various patterns... As well the patterns of what the responses should look like.....

Here is a VERY basic example of how you could do this.

import nlp from "https://esm.sh/compromise";

function generateResponse(question) {
  // Parse the question using compromise
  let doc = nlp(question);

  // Extract the main subject and verb from the question
  let questionWord = doc.match("#QuestionWord+").first().text();
  let secondPart = doc.match("(#Verb+|#Determiner+)").first().text();
  //console.log(verb)
  return (
    question.replace(questionWord, "").replace(secondPart, "").trim() +
    ` ${secondPart}`
  );
}

// Example usage
let question = "When was World War II";
let response = generateResponse(question);
console.log(response); // Output: "World War II was"

This would be a VERY tedious task. Tho I love Compromise.js and it's capabilities. I suggest you look at another tool / option if you are looking to do more than just VERY basic use cases.

Hope this answers your question.

ps; if it deal. Feel feel to close this issue to save some stress on Spencer!

@spencermountain
Copy link
Owner

hey ComputerGuy, yep I would start writing some templates, like jared has suggested. Could get you somewhere, if your question-answer forms were in well-understood formats:

let m = doc.match('what [<verb>(is|was)] [<subj>#Noun+]$')
if(m.found){
  return m.groups('subj').text() + ' ' + m.groups('verb').text() +' ...'
}

https://runkit.com/spencermountain/6674229afd6d9b00083261b3
but like Jared mentioned, it's also a very hard problem!
cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants