Setting path for macecommand for nltk - nltk

I found a solution to set the path for prover9 from the link
config_prover9 method for setting prover9 path
Is there any similar method for dealing with macecommand too? My code is below
a4 = read_expr('exists y. (woman(y) & all x. (man(x) ->love(x,y)))')
a5 = read_expr('man(adam)')
a6 = read_expr('woman(eve)')
g = read_expr('love(adam,eve)')
mc = nltk.MaceCommand(g, assumptions=[a4, a5, a6])
mc.build_model()
Is there any way to set it to find the directory where I have installed Macecommand? Thanks in advance.

I found the solution, I just needed to set environment variable for it.

Related

rdbwselect in R not showing output

I'm using the package rdrobust in R and Stata. I planned to fully implement the analysis in R, but encountered a problem with the function rdbwselect. This function computes different bandwidths depending on the selection procedure. By default, the procedure is Mean Square Error bwselect=mserd. However, I'm interested in exploring other procedures and comparing them. I then tried ALL=true; which is the option that according to the package "if specified, rdbwselect reports all available bandwidth selection procedures"
My issue is that, in R, rdbwselect is not showing me the bandwidths, not with the default not with the 'all' option or any other specification
x<-runif(1000,-1,1)
y<-5+3*x+2*(x>=0)+rnorm(1000)
## With default mserd
rdbwselect(y,x,)
## All selection procedures
rdbwselect(y,x,all= TRUE)
Output rdwselect
The output of both lines of rdbwselect code is exactly the same (see image), and it should not. I also try replicating the script from the rdrobust article in The R Journal (Page 49) and I don't get the same output as in the paper.
Nevertheless, the function is working in Stata 16
clear all
set obs 1000
set seed 1234
gen x = runiform(-1,1)
gen y = 5+3*x+2*(x>=0)+rnormal()
rdbwselect y x
rdbwselect y x, all
Could someone provide me with some guidance on why R is not showing me the complete expected output of the function rdbwselect? I'm wondering if this is an issue related to my version of R? Could this be a bug with the R package or the specific function rdbwselect? How can I verify the computation behind rdbwselect?
I appreciate any advice or follow-up questions.
Found the solution. All I needed to do was to embed the function within the summary() function
summary(rdbwselect(y,x,))
or add a pipe and the summary function
rdbwselect(y,x,all= TRUE) %>%
summary()
I want to post it as this is nowhere mentioned in the package documentation nor the article in The R Journal.

unable to unrar when the syntax built from function

I work in google colab, I've got an error with this code...
I have so many rar files, and I need to unpack them, those are in different path and I made a function in to simplify my work. I made variables those are changeable so I can replace the path to something else, unfortunately the result says No file extracted or asking me a password even I have true password it doesn't wanna stop asking
type hereaddress = "/content/temporary/myfile.rar"
foldestny = "/content/hasilekstrak"
ps ="pass2345"
def rara(adrs, fdstn, pswrd):
!unrar x "$adrs" "$dstn" "-p$psward"
rara(address, foldestny, ps)
however if I type the code in singgle line, it will work.
why does this happen?
I hope I can make a function to extract anything when I need, so simple by typing variables

Get atomic coordinates from specific residues and compute distances

I'm trying to extract the exact coordinates for an atom in specific residues in a PDB file.
The idea is to use a function that finds the coordinates of all oxygens of the cysteines in a file, find the nitrogen coordinates on the histidines in the same file, and calculate the distances between them.
import sys
import os
os.getcwd()
filename = sys.argv[1]
def cys_ox_coord_extr():
with open(filename, "r") as fileobj:
content = fileobj.readlines()
print("Cysteine's oxygen coordinates\n")
for line in content:
if line.startswith("ATOM"):
if str(line.split()[3]) == "CYS" and str(line.split()[2]) == "O":
cys_ox = [line.split()[5], [line.split()[6], line.split()[7], line.split()[8]]]
print(cys_ox)
The function works fine, and I can get the coordinates for this atom type, however, I can't use these results elsewhere.
I can't recall "cys_ox" anywhere outside the function itself, even using `return cys_ox.
Yet, if I print it, the results come out fine.
My goal is to get the coordinates for another atom type in another residue and compute the distances, but it is impossible if I can't use the results outside the function which generates them.
What can I do?
Thank you!!!
as Giacomo suggested,
define a list outside the function, and append cys_ox to the list. So the list has global scope and you can access outside the function. Else you should define global cys_ox at start of function, so python know that such variable should have global scope (and not the default function scope), but you may have many cys_ox, so a list is better. –
Giacomo Catenazzi

Are there differences between .img and .tif formats which affects how GDAL .SetNoDataValue() works?

I'm having an issue masking No Data values from a statistical analysis of raster image data.
The input file is a 3-dimensional (rows, columns and layers) .img file
It is opened using the gdal.Open() function and then I want to extract some per layer statistics from each row x column image it contains (layer).
Some of these images contain crap data (or No Data), which has been given a value of -0.0 by the dataset originators. I do not want these pixel values to be included in the statistics calculations, and need to screen them out.
For this i'm using the SetNoDataValue() function, which works well on .tif imagery.
Unfortunately, with .img, -0.0 keeps showing up as each layer's minimum value (it should be around 270.something) in the minCubeValues variable, and the mean and standard deviation values are incorrect as a consequence.
When i've run this sequence on .tif files, it works fine, but it does not for .img files, and I can't figure out why.
I need to get it working directly on .img files as the bulk of my image data are in .img, and are made available as such.
I suspect it comes down to structural differences between .img and .tif files, but I cannot understand how this is being drawn into the ds2 variable.
Anyone experienced this issue before and figured out what was happening?
Code is as follows:
inputFilePathName = str("C:\\ResearchProcess\\2011sst_sstklcube20170628.img")
noDataValue = (-0.0)
ds2 = gdal.Open(inputFilePathName)
layerList = []
minCubeValues = []
maxCubeValues = []
layerMeans = []
for layer in range( ds2.RasterCount ):
layer += 1
srcLayer = ds2.GetRasterBand(layer)
srcLayer.SetNoDataValue(noDataValue) # screens out the No Data value in .tif, for .img, it doesn't :/
stats = srcLayer.ComputeStatistics( 0 )
layerList.append(layer)
minCubeValues.append(stats[0])
maxCubeValues.append(stats[1])
layerMeans.append(stats[2])
print minCubeValues
ds2 = None
Suggestion by Gabriella Giordano to adapt the approach here works beautifully. Had to create a third variable ds3Array as i had to run through the layered data arrays layer by layer in the wider algorithm.
Cheers :)
Working code as follows.
ds2 = gdal.Open(inputFilePathName)
ds2Array = ds2.ReadAsArray()
layerList = []
minCubeValues = []
maxCubeValues = []
layerMeans = []
layerStdevs = []
for layer in range( ds2.RasterCount ):
layer += 1
ds3Array = ds2Array[layer -1]
ds3Array = np.ma.masked_equal(ds3Array, noDataValue)
minCubeValues.append(ds3Array.min())
layerMeans.append(ds3Array.mean())
layerStdevs.append(ds3Array.std())
Thank you :)
Unfortunately ERDAS imagine (.img) does not support nodata values as GeoTiff or other formats that define a mask to get rid of them.
As stated in the documentation of the SetNodataValue() API that you can find here, the effect of setting a nodata value is therefore driver-dependent.
Nevertheless, for this specific case you could try this solution (go to second answer provided by user Mike T).

write_rich_text of xlwt returns error

I am using xlwt and the following code returns the error Worksheet object has no attribute write_rich_text Why would that be?
seg1 = ("NOT ", Font1)
seg2 = (str(data['Customer'])[:-1], Font2)
sheet1.write_rich_text(row, 4, (seg1, seg2) , Style1)
Note: I am using xlwt 0.7.5 and I see write_rich_text() defined in worksheet.py file
How are you initializing your sheet1 variable?
Make sure there is a page first:
wb = xlwt.Workbook()
sheet1 = wb.add_sheet('Sheet1')
sheet1.write_rich_text(....)
Also you want to take into consideration that write_rich_text is not included in all versions of xlwt so you might want to make sure that the version of xlwt that you are using is the same version that you verified that actually has write_rich_text. Clearly the version that is imported into your app doesn't know anything about a write_rich_text method.
Thank you Max for the pointer. Yes, I had an older version of xlwt in python27 that didn't have write_rich_text method. Replacing that xlwt with the newer version fixed the issue.