In Bazel you can define an attribute type, which could be int or string ... or output
What does it mean to have a type of attribute as "output" ?
Here's an example:
def _something(ctx):
print("The username is: ", ctx.attr.username)
print("boolean value is", ctx.attr.boolean)
print("my age is:", ctx.attr.age)
print("Start printing hours .." )
for i in ctx.attr.hours:
print (i)
print("Finish printing hours ..")
print("Depending on: ", ctx.attr.dep_on)
print_me = rule(
implementation = _something,
attrs = {
"username" : attr.string(),
"boolean" : attr.bool(),
"age" : attr.int(),
"hours" : attr.int_list(),
"dep_on": attr.label(),
"the_results": attr.output(),
},
)
It's a simple rule, which has the_results as of type output
It means that attribute corresponds to a file that the rule will create an action to produce. See https://docs.bazel.build/versions/master/skylark/rules.html#output-attributes and https://docs.bazel.build/versions/master/skylark/lib/attr.html#output.
I have a text file contains:
<Response>
<IP>17.178.96.59</IP>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<RegionCode></RegionCode>
<RegionName></RegionName>
<City>Chicago</City>
<ZipCode></ZipCode>
<TimeZone>America/Chicago</TimeZone>
<Latitude>37.751</Latitude>
<Longitude>-97.822</Longitude>
<MetroCode>0</MetroCode>
</Response>
How to remove each and so I get only:
17.178.96.59,
US,
United States,
nil,
nil,
Chicago,
nil,
America/Chicago,
37.751,
-97.822,
0
Using the Lua script.
You don't show what you already tried, but there is a recently discussed SO question on how to iterate over XML nodes that should work well for your purposes. Just replace fixed element names with something like [%w_]+ and collect parsed values into a table and you'll get the result you are looking for.
This is what I am trying to do.
int = getInternet()
url3 = 'https://freegeoip.app/xml/17.178.96.59'
result = int.getURL(url3)
result = result:gsub("><",">nil<"):gsub("<.->",""):gsub("%c%s+",","):sub(2)..'nil'
print(result)
-- = 17.178.96.59,US,United States,nil,nil,nil,nil,America/Chicago,37.751,-97.822,0,mil
geoResult = {}
for word in string.gmatch(result, '([^,]+)') do
--print(word)
table.insert(geoResult, word)
--for i,v in ipairs(result) do print(i,v) end
end
print('IP : '..geoResult[1])
print('Country ID : '..geoResult[2])
print('Country Name : '..geoResult[3])
print('Region Code : '..geoResult[4])
print('Region Name : '..geoResult[5])
print('City : '..geoResult[8])
print('ZIP Code : '..geoResult[7])
print('Time Zone : '..geoResult[8])
print('Latitude : '..geoResult[9])
print('Longitude : '..geoResult[10])
print('Metro Code : '..geoResult[11])
-- result:
17.178.96.59,US,United States,nil,nil,nil,nil,America/Chicago,37.751,-97.822,0,nil
IP : 17.178.96.59
Country ID : US
Country Name : United States
Region Code : nil
Region Name : nil
City : America/Chicago
ZIP Code : nil
Time Zone : America/Chicago
Latitude : 37.751
Longitude : -97.822
Metro Code : 0
I wanted to copy this page http://www.99-bottles-of-beer.net/lyrics.html in IOS playground to practice but I would like to ask a question and I hope for your help. I created a function called vantanoveBottles, created a variable "texts" of type String and used "for and in" for numbers from 0 ... 5 I created a string constancy in which I entered numbers and text and then I added texts + newLine as in the code.Now if you compare the site when it comes to 1 and says that there are no more beers do not use the number 0, instead I get out so I would basically print example numbers from 1 to 98 inverse with string of text, (and I did this) then come to 1 should not go out "1 bottles of beer on the wall, 1 bottles of beer. \ n" Take one down and pass it around, 0 bottles of beer on the wall. " the 0 must be eliminated must not go out, how do I do? This is a test code
func novantanoveBottles () ->String {
var testi: String = ""
for numeri in (1...99).reversed() {
let newLine:String = "\n \(numeri) bottles of beer on the wall, \(numeri) bottles of beer.\n Take one down and pass it around, \(numeri - 1) bottles of beer on the wall. \n"
testi += newLine
}
testi += "\n \n \n No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall."
return testi
}
print(novantanoveBottles())
You can just add a check before you add that part of the text
for numeri in (1...99).reversed() {
let newLine:String = "\n \(numeri) bottles of beer on the wall, \(numeri) bottles of beer.\n Take one down and pass it around"
if numeri != 1 {
test1 += ", \(numeri - 1) bottles of beer on the wall. \n
} else {
test1 += ".\n"
}
testi += newLine
}
I'm adding some HTML content to an UIWebView.
This line:
generatedHtml += "<br><p style=\"font-family:'Chevin-Medium';font-size:12px;color:#505050;padding-top:0px;\">" + newsItem.entry.likes + " like this " + newsItem.entry.comments?.count + " comments</p>"
I get:
expressions was too complex to be solved in reasonable time
I'm just doing a count on an array, i don't know how to make that less complex?
The object looks like this:
public class NewsItem: NSObject {
var entry: EntryObject = EntryObject()
}
public class EntryObject: NSObject {
var comments: [Comment]? = []
}
newsItem.entry.comments?.count is an integer, and you can't add an integer to a string using +, you should use string interpolation with \():
" like this \(newsItem.entry.comments?.count) comments</p>"
Or use the String initializer if you need to keep using +:
" like this " + String(newsItem.entry.comments?.count) + " comments</p>"
If the error "too complex" persists, you'll have to break down the statements and use variables instead of inserting the expressions directly.
Try to do by this way
var countComments : Int = 0
//Validate comment counting
if let cComments = newsItem.entry.comments?.count
{
countComments = cComments
}
//... Some code here ...
//Devide to Conquest.
//If is easy to find... Is not hard to fix
generatedHtml += "<br>"
generatedHtml += "<p style=\"font-family:'Chevin-Medium';font-size:12px;color:#505050;padding-top:0px;\">"
generatedHtml += "\(newsItem.entry.likes) "
generatedHtml += "like this \(countComments) comments" //Here you have a valid value
genetatedHtml += "</p>"
But, why?
Maybe you have a problem with the optional value newsItem.entry.comments?.count that can gets you a nil value. Then, first of all, validate the value and be sure about what was returned. Better "0", a valid value than nil
When you split the string creation, the debug working will be more easy to execute. You will can have a better idea where is happening an error.
Maybe it´s not a definitive solution to your problem, but a good way to help you fix it.
I have this data set:
Instance num 0 : 300,24,'Social worker','Computer sciences',Music,10,5,5,1,5,''
Instance num 1 : 1000,20,Student,'Computer engineering',Education,10,5,5,5,5,Sony
Instance num 2 : 450,28,'Computer support specialist',Business,Programming,10,4,1,0,4,Lenovo
Instance num 3 : 1000,20,Student,'Computer engineering','3d Design',1,1,2,1,3,Toshiba
Instance num 4 : 1000,20,Student,'Computer engineering',Programming,2,5,1,5,4,Dell
Instance num 5 : 800,16,Student,'Computer sciences',Education,8,4,3,4,4,Toshiba
and I want to classify using SMO and other multi-class classifiers so I convert all the nominal values to numeric using this code :
int [] indices={2,3,4,10}; // indices of nominal columns
for (int i = 0; i < indices.length; i++) {
int attInd = indices[i];
Attribute att = data.attribute(attInd);
for (int n = 0; n < att.numValues(); n++) {
data.renameAttributeValue(att, att.value(n), "" + n);
}
}
and the result is:
Instance num 0 : 300,24,0,0,0,10,5,5,1,5,0
Instance num 1 : 1000,20,1,1,1,10,5,5,5,5,1
Instance num 2 : 450,28,2,2,2,10,4,1,0,4,2
Instance num 3 : 1000,20,1,1,3,1,1,2,1,3,3
Instance num 4 : 1000,20,1,1,2,2,5,1,5,4,4
Instance num 5 : 800,16,1,0,1,8,4,3,4,4,3
after applying the "Normalize" filter the result will be like this:
Instance num 0 : 0,0.666667,0,0,0,1,1,1,0.2,1,0
Instance num 1 : 1,0.333333,1,1,1,1,1,1,1,1,1
Instance num 2 : 0.214286,1,2,2,2,1,0.75,0,0,0.5,2
Instance num 3 : 1,0.333333,1,1,3,0,0,0.25,0.2,0,3
Instance num 4 : 1,0.333333,1,1,2,0.111111,1,0,1,0.5,4
Instance num 5 : 0.714286,0,1,0,1,0.777778,0.75,0.5,0.8,0.5,3
the problem is the converted columns still in String "Normalize" filter will not normalize them...
Any ideas?
and my second question: what should I use as multi-class classifier beside SMO?
Don't convert nominals/categoricals into floats(/integers), and then normalize them. It's meaningless. Garbage In, Garbage Out. Treating them as continuous numbers or numeric vectors gives nonsense results like "the average of 'Engineering' + 'Nursing' = 'Architecture'"
The right way to treat nominals/categoricals is to convert each one into dummy variables (also known as 'dummy coding' or 'dichotomizing'). Say if Occupation column (or Major, or Elective, or whatever) has K levels, then you create either K or (K-1) binary variables which are everywhere 0 except for one corresponding column containing a 1.
Look up Weka documentation to find the right function call.
cf. e.g. SO: Dummy Coding of Nominal Attributes (for Logistic Regression)
I believe that best way to convert string into a numeric can be done using the filter weka.filters.unsupervised.attribute.StringToWordVector.
After doing so, you can apply the "Normalize" filter weka.classifiers.functions.LibSVM.