Print

Print


In a perfect world, your parser would include the referents for the
adjectives, which would solve the problem lickety split, but I assume
that's not an option here. Are you ok with only discovering adjective-noun
pairs?

I don't know if pure SQL includes string manipulation / regex, but I think
you could go without if you are willing to add a column. My SQL is super
rusty, so I'll just do this in broad strokes. How about something like:

Add a sequentially numbered autogen column that's pure integer. (Unless you
have string manipulation -- in which case you could just work on the "key"
column).


Then something like:

SELECT * FROM table WHERE autogen IN (SELECT (autogen-1) FROM table WHERE
word = "king") AND part_of_speech="adjective"

I think you should be able to do something like that.... If you have string
manipulation and you don't want to add an autogen column you should be able
to do something similar with a lot of horrible string tweaking.

Also, fair warning that the query could balk if "King" happens to be the
first entry in the table.



On Sat, Jul 22, 2017 at 8:18 AM, Eric Lease Morgan <[log in to unmask]> wrote:

> How might I write an SQL query to find all the descriptions of good kings
> and bad kings in my database?
>
> I have a table that looks something like this:
>
>   key  word       part_of_speech  position
>   ---  ---------  --------------  --------
>   w1   The        article         1
>   w2   righteous  adjective       2
>   w3   king       noun            3
>   w4   solved     verb            4
>   w5   all        adjective       5
>   w6   the        article         6
>   w7   problems   noun            7
>   w8   Your       noun            8
>   w9   evil       adjective       9
>   w10  king       noun            10
>   w11  over       adverb          11
>   w12  taxes      verb            12
>   w13  us         pronoun         13
>
> And I want to list how kings are described. In this example, kings are
> both righteous as well as evil. How can I implement this in pure SQL? How
> do I find all words where the given word is "king" and the previous word is
> an adjective?
>
> —
> Eric Morgan
>