SKOS multiple broader term effect - skos

There is one thing which confuses me with the use of multiple broader terms and classification.
Suppose I have the following thesaurus:
> colors
> green
> red
> blue
> yellow
> orange
> favorite colors
> orange
> red
> yellow
where the concepts orange, red and yellow have two broader concepts:
favorite colors and colors.
What is the effect then if I give a document the concept 'orange'?
Can I make the difference between 'favorite color' and just 'color'?

SKOS does support polyhierarchies as you have shown here. This means that a concept can have multiple "contexts", where the context is defined by its broader concepts. In your case, <orange> has two contexts: <favorite colors><colors> and <colors>. There isn't a way to say is one or the other - it is both. That's what polyhierarchies are all about.
But I would expect that the kinds of questions one would ask of this hierarchy are along the lines of "What are the colors?" "What are 'favorite colors'?", and that is what determines which context is being used in.

Related

Change support and resistance line color in mplfinance

Currently, I'm using this code. How can I change the hlines to red if it's a resistance and blue if it's a support?
mplfinance.plot(df,
type = 'candlestick',
style = 'binance',
hlines=dict(hlines= support_resistance,linestyle='-', linewidths = (1,1)),
volume = True)
I'm getting results like this:
hlines=dict(hlines= support_resistance,linestyle='-',linewidths = (1,1),colors=('b','r')
See for example cell "In [6]" in this tutorial: https://github.com/matplotlib/mplfinance/blob/master/examples/using_lines.ipynb
You may need to include as many colors as you have support_resistance lines. So for example, maybe something like: colors=['b','r','b','r','r','r']
Regarding handling support resistance colors dynamically (per your comment) it is not appropriate for mplfinance to provide algorithms for determining support or resistance, only to provide tools to make it easier for you to visualize them.
Also, each user may have their own specific way of determining support or resistance.
Presumably as you are building the support_resistance list, at the point in your code where you are adding a specific price to that list, you probably know whether that price represents support or resistance. At the same point in your code you should add a color ('b' or 'r') to the colors list. That way you dynamic build two lists: support_resistance, and colors which end up being the same length.
Based on the suggestion from Daniel, I made a list of colors as follows and it worked. support_resistance variable here consists of both support and resistance levels.
colors = []
for lvl in support_resistance:
if lvl > df['Close'][-1]:
colors.append('r')
else:
colors.append('b')

Can knowledge graphs deal with a sentence including a preposition or adjective

I am thinking of how suitable knowledge graphs such as "Google Knowledge Graph", "WordNet", "Yago", or "FreeBase" is for representing facts including a preposition or adjective.
For example, "Obama has a daughter" can clearly be represented by node and link relations. "Obama" and "daughter" are nodes. "has a" is a link.
However, I can not find a way to represent a sentence with a preposition or adjective by googling by several keywords.
Suppose you have a fact that "Obama has a white dog in whitehouse", it seems impossible to be represented by graph structures. Obama's dog is white, bat not all dog is white. Also, Obama's dog is kept in whitehouse, but not all dog is.
My first question is whether knowledge graph can represent this kind of fact or not. My second question is how knowledge graph can do this, if the first answer is yes.
You'd represent this is a series of facts. For example:
barackObama owns fido
fido isA dog
fido livesIn theWhiteHouse
fido hasFurColour white
i.e. you have a specific node in your graph which represents the specific object, and then assert further facts about that object. Similarly, while you could assert a single fact "barackObama hasA daughter", you'd probably assert a number of facts linking the two nodes "barackObama" and "maliaObama".
As with everything else, there is no one "right" representation of your data - it varies depending on the problem you're trying to solve.

How to use Inversable features in prestashop

This is a very special problem I met in Prestashop.
I have a product, let's say a two color wooden stick, which is a normal 10" long stick. Half of it (5") can be blue and the other half red for example.
My product is this: Two color wooden stick. I have the following features: color 1 and and color 2 .
In the admin at the product's features I check red for the color 1 and blue for color 2.
Now the problem: when user filters using layered navigation, maybe they select blue for color 1 and red for color 2. This will result displaying 0 products as our wooden stick is inverse, but in the reality it's the same product.
How could I make that possible without duplicating the wooden stick product?
I see there is mismatching, your product 10" is not blue OR red, but blue-red in same time, so set two different colors is bad idea, instead I can propose you to do next, I hope when you said that you use color features it is named in Presta backoffice attributes, there is the difference between two this things in Presta, so:
in Catalog -> Product Attributes create new P.Attribute with name Color and for last option choose Color or textures in dropdown
add new Value for this new Color p.atrribute named e.g. "blue-red" and upload texture (img) that contains both colors. Repeat this procedure as much as needed.
in Layered navigation use this new p.attribute instead old
OR
another idea, create using same way 2 different color attributes Color1 and Color2, no textures, just use real separate colors there like "red", "blue". Then in product create combinations of this two colors and assign it to product.
In this case in layered navigation you will can set 2 filters - Color1, Color2 and customers will can to choose it. But, imho, first solution is better for UX.

Understanding Google Code Jam 2013 - X Marks the Spot

I was trying to solve Google Code Jam problems and there is one of them that I don't understand. Here is the question (World Finals 2013 - problem C): https://code.google.com/codejam/contest/2437491/dashboard#s=p2&a=2
And here follows the problem analysis: https://code.google.com/codejam/contest/2437491/dashboard#s=a&a=2
I don't understand why we can use binary search. In order to use binary search the elements have to be sorted. In order words: for a given element e, we can't have any element less than e at its right side. But that is not the case in this problem. Let me give you an example:
Suppose we do what the analysis tells us to do: we start with a left bound angle of 90° and a right bound angle of 0°. Our first search will be at angle of 45°. Suppose we find that, for this angle, X < N. In this case, the analysis tells us to make our left bound 45°. At this point, we can have discarded a viable solution (at, let's say, 75°) and at the same time there can be no more solutions between 0° and 45°, leading us to say that there's no solution (wrongly).
I don't think Google's solution is wrong =P. But I can't figure out why we can use a binary search in this case. Anyone knows?
I don't understand why we can use binary search. In order to use
binary search the elements have to be sorted. In order words: for a
given element e, we can't have any element less than e at its right
side. But that is not the case in this problem.
A binary search works in this case because:
the values vary by at most 1
we only need to find one solution, not all of them
the first and last value straddle the desired value (X .. N .. 2N-X)
I don't quite follow your counter-example, but here's an example of a binary search on a sequence with the above constraints. Looking for 3:
1 2 1 1 2 3 2 3 4 5 4 4 3 3 4 5 4 4
[ ]
[ ]
[ ]
[ ]
*
I have read the problem and in the meantime thought about the solution. When I read the solution I have seen that they have mostly done the same as I would have, however, I did not thought about some minor optimizations they were using, as I was still digesting the task.
Solution:
Step1: They choose a median so that each of the line splits the set into half, therefore there will be two provinces having x mines, while the other two provinces will have N - x mines, respectively, because the two lines each split the set into half and
2 * x + 2 * (2 * N - x) = 2 * x + 4 * N - 2 * x = 4 * N.
If x = N, then we were lucky and accidentally found a solution.
Step2: They are taking advantage of the "fact" that no three lines are collinear. I believe they are wrong, as the task did not tell us this is the case and they have taken advantage of this "fact", because they assumed that the task is solvable, however, in the task they were clearly asking us to tell them if the task is impossible with the current input. I believe this part is smelly. However, the task is not necessarily solvable, not to mention the fact that there might be a solution even for the case when three mines are collinear.
Thus, somewhere in between X had to be exactly equal to N!
Not true either, as they have stated in the task that
You should output IMPOSSIBLE instead if there is no good placement of
borders.
Step 3: They are still using the "fact" described as un-true in the previous step.
So let us close the book and think ourselves. Their solution is not bad, but they assume something which is not necessarily true. I believe them that all their inputs contained mines corresponding to their assumption, but this is not necessarily the case, as the task did not clearly state this and I can easily create a solvable input having three collinear mines.
Their idea for median choice is correct, so we must follow this procedure, the problem gets more complicated if we do not do this step. Now, we could search for a solution by modifying the angle until we find a solution or reach the border of the period (this was my idea initially). However, we know which provinces have too much mines and which provinces do not have enough mines. Also, we know that the period is pi/2 or, in other terms 90 degrees, because if we move alpha by pi/2 into either positive (counter-clockwise) or negative (clockwise) direction, then we have the same problem, but each child gets a different province, which is irrelevant from our point of view, they will still be rivals, I guess, but this does not concern us.
Now, we try and see what happens if we rotate the lines by pi/4. We will see that some mines might have changed borders. We have either not reached a solution yet, or have gone too far and poor provinces became rich and rich provinces became poor. In either case we know in which half the solution should be, so we rotate back/forward by pi/8. Then, with the same logic, by pi/16, until we have found a solution or there is no solution.
Back to the question, we cannot arrive into the situation described by you, because if there was a valid solution at 75 degrees, then we would see that we have not rotated the lines enough by rotating only 45 degrees, because then based on the number of mines which have changed borders we would be able to determine the right angle-interval. Remember, that we have two rich provinces and two poor provinces. Each rich provinces have two poor bordering provinces and vice-versa. So, the poor provinces should gain mines and the rich provinces should lose mines. If, when rotating by 45 degrees we see that the poor provinces did not get enough mines, then we will choose to rotate more until we see they have gained enough mines. If they have gained too many mines, then we change direction.

Available Colors for SetConsoleTextAttribute

im working with SetConsoleTextAttribute API (Delphi to be specific), well anyway i cannot find a list of available colors anywhere?? can anyone help me out
There a 4 Bits used for the foreground color
FOREGROUND_BLUE; //1
FOREGROUND_GREEN; //2
FOREGROUND_RED; //4
FOREGROUND_INTENSITY; //8
which will give 16 possible colors. (0-15)
The next 4 bits are used for background color with the same scheme
See this. Colors are formed by ORing different constants. For instance:
An application can combine the foreground and background constants to
achieve different colors. For example, the following combination
results in bright cyan text on a blue background.
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY |
BACKGROUND_BLUE
For more Turbo/Borland Pascal CRTish implementations of such, see this. The colors available in the Windows console via SetConsoleTextAttribute work out roughly to be the same ones as the CRT unit, so any more relevant details can be found there.