trying to extract phone number from a resume - nltk

When I try to use the findall function I get this error:
AttributeError: 'str' object has no attribute 'findall'
here is my code :
def phone(content):
content.findall(r"<.*><phone><.*><.*><.*>")

Are you trying to use a regular expression? In this case, the syntax is re.findall(pattern, string, flags=0), thus re.findall("<.*><phone><.*><.*><.*>", content) in your case. See the docs here. Note that this returns a list, and you can access results by indexing with [x].

Related

Azure Data Factory Expression to Check if Property is Defined

I am working with JSON structured data in ADF and trying to implement an IF condition where, if a property is defined in JSON, I will execute one path, another if not defined.
For example, consider the JSON data:
{
"name" : "sh"
"RareProperty" : "rarevalue"
}
RareProperty may or may not exist depending on scenario.
If I try to reference RareProperty in the If Condition block, I get an error saying property RareProperty not defined, which is understandable as the property isn't actually defined in the scenario.
I am looking for a way to check if a property is defined without getting any error.
I think you can use the ? something like
#{body('yourresponse')?['RareProperty']}

Parse value as int in HLC files

I am writing the template for a parametrized HashiCorp Nomad job. One of its parameters is priority, which is supposed to be an integer between 0 and 100.
Like other tools, Nomad supports variable interpolation, so that a variable can be defined at some point and later referenced. Nomad also allows to define "meta" variables, which are passed at runtime and can be used within the HLC file.
What I'm trying to do looks as follows:
job "my-job" {
parametrized {
meta_required = ["TASK_PRIORITY"]
}
priority = "${NOMAD_META_TASK_PRIORITY}"
...
}
The only way I have found to read those variables are within strings. Since the priority stanza expects an integer, the following error is thrown:
error parsing 'job': 1 error(s) decoding: * cannot parse 'Priority' as int: strconv.ParseInt: parsing "${NOMAD_META_TASK_PRIORITY}": invalid syntax
Is there any way to "cast" the string to an integer? Or, alternatively, is there any other way of referencing the variable that would work?
I ended up raising an issue on Github. Their response is that it's not yet possible to interpolate the priority field. See issue.

Supporting JSON paths in BigQuery

I was wondering if BigQuery has any additional support to JSON paths, as it seems like this is such a common way to work with nested data in BigQuery. For example, as a few years ago it seemed like the answer was: What JsonPath expressions are supported in BigQuery?, i.e., "Use a UDF".
However, it seems like using a path within an array, such as:
`$..Job'
Is such a common operation given BigQuery's repeated field, that about 70% of the times I've tried to use BigQuery's JSON_EXTRACT, I run into the limitation of having to iterate down an array.
Is this ability supported yet in BigQuery, or are there plans to support it, without having to do a UDF? As nice as something like the following works:
CREATE TEMPORARY FUNCTION CUSTOM_JSON_EXTRACT(json STRING, json_path STRING)
RETURNS STRING
LANGUAGE js AS """
try { var parsed = JSON.parse(json);
return JSON.stringify(jsonPath(parsed, json_path));
} catch (e) { return null }
"""
OPTIONS (
library="gs://xx-bq/jsonpath-0.8.0.js"
);
SELECT CUSTOM_JSON_EXTRACT(to_json_string(Occupation), '$..Job'), to_json_string(MovieInfo), json_extract(MovieInfo, '$.Platform') FROM `xx-163219.bqtesting.xx` LIMIT 1000
It ends up taking anywhere between 4-6x longer than a normal JSON_EXTRACT function (2s vs. about 10s). Or, is there something that I'm missing with what you're able to do with JSON objects in BQ?
Currently, the support for JSONPath on BigQuery includes and is limited to $, ., and [], where the latter can be either a child operator or a subscript (array) operator.
Other syntax elements from JSONPath are not supported, but for future reference, there's a public feature request to support complete JSONPath syntax.

Elixir - Capitalized keys in structs

I am trying to write a CLI client in Elixir for an API so that I can login to the API system, fetch the data I need for my calculation and then logout. I have defined a Packet.Login struct that supposed to be my internal data structure that I end up with after parsing the JSON I receive.
I am using Poison to parse the JSON. The problem is that it seems like, because of the API returning capitalised properties, I can't match them when printing or parsing, as Poison will return a map with these capitalized keys. The problem is that it seems impossible for me to use the alias like this. If I try to use another syntax,
packet[:Token]
it still does not work and instead gives me an error. But this time about Packet.Login not implementing the Access behaviour. I can understand that part, but not the first issue. And I'm trying to keep the code stupid simple.
defmodule Packet.Login do
defstruct [:Data, :Token]
end
defimpl String.Chars, for: Packet.Login do
def to_string(packet) do
"Packet:\n---Token:\t\t#{packet.Token}\n---Data:\t#{packet.Data}"
end
end
loginPacket = Poison.decode!(json, as: %Packet.Login{})
IO.puts "#{loginPacket}"
When trying to compile the above I get this:
** (CompileError) lib/packet.ex:31: invalid alias: "packet.Token". If you wanted to define an alias, an alias must expand to an atom at compile time but it did not, you may use Module.concat/2 to build it at runtime. If instead you wanted to invoke a function or access a field, wrap the function or field name in double quotes
(elixir) expanding macro: Kernel.to_string/1
Is there a way for me to fix this somehow? I have thought of parsing the map and de-capitalizing all fields first, but I would rather not.
Why can't I have capitalized keys for a struct? It seems like I can though, as long as I don't try to use them.
In order to access a field of a map which is an atom starting with an uppercase letter, you need to either put the key in quotes, e.g. foo."Bar" or use the bracket syntax, e.g. foo[:Bar]. foo.Bar in Elixir is parsed as an alias. With structs, you cannot use the bracket syntax, so the easiest way is to use quotes around the field name. In your code, you'll therefore need to change:
"Packet:\n---Token:\t\t#{packet.Token}\n---Data:\t#{packet.Data}"
to:
"Packet:\n---Token:\t\t#{packet."Token"}\n---Data:\t#{packet."Data"}"
I could not find this documented clearly anywhere but Elixir's source mentions this in some places and also uses this syntax to access some functions in :erlang which have names that are not valid identifiers in Elixir, e.g. :erlang."=<".
Fun fact: you can define functions in Elixir that can only be called with this quote syntax as well:
iex(1)> defmodule Foo do
...(1)> def unquote(:"!##")(), do: :ok
...(1)> end
iex(2)> Foo."!##"()
:ok

SoapUI - how to assert a JSON element containing a custom property

I use SoapUI NG Pro (ReadyAPI-1.1.0.) and try to use the UI to set all my required assertions.
What I try to do is to check if a list (JSON) contains an element that is defined in a soapUI custom property. To get all elements from the list I use the path: $.devices[*].deviceName. Now I like to check if the string from the customer property ${#Project#devname.1} is part of the list.
To write the assertion I found two possibilities, but both of them do not really work.
Use JsonPath Match: The menu servers an input field for the path and one for the expected result and a check box named “Allow Wild…”. I filled the path with $.devices[*].deviceName and the expected result with ${#Project#devname.1}. I also checked the check box to support wildcards. The result is a positive assertion. SoapUI does what I expect. BUT! If I save the project and reopen it, the check box is not checked any more. I have to go over all my assertions and check the boxes again. This is not a solution because I have about 100 of these assertions.
Use JsonPath RegEx Match: A nice way not use the broken “Allow Wild…” checkboxes should be to use a regular expression instead. Therefore I use the “JsonPath RegEx Match” and put the right path $.devices[*].deviceName into the input field and used this regular expression: ${#Project#devname.1}. Sadly this does not work, because SoapUI does not expand the Custom Properties before applying the regular expression. I did not find anything in the documentation explaining how to use custom properties in regular expressions. Could you help here?
In any case. What is a good solution for this type of assertions?
You can try to use JsonPath Match assertion with expression
$.devices[?(#.deviceName=='${#Project#devname.1}')].deviceName.
It will try to find device with deviceName == devname.1. If exists = true, if not - "Comparison failed for path "...", expecting [%your deviceName%], actual was [[]]"