I'm trying to delete a class and axioms for that class. I've tried different options, could not get them to work the way I want. Here is the code I have (it deletes nothing...):
if(clazz.toString().contains("2381")) {
Stream<OWLClassAssertionAxiom> axiomstodelete = ontology.classAssertionAxioms(clazz);
OWLEntityRemover remover = new OWLEntityRemover(Collections.singleton(ontology));
axiomstodelete.forEach(i -> i.individualsInSignature().forEach(j -> j.accept(remover)));
manager.applyChanges(remover.getChanges());
}
Update:
This code seems to work for a class and associated axioms removal:
OWLEntityRemover remover = new OWLEntityRemover(Collections.singleton(ontology));
currentClass.accept(remover);
manager.applyChanges(remover.getChanges());
Now, there is a condition, based on which I want to delete all subclasses (branches) of a particular class. The problem is I have to go from the bottom up, because I need to find the "lowest" class in the hierarchy for which the condition is true. I use this code:
currentClass = class_stack.pop();
removeClass(manager, clazz);
prevClass = class_stack.peek();
while(isBottom(reasoner, prevClass) && !class_stack.isEmpty() && !checkCondition(prevClass)) {
currentClass = class_stack.pop();
removeClass(manager, currentClass);
prevClass = class_stack.peek();
}
It works for one leaf, but it does not for the parent of the leaf, because isBottom condition for the parent is not true, even after all its children are deleted. I have a workaround for now - after leaf is deleted, save the ontology, then reload again and delete next leaf etc. Would be nice to make it in one run.
For Ignazio - this is an example of a branch that shows why I'm checking for the bottom (C is for class with the true condition, L - for other classes). If I go up the left branch: L (bottom?->yes->delete) -> L(bottom?->yes->delete) -> L (bottom?->NO->leave for now). Then check the right branch: C (bottom?->yes && condition?->yes -> leave!)
C
|
L
/ \
L L
/ \
L C
The result I need should be:
C
|
L
|
L
|
C
You have already selected the axioms to remove. Skip the entity removed and use the remove method on the ontology.
Related
I am trying to read word content line by line. But I am facing an issue. When trying to read paragraph. If paragraph content is multi line. I am getting single line internally. Can any one please help me on this.
Expected Output:
Line 1 - > TERM BHFKGBHFGFKJHGKJSHFKG ABC1 IOUTOYTIUYRUYTIREYTU B08
Line 2 - > NBHFBHDFGJDSBHKHDGFJGJGDJK 3993 JBHKJSFGSDKFJDGFJKDSBF3993
Line 3 - > JHBJKFHKJGDGFSFGB08 HGHGGFGFDGJFFFDSGFABC1 JJBVHGHDFTERM
Line 4 - > TERMBHFKGBHFGFKJHGKJSHFKG ABC1IOUTOYTIUYRUYTIREYTU B08NBHFBHDFGJDSBHKHDGFJGJGDJK
Line 5 - > 39931234567890987654321
Actual Output:
Single Line -> TERM BHFKGBHFGFKJHGKJSHFKG ABC1 IOUTOYTIUYRUYTIREYTU B08 NBHFBHDFGJDSBHKHDGFJGJGDJK 3993 JBHKJSFGSDKFJDGFJKDSBF3993 JHBJKFHKJGDGFSFGB08 HGHGGFGFDGJFFFDSGFABC1 JJBVHGHDFTERM
TERMBHFKGBHFGFKJHGKJSHFKG ABC1IOUTOYTIUYRUYTIREYTU B08NBHFBHDFGJDSBHKHDGFJGJGDJK
39931234567890987654321
Below is my code sample:
OpenXml:
using (WordprocessingDocument doc = WordprocessingDocument.Open(fs, false))
{
var bodyText = doc.MainDocumentPart.Document.Body;
if (bodyText.ChildElements.Count > 0)
{
foreach (var items in bodyText)
{
if (items is Paragraph)
{
var par = items.InnerText;
}
}
}
}
Office.Interop
object nullobj = System.Reflection.Missing.Value;
Word.Application app = new Word.Application();
Word.Document doc = app.Documents.Open(FilePath, ref nullobj, FileAccess.Read,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
foreach (Word.Paragraph paragraph in doc.Paragraphs)
{
var line = paragraph.Range.Text;
}
It is not possible to determine individual lines in the closed file. Lines are dynamically generated when a document is opened in Word and where a line "breaks" depends on many factors - it's not necessarily the same from system profile to system profile. So it's necessary to use the interop, not Open XML to pick up where lines break on the screen.
What's more, the Word object model does not provide "Line" objects for this very reason - there is no "line", only a visual representation of how the page will print, given the current printer driver and version of Windows.
The only part of the Word object model that recognizes "lines" is Selection, as this works solely with what's displayed on the screen.
The following code demonstrates how this can be done.
First, since Selection is being worked with and this is visible on-screen, ScreenUpdating is disabled in order to reduce screen flicker and speed up processing. (Note that working with selections is generally much slower than other object model processing.)
Using ComputeStatistics the number of lines in a paragraph is determined. An array (you can also use a list or anything else) to contain the lines is instantiated. The paragraph range is "collapsed" to its starting point and visually selected.
Now the lines in the paragraph are looped, based on the number of lines. The selection is extended (MoveEnd method) by one line (again, moving by lines is only available to a selection) and the selected text written to the array (or whatever).
Finally, screen updating is turned back on.
wdApp.ScreenUpdating = false;
foreach (Word.Paragraph para in doc.Paragraphs)
{
Word.Range rng = para.Range;
int lNumLines = rng.ComputeStatistics(Word.WdStatistic.wdStatisticLines);
string[] aLines = new String[lNumLines];
rng.Collapse(Word.WdCollapseDirection.wdCollapseStart);
rng.Select();
for (int i = 0; i < lNumLines; i++)
{
wdApp.Selection.MoveEnd(Unit: Word.WdUnits.wdLine, Count: 1);
aLines[i] = wdApp.Selection.Text;
wdApp.Selection.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
}
for (int i = 0; i < aLines.Length; i++)
{
Debug.Print(aLines[i]);
}
}
wdApp.ScreenUpdating = true;
In Word, a paragraph is a sinle line of text. Change the size of the print area (e.g. change the margins and/or page size) or the font/point size and the text reflows accordingly. Moerover, since Word uses the active printer driver to optimise the page layout, what exists on a given line in one computer may not exist on the same line on another computer.
Depending on your requirements, though, you could employ Word's predefined '\Line' bookmark to navigate between lines or the Rectangle.Lines property.
I just started programming in Elm and am stuck at something:
I would like to have a method that can update fields of elements in a list at a certain index.
My signature would look like this:
updateElement : List (ID, Task) -> Int -> List (ID, Task)
with:
type alias Task =
{ description : String, focus : Bool}
In this case I would like to set the boolean (focus) of the task at the index given to true and all the others tasks in the list to false.
I already tried with arrays in Elm but then I have to work with Maybe and don't think that is a good solution.
I suppose I will have to work with 'map' to change elements in my list but I don't have any clue how I could change it at a particular index.
Thanks!
Now that you've clarified your question, the real answer is a combination of the two updates Chad posted
updateElement : List (ID, Task) -> Int -> List (ID, Task)
updateElement list indexToFocusOn =
let
toggle index (id, task) =
if index == indexToFocusOn then
(id, { task | focus = true })
else
(id, { task | focus = false })
in
List.indexedMap toggle list
If you want often to change only the nth element of a list, a List would be the wrong data structure. A List in elm is implemented as a linked list, which will not fare well in terms of performance with random access.
For that kind of work, you probably should rather use an elm Array, and indeed the Array does have a simple function to set the nth element, leaving all the others untouched: Array.set :: Int -> a -> Array a -> Array a.
On that topic, this discussion on the elm bug tracker could be of interest.
Since you want to update all elements in the list (to make sure all elements are either False while those matching the ID are True), you can perform a List.map over the list, while supplying a function whose job is to check the index and perform the update on the element.
Here's an example with a few minor changes to your example code:
type alias MyTask =
{ description : String
, focus : Bool
}
updateElement : List (a, MyTask) -> a -> List (a, MyTask)
updateElement list id =
let
toggle (idx, task) =
if id == idx then
(idx, { task | focus = True })
else
(idx, { task | focus = False })
in
List.map toggle list
I changed your signatures to be more generic. Since you provided no indication of what ID was, I assumed that the first element in the tuple had to match the type of whatever the second function parameter was. I also replaced Task with MyTask since there's already a common type in elm called Task.
I'll also mention that there is a List.indexedMap function which could let you simplify your function declaration a little bit. If the only reason you have a tuple input and output in your example above is because you need to locate an element by its index, it's probably easier to use List.indexedMap. Here's an example:
updateElement2 : List MyTask -> Int -> List MyTask
updateElement2 list id =
let
toggle idx task =
if id == idx then
{ task | focus = True }
else
{ task | focus = False }
in
List.indexedMap toggle list
As you can see, it cuts some of that tuple boilerplate out of the function, making it a bit cleaner.
I have documents in my solr already indexed. I want to find Producer and model in tire.
I have file with producer and model like this:
Nokian;WR G2 SUV
Nokian;WR SUV
Nokian;V
Query:
((productname:"NOKIAN" OR producer:"NOKIAN") AND (productname:"V" OR description:"V" OR referencenumber:"V"))
But it found for example this:
"2X NOKIAN 215/55 R17 94V LINE (3)"
Because in this product speed index is V and here model is Line. My algorithm take this product for Nokian;V not for Nokian;Line.
How to ask solr to gives me only this product where this V don't have any other letters around?
LETNIE 225/45/17 94V NOKIAN V FINLAND - PŁOTY
This found beautiful. Its Nokian;V.
As far as I understand your question you need to put MUST quantifier before each boolean clause. So query will look like:
(
+(productname:"NOKIAN" OR producer:"NOKIAN") AND
+(productname:"V" OR description:"V" OR referencenumber:"V")
)
If your productname field is of type text it has the WordDelimiterFilter in the analysis chain. One of the default behaviors of this filter is to split terms on letter-number boundaries causing:
2X NOKIAN 215/55 R17 94V LINE (3)
to generate the following tokens:
2 X NOKIAN 215 55 R 17 94 V LINE 3
(which matches the "V" in your query).
You can always run debug=results to get an explanation for why something matches. I think in this particular case, you might construct another field type for your productname field that analyzes your model string less aggressively.
I solved the problem in such a way that sorted out brand,model Dictionary. I used my own comparer.
public class MyComparer : IComparer<string>
{
int IComparer<string>.Compare(string x, string y)
{
if (x == y)
{
return 0;
}
if (x.Contains(y))
{
return -1;
}
else
{
return 1;
}
}
}
All model that have V or H now are on the end of Dcitionary. It's works very well. Because first solr searched Nokian;Line and this product where found add to other list alreadyFound and skip this product where found model. Thanks all for your reply.
I'm attempting to draw in a non-customized (I mean, simply creating an instance of the default form class, not an instance of a deriving class I can create) System.Windows.Forms.Form in F#.
I had created a custom form, but I didn't need nor want a new complex structure like that, so I removed it, and it simplified the code a lot; so much, that it stopped to show an image.
The problem must be in the function I created to draw, that is in another F# project. I've created it (function conect) to connect points in the order they are provided, unlike System.Drawing.Graphics.DrawLines, that draws lines between the points in some other order why haven't noticed yet (maybe right to left, top to bottom, as the points are represented).
Programa.fs relevant code snippet:
let pen = new Pen(brush = Brushes.Black, width = 1.0f)
let original =
([|new PointF(50.0f, 50.0f); new PointF(100.0f, 50.0f)|])
use form1 = new Form(Width = 400, Height = 400, Text = "Fractais (Teste - Windows Forms)")
form1.Paint.Add(
fun e -> // (1)
original
|> List.ofArray
|> Base.applyFractal 1uy Base.fractalFunc1
|> Base.conect e.Graphics pen)
If in the lambda expression instead of what's written there was e.Graphics.DrawLines(pen, original), it would draw a simple line between the points in the list.
Here's the troublemaker method, in Base.fs, across the solution:
let conect (gr:Graphics) (pen:Pen) (points:PointF list) =
let rec usefulFunc (gr:Graphics) (pen:Pen) (points:PointF list) prevPoint =
match points with
| [] -> ()
| point :: remainings ->
gr.DrawLine (pen, prevPoint, point)
usefulFunc gr caneta remainings.Tail remainings.Head
usefulFunc gr pen points.Tail points.Head
And the called (from the form initialization snippet) and relevant methods' signatures, in Base.fsi (I could give you all of the full methods' implementation, but it would take a lot of space, and this is probably for you already becoming a long question to read):
val fractalFunc1 : points:PointF list -> PointF list
val applyFractal : stepNumber:byte -> fractalFunc:(PointF list -> PointF list) -> points:PointF list -> PointF list
val conect : gr:Graphics -> pen:Pen -> points:PointF list -> unit
For this specific problem, my search results were none. I'd like to know how can I make the function conect work.
Thanks in advance.
You have one error in conectar.
fUtil gr caneta resto.Tail resto.Head
Should be
fUtil gr caneta resto ponto
You're already matching the head and tail inside of the match statement.
The following code draws a line for me. I didn't have to modify much.
open System.Drawing
open System.Windows.Forms
let caneta = new Pen(brush = Brushes.Black, width = 1.0f)
let original =
([|new PointF(50.0f, 50.0f); new PointF(100.0f, 50.0f)|])
let form1 = new Form(Width = 400, Height = 400, Text = "Fractais (Teste - Windows Forms)")
let conectar (gr:Graphics) (caneta:Pen) (pontos:PointF list) =
let rec fUtil (gr:Graphics) (caneta:Pen) (pontos:PointF list) pontoAnt =
match pontos with
| [] -> ()
| ponto :: resto ->
gr.DrawLine (caneta, pontoAnt, ponto)
fUtil gr caneta resto ponto
fUtil gr caneta pontos.Tail pontos.Head
form1.Paint.Add(
fun e -> // (1)
original
|> List.ofArray
//|> aplicFractal 1uy Base.funcFractal1
|> conectar e.Graphics caneta)
form1.Show()
Application.Run(form1)
this may be a simple question, yet I haven't been able to find an answer to it:
How do I add a value to an array without overwriting (all) old values, or having to rewrite them? Is there such a thing as array_push in LUA? And if so, does it work for multidimensional arrays as well?
Example:
Array={"Forest","Beach","Home"} --places
Array["Forest"] = {"Trees","Flowers"} --things you find there
Array["Forest"]["Trees"] = "A tree is a perennial woody plant" --description
If I'd like to add a description of a new thing in a new place, I can't do it using
Array["Restaurant"]["Spoon"] = "A type of cutlery."
because I'd have to declare all these things, as well as the old ones so I don't overwrite them. So I'm looking for something like:
array_push(Array, "Restaurant")
array_push(Array["Restaurant"],"Spoon")
Array["Restaurant"]["Spoon"] = "A type of cutlery."
Thanks!
The following index metamethod implementation should do the trick.
local mt = {}
mt.__index = function(t, k)
local v = {}
setmetatable(v, mt)
rawset(t, k, v)
return v
end
Array={"Forest","Beach","Home"} --places
setmetatable(Array, mt)
Array["Forest"] = {"Trees","Flowers"} --things you find there
Array["Forest"]["Trees"] = "A tree is a perennial woody plant" --description
Array["Restaurant"]["Spoon"] = "A type of cutlery."
Note that you are mixing array indexed values with with string indexed values, and I don't think you intended to do so. For example, your first line stores "Forest" under the key "1", while the second line creates a new table key "Forest" with a table value that holds sequential string values. The following code prints out the generated structure to demonstrate my meaning.
local function printtree(node, depth)
local depth = depth or 0
if "table" == type(node) then
for k, v in pairs(node) do
print(string.rep('\t', depth)..k)
printtree(v, depth + 1)
end
else
print(string.rep('\t', depth)..node)
end
end
printtree(Array)
Next is the resulting output of the two code snippets listed above.
1
Forest
2
Beach
3
Home
Restaurant
Spoon
A type of cutlery.
Forest
1
Trees
2
Flowers
Trees
A tree is a perennial woody plant
With this understanding, you could then solve your problem without such trickery as follows.
Array = {
Forest = {},
Beach = {},
Home = {}
}
Array["Forest"] = {
Trees = "",
Flowers = "",
}
Array["Forest"]["Trees"] = "A tree is a perennial woody plant"
Array["Restaurant"] = {
Spoon = "A type of cutlery."
}
printtree(Array)
The output is then what you probably expected.
Restaurant
Spoon
A type of cutlery.
Beach
Home
Forest
Flowers
Trees
A tree is a perennial woody plant
With all of that in mind, the following accomplishes the same thing, but is much clearer in my humble opinion.
Array.Forest = {}
Array.Beach = {}
Array.Home = {}
Array.Forest.Trees = ""
Array.Forest.Flowers = ""
Array.Forest.Trees = "A tree is a perennial woody plant"
Array.Restaurant = {}
Array.Restaurant.Spoon = "A type of cutlery."
printtree(Array)
First, what you're making is not an array at all, but a dictionary. Try:
T = { Forest = { } , Beach = { } , Home = { } }
T.Forest.Spoon = "A type of cutlery"
Otherwise table.insert may be what you want in array_push
This is almost identically there in standard Lua like this:
Array.Restaurant={}
Array.Restaurant.Spoon={}
Array.Restaurant.Spoon[1]="A type of cutlery."
the table.key notation is equivalent of the table["key"] notation.
Now every item has it's description in the value corresponding to a number-key, and sub items as values corresponding to string keys.
If you really want to have exactly the same syntax as your example, you'll have to use metatables (__index and __newindex methods).