I have a location
|project://SmallSQL/src/smallsql/database/SQLParser.java|(10257,10257,<305,60>,<371,5>).
However, because the line final class SQLParser { appears to be on line 39, there is an offset of 38, meaning that line 305 actually refers to line 343 (and 371 to 309). I would like to see this offset be reflected in the location. Is that possible, and if so, how? If not, how can I calculate the offset myself?
In addition, the starting line can also be on another location, for example when doc is present before the class. For example in |project://SmallSQL/src/smallsql/database/ExpressionFunctionBitLen.java|(302,302,<11,25>,<13,2>).
Addendum: the locations I am using have been built up by a conversion, i.e., |java+class:///smallqsl/database/SQLParser|(10257,10257,<305,60>,<371,5>) was converted to
|project://SmallSQL/src/smallsql/database/SQLParser.java|(10257,10257,<305,60>,<371,5>).
If you use resolveLocation from the IO module, the offsets will be changed accordingly and properly automatically.
You can also do the resolution yourselves, by looking the right location directly in the M3#declarations table.
resolvedLoc = myM3Model#declarations[myLogicalLocation];
Related
I'm using coordinate_cleaner's country test cc_coun but it's flagging entries with coordinates near to the edges country borders. To try to keep them I wanted to buffer the terrestrial area of countries, essentially expanding their borders a little so that it doesn't flag these entries.
I've tried:
require(rnaturalearth)
world <- ne_countries(scale = "large", returnclass = "sf") %>% st_buffer(dist=.001)
Using st_buffer(dist=.001) does change the geometry, but I noticed whatever I put into dist doesn't matter as it changes it to the same thing regardless (I tried .001, 0.1, 1, 2, and -1, though any minus number removes the geometry altogether).
I found that maybe I need to transform my sf file into something else and then use st_buffer so it's in meters rather than degrees(?). I saw this question/answer but I don't understand it well enough to help my situation: What unit is the `dist` argument in `st_buffer` set to by default?
In the end I'm looking to create a SpatialPolygonsDataFrame reference file to feed into cc_coun. Using the above code I followed on with:
world <- sf:::as_Spatial(world)
coun_test <- cc_coun(x = data,
lon = "Decimal_Long",
lat = "Decimal_Lat",
iso3 = "Country_code",
value = "flagged",
ref = world,
verbose = TRUE)
Which ended up flagging more entries than when I didn't use st_buffer on the reference fine.
In summary, I want to add a buffer to the edge of every country border by around 100 meters in a file I can use as a reference in this test. Is this the best way to go about it or is there a better/easier way? I'd appreciate any advice.
Thank you
Documentation is not helpful to me at all.
First, I tried using set() ,but I don't understand what it means by
set an instance for future calls
I could successfully feed my data using my dataset's structure described below.
So, I am not sure why I need to use set for that as it mentioned.
Here is my feature sequence of type scipy.sparse after I called nonzero() method.
[['66=1', '240=1', '286=1', '347=10', '348=1'],...]
where ... imply, same structure as previous elements
Second problem I encountered is Tagger.probability() and Tagger.marginal().
For Tagger.probability, I used the same input as Tagget.tag(), and I get this follwoing error.
and if my input is just a list instead of list of list. I get the following error.
Traceback (most recent call last):
File "cliner", line 60, in <module>
main()
File "cliner", line 49, in main
train.main()
File "C:\Users\Anak\PycharmProjects\CliNER\code\train.py", line 157, in main
train(training_list, args.model, args.format, args.use_lstm, logfile=args.log, val=val_list, test=test_list)
File "C:\Users\Anak\PycharmProjects\CliNER\code\train.py", line 189, in train
model.train(train_docs, val=val_docs, test=test_docs)
File "C:\Users\Anak\PycharmProjects\CliNER\code\model.py", line 200, in train
test_sents=test_sents, test_labels=test_labels)
File "C:\Users\Anak\PycharmProjects\CliNER\code\model.py", line 231, in train_fit
dev_split=dev_split )
File "C:\Users\Anak\PycharmProjects\CliNER\code\model.py", line 653, in generic_train
test_X=test_X, test_Y=test_Y)
File "C:\Users\Anak\PycharmProjects\CliNER\code\machine_learning\crf.py", line 220, in train
train_pred = predict(model, X) # ANAK
File "C:\Users\Anak\PycharmProjects\CliNER\code\machine_learning\crf.py", line 291, in predict
print(tagger.probability(xseq[0]))
File "pycrfsuite/_pycrfsuite.pyx", line 650, in pycrfsuite._pycrfsuite.Tagger.probability
ValueError: The numbers of items and labels differ: |x| = 12, |y| = 73
For Tagger.marginal(), I can only produce error similar to first error shown of Tagger.probabilit().
Any clue on how to use these 3 methods?? Please give me shorts example of use cases of these 3 methods.
I feel like there must be some example of these 3 methods, but I couldn't find one. Am I looking at the right place. This is the website I am reading documentation from
Additional info: I am using CliNER. in case any of you are familiar with it.
https://python-crfsuite.readthedocs.io/en/latest/pycrfsuite.html
I know this questions is over a year old, but I just had to figure out the same thing as well -- I am also leveraging some of the CliNER framework. For the CliNER specific solution, I forked the repo and rewrote the predict method in the ./code/machine_learning/crf.py file
To obtain the marginal probability, you need to add the following line to the for loop that iterates over the pycrf_instances after yseq is created (see line 196 here)
y_probs = [tagger.marginal(y, ii) for ii, y in enumerate(yseq)]
And then you can return that list of marginal probabilities from the predict method -- you will in turn be required to rewrite additional functions in the to accommodate this change.
I have a pyscript that I am working on and running into issues with the legend.
The goal of the script is to take a csv file with two columns (country, value) that I am joining to a world map based on country name. Once they are joined I turn it into a lyr file and then start to work on the mapping aspects of it.
I want to change the field being mapped to 'value' and then change the mapping to graduated symbols with 5 breaks (at 5,20,50,75,100 % of the max value in the map). The problem being that depending on what layer file is being used the max value changes. I have spent a lot of time searching for how to do this and have still come up short, there are probably some unnecessary bits to my code as well as I am now to python.
How can I get it to map based on graduated symbol based on 5 percent breaks with a changing max value?
Some of the code I have been working on below,
import os, sys, string, arcpy, arcpy.mapping, glob, arcgisscripting,time
from arcpy import env
call blank mxd file, set feature layer, Declare variables
mxd = arcpy.mapping.MapDocument(workspace/blank_4.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
'newname' is the layer file being used
sourceLayer = arcpy.mapping.Layer(newname)
Convert feature classes to layer objects
outLayer = str(newname)
curmap = workspace + filename + ".shp"
arcpy.MakeFeatureLayer_management(curmap, outLayer)
Save layer objects to layer files
LayerFile = str(outLayer) + ".lyr"
arcpy.SaveToLayerFile_management(outLayer, LayerFile)
Define variable for the new layer using LayerFile object
newlayer = arcpy.mapping.Layer(LayerFile)
Adds the new layer to top of TOC in the mxd doc map document
arcpy.mapping.AddLayer(df, newlayer, "TOP")
change the mapping field from country name to fert value
lyr = arcpy.mapping.ListLayers(mxd, newlayer, df)[0]
symbols = arcpy.mapping.Layer(C:\workspace\graduated_symbol2.lyr")
graduated symbols is a blank layer file where I created a legend with 5 breaks (5,20,50,75,100 %) but the range was created based on a max value of 22,000 and now when I run a file with a max value of 35,000 anything above 22,000 becomes blank.
How can I get it to purely work on % breaks, and have the 0/max range of the respective csv file be used??????
Update new layer with sybmology from the source layer
arcpy.ApplySymbologyFromLayer_management(lyr,symbols)
arcpy.mapping.UpdateLayer(df, lyr, symbols, True)
change symbology, colors, and breaks
if lyr.symbologyType == "GRADUATED_COLORS":
lyr.symbology.valueField = "value"
print lyr.symbology.numClasses #
Then I output this to a pdf, but that part is working.
Thanks!
I have audio files, with different durations. They have common content and unique content. E.g. two files, 70 seconds each, last 10 seconds of the first file is the same as first two seconds of the second file. How can I find the exact position of common content (e.g. 60.0 of the first file)?
Sounds a little bit messy, hope the following image can help https://drive.google.com/file/d/0BzBE2Kfw8uQoUWNTN1RXOEtLVEk/view?usp=sharing
So, I'm looking for the red mark - common content starts at 60.0 sec of the first file.
The problem is that I have files with different durations. Sometimes it's 70 seconds long, sometimes one file is 70 seconds, the other is 80 seconds long, etc. Most likely they have 60.0 seconds of unique content, but I'm not sure (it could be 59.9 of unique content, etc.).
Thus, I assume I need to get a short snippet of the second file from first 10 seconds and find it in the first file:
For example, output: 2.5 sec of the second file = 62.5 from the first file - works for me, as well.
THE MAIN GOAL IS TO PLAY FILE AFTER FILE GAPLESS. If I get the values, I'll be able to do this. Sometimes the values can be: 2.5 = 63.7, that's why I need the exact match.
Can anybody help with the code or at least some information of how to compare two snippets of audio content? Thanks in advance!
Wow, that is quite a problem to solve. And I must confess that i've not done anything exactly like this or have any code based suggestions.
All I will say is that if I were looking to try and solve this problem, then I would try and save the audio file as some kind of uncompressed and fixed size (as in a known number of bytes per second) format.
Then you could take a section of one file and byte match it with another, then you would know how many bytes inwards that snippet occurred. Then, knowing the bytes per ms (sort of frame size), you could work out the exact time position.
It's a bit hair brained, but i've used that technique with images before but at least audio is linear!
Here is an approximate example of how I would go about doing the comparison of a sample within a sound file.
- (int)positionOf:(NSData*)sample inData:(NSData*)soundfile {
// the block size has to be big enough to find something genuinely unique but small enough to ensure it is still fast.
int blockSize = 128;
int position = 0;
int returnPosition = INT32_MAX;
// check to see if the block size exceeds the sample or data file size
if (soundfile.length < blockSize || sample.length < blockSize) {
return returnPosition;
}
// create a byte array of the sample, ready to use to compare with the shifting buffer
char* sampleByteArray = malloc(sample.length);
memcpy(sampleByteArray, sample.bytes, sample.length);
// now loop through the sound file, shifting the window along.
while (position < (soundfile.length - blockSize)) {
char* window = malloc(blockSize);
memcpy(window, soundfile.bytes + position, blockSize);
// check to see if this is a match
if(!memcmp(sampleByteArray, window, blockSize)) {
// these are the same, now to check if the whole sample is the same
if ((position + sample.length) > soundfile.length) {
// the sample won't fit in the remaining soundfile, so it can't be this!
free(window);
break;
}
if(!memcmp(sampleByteArray, soundfile.bytes + position, sample.length)) {
// this is an entire match, position marks the start in bytes of the sample.
free(window);
returnPosition = position;
break;
}
}
free(window);
position++;
}
free(sampleByteArray);
return returnPosition;
}
It compiles, didn't have time to setup the scenario to check your exact case, but i'm quite confident this may help.
Is there a way to bypass the character limit of naughty's notification messages? I don't know what that limit is, but they seem to be getting truncated after a certain length. I'm using orglendar and it summarizes my google calendar events in one message/pane, which is very convenient.
Problem is if I have more than 4 or so events, they tend to get too long and get cut off. The resulting message ends up being somewhat unreadable due to incorrect parsing because of truncated </span> tags.
Alternatively, since notification messages probably weren't designed for long lists like this to begin with, is there an alternative widget that I could modify orglendar to use instead?
Looking at the orglendar code, it seems you could simply tweek the calendar_width variable at the top of the script to a larger value.
Alternatively, the naughty documentation tells that you can use a nil width to get automatic width. If this is what you want, you can simply change orglendar to reflect this. At the bottom of the orglendar.lua file (line 268), simply comment-out or remove the width parameter:
calendar = naughty.notify({ title = header,
text = cal_text,
timeout = 0, hover_timeout = 0.5,
-- width = calendar_width * char_width,
screen = mouse.screen,
})