Prolog: slash separated string to list - string

I have a string like '/home/user/something/' and I want to convert it to ['/', 'home', '/', 'user', '/', 'something', '/']
How can I do this?

1- s predicate takes the input and gives the final split answer.
2- split_string is used to return just the words, so it returns L = ["home", "user", "something"]. Notice we don't have the /.
3- Now we need to add the "/". We use addslash predicate, before every word we add a "/". For the last "/" it checks the base predicate and the last "/" is added to the list.
s(X,L1):-
split_string(X, "/", "/", L),
addslash(L,L1).
addslash([],["/"]).
addslash([H|T],[H1,H|L]):-
H1="/",
addslash(T,L).
?- s('/home/user/something/', L).
L = ["/", "home", "/", "user", "/", "something", "/"]

Related

Array with two objects and string how to remove Quotes

I had to .concat two objects and a string, the string didn't have surrounding quotes and now it does, I have tried .replace in every different way, please, is there a way to remove the quotes surrounding a string inside array with other objects
var keywrdrtrn = {city_name:'${city_name}'}
var obj =v[0].concat(v[1]).concat(keywrdrtrn);
}
obj [
{
city_name: 'Cincinnati',
},
{
city_name: 'Mumbai',
},
"{city_name:'',state: ''}"
]
I have removed other index/objects for space but the format is same. I just cannot figure out how to concat the setup without quotes being added or figuring out how to remove quotes after concat
I tried .replace and I tried to convert string to object prior to concat

How do I compare attribute to a lower case value in dynamodb table -> Item -> attribute in query runtime

I want to search text string in attribute like we do in mysql LOWER(fieldName) = LIKE% strtolower(search_text)% . I did some r n d but not found any solution.
{
"TableName": "DEV_postTbl",
"ProjectionExpression": "postId, postType, postStatus",
"ScanIndexForward": false,
"Limit": 6,
"KeyConditionExpression": "postStatus =:postStatusPublished",
"IndexName": "postStatus-createdOn-index",
"FilterExpression": " ( contains( postTitle, :searchText) OR contains(postDescription, :searchText) OR contains(postLocation.addressLine, :searchText) ) ",
"ExpressionAttributeValues": {
":searchText": "hello",
":postStatusPublished": "published"
}
}
This is my code.. but this search only "hello" instead of "Hello", "heLLO" like this
DynamoDB is case sensitive. If your data is case insensitive, one solution is to lower case or upper case the data before storing it in DynamoDB. Then you can get around this by querying for all lower case or all upper case.
Example :
Store postTitle with lowerCase items.
When You search just lowerCase the :searchTex (str.toLowerCase()) and then query.

String matching and store in a list with duplicates

How do i match the string which I already have predefined, and then extract them if they are present in the paragraph which i pass on.
PARAGRAPH : Paragraph are the building blocks of papers. Many student define paragraph in terms of length: a paragraph is a group of at least five sentences, a paragraph is half a page long, etc. In reality, though, the unity and coherence of ideas among sentences is what constitutes a paragraph
Predefined strings: ['paragraph','building blocks', 'length', 'page', 'students']
Output :
['paragraph', 'paragraph', 'paragraph', 'paragraph', 'paragraph', 'length', 'page', 'student' ]
CODE :
match = []
string_doob = paragraph.lower()
for i in predefined_string:
if i in string_doob:
match.append(i)
print(match)
Use your predefined strings as regular expressions(See module re) and re.findall them
EDIT: without regex: iterate over your paragraph for each string and replace if string in paragraph until string is not in paragraph
EDIT2:
paragraph = "abaabbccchsjieiaaavdh"
strings = ["aa", "ab"]
strings_in_para = []
for string in strings:
paragraph_copy = paragraph
while string in paragraph_copy:
paragraph_copy = paragraph_copy.replace(string, "", 1)
strings_in_para.append(string)

Select and substitute whole word before a special character

I have this content in my file:
{
"performanceHighToLow" : {
tabs : {
bySales : "by sales",
byOrder : "by order"
},
category : "performanceHighToLow",
onTabClick
},
performanceLowToHigh : {
tabs : {
bySales : "by sales",
byOrder : "by order"
},
category : "performanceLowToHigh",
onTabClick
}
}
I was wondering if I could write a regex to quote all dequoted words. On the same subject, is there a way to select full word(word boundary) before the colon(:) occurrence.
To match words before a colon you could match word character + possible whitespace + colon, but stopping the match after the word itself with \ze:
/\w\+\ze\s*:
To also match the possible last word in a line (line onTabClick) you could modify the previous pattern with an or at the colon / EOL:
/\w\+\ze\s*\(:\|$\)
In which case it could be easier to enable very-magic to simplify escaping:
/\v\w+\ze\s*(:|$)
To then "quote" these results:
:%s/\v\w+\ze\s*(:|$)/"&"/g

How to handle semicolons when generating a CSV file?

I am using the NPM module json-csv to generate a CSV file from an array of objects. However, some fields might contain a semicolon (;), and apparently the CSV gets split at the semicolon, despite the fact that this field is quoted. Can anyone make any suggestions as to how to fix this issue?
The code I use for the options is the following:
var options = {
fields: [
{
name : 'paragraphId',
label : 'ParagraphID'
},
{
name : 'paragraph',
label : 'Paragraph',
quoted : true
}
]
};
According to CSV specification, you can have delimiters in values, as long as you surround these values with double quotes. From CSV specification:
Fields with embedded commas must be delimited with double-quote characters.
And:
Fields may always be delimited with double quotes.
The delimiters will always be discarded.
Option to trigger this behavior on when exporting data using json-csv library is quoted: true in the options for a given field - I see that you've already included it, so you're good.
Also - it's worth to note that this library uses comma (,) as delimiter by default, not semicolon (;). To use different delimiter, alter your options properly:
var options = {
fields: [
{
name: 'paragraphId',
label: 'ParagraphID'
},
{
name: 'paragraph',
label: 'Paragraph',
quoted: true
}],
fieldSeparator: ';' // the important part!
};

Resources