Sorry I'm new to Swift, and I need to create an Array of String data. I know about 2-D Arrays, but I would prefer Objects to store String.
stringObject[0] = ("MATISSE", "JASON SHAPIRO", "9:00AM", "EXPLORE THE TOPICS AND TOOLS RELATED TO TEST DRIVEN DEVELOPMENT.", "TEST DRIVEN DEVELOPMENT")
stringObject[1] = ("ROTHKO", "JIM WHITE", "9:00AM", "DISCUSS THE LATEST SET OF TOOLS USED TO HELP EASE SOFTWARE DEVELOPMENT.", "JAVA TOOLS")
How do I initialized the stringObject?
Related
I'm a newbie in flutter and android application.
I have developed a quiz app.
It loading a Json data from Firebase and i want to save it to Sqlite(for query fast purpose).
My problem is Json data quite complicated, it have multi data array nested(refer Json data as bellow)
Since Sqlite doesn't allow nesting tables within tables, I not sure how to organize or convert the data to Sqlite most reasonable.
I am thinking of saving all my Json as a String, but I know it not a good idea.
Any have a better idea, very appreciate it
{
"title": "TEST title",
"des": null,
"ver": 0,
"partOne": [
{
"number": 1,
"correctAns": 3,
"question": "question 1 here?",
"ansA": "answer A here",
"ansB": "answer B here",
"ansC": "answer C here",
"ansD": "answer D here"
},
// about 100 question
...
// about 100 part
...
]
}
you can try Hive or Objectbox. Both of them are local DB that easy to use and also faster than SQFLite.
If you want to learn more about Hives, you can learn here
https://pub.dev/packages/hive
Flutter x Hive tutorial
If you want to learn more about Objectbox, you can learn here
https://pub.dev/packages/objectbox
Flutter x Objectbox tutorial
this is the database performance benchmark between Hive, Objectbox, and SQFLite (image source: link)
I have try both hive and objectbox. Its recommended for you if you have a complex data and want to solve the storing problem.
Goodluck, hope it helps!
Its better if you use Hive, its a local DB that will let you solve your complex data problem. Super easy and works much faster than SQflite
Things you need:
https://pub.dev/packages/hive
https://pub.dev/packages/hive_flutter
https://pub.dev/packages/hive_generator
And of course some tutorial as well. So,
Flutter x Hive Tutorial
Cheers and good luck!
i´m currently building a Flutter app that includes a larger set of data (like 2000-10000 pieces of text).
I´m relatively new to Flutter delevopment so i have no idea what databases are the best for this case.
The app needs no connection to the internet a all data is on the device after downloading.
You only need to query this data extensively and build now datasets out of it.
I researched a bit, but the most common used database (hive) seems not to be suitable for my needs.
If anyone could help, I´d appreciate it.
It seems ObjectBox is best For Large Data ,it Performs very Well
[Check this package best suits for your data][1]
import 'package:objectbox/objectbox.dart';
class Note {
// Each "Entity" needs a unique integer ID property.
// Add `#Id()` annotation if its name isn't "id" (case insensitive).
int id = 0;
String? text;
DateTime date;
#Transient() // Make this field ignored, not stored in the database.
int? notPersisted;
// An empty default constructor is needed but you can use optional args.
Note({this.text, DateTime? date}) : date = date ?? DateTime.now();
// Note: just for logs in the examples below(), not needed by ObjectBox.
toString() => 'Note{id: $id, text: $text}';
}```
What samples can one add to a custom slot to make it accept any word or phrase?
Update
This solution has been outdated with the introduction of phrase slots eg. AMAZON.SearchQuery.
From the Announcements
Phrase slots are designed to improve speech recognition accuracy for
skills where you cannot include a majority of possible values in the
slot while creating the interaction model. The first slot available in
this category is AMAZON.SearchQuery is designed to provide improved
ability for you to collect generic speech from users.
The Problem
Having worked on developing an urban dictionary skill over the weekend to polish up on my Alexa skills I ran into a problem which I think a lot of skill developers might encounter.
TL;DR
Namely, how do you train Alexa on a custom slot to be able to take any value you give it?
First Attempts
At first I added about 5 words to the custom slot samples like bae, boo, ship it. But I quickly found that the skill would only work with those 5 words and I'd get no calls to my lambda function for words outside that list.
I then used
from nltk.corpus import words
import json, random
words_list = random.shuffle(words.words()[:1000])
words_list = [word.lower() for word in words_list]
words_list = list(set(words_list))
values = []
for word in words_list:
value = {}
value['id'] = None
value['name'] = {}
value['name']['value'] = word
value['name']['synonyms'] = []
values.append(value)
print(json.dumps(values))
The above code uses nltk, which you can install with pip install nltk, to generate a 1000 words according to the schema you can find under code editor, it produce a thousand of these;
{
"id": null,
"name": {
"value": "amblygeusia",
"synonyms": []
}
}
I copied and pasted these under values, you can find the whole file under Code Editor on the Skills Builder page.
"languageModel": {
"types": [
{
"name": "phrase", //my custom slot's name
"values": [...] //pasted the thousand words generated here
...
After saving and building in the Skills Builder UI. This only allowed my skill to capture single word slot values. I tried generating 10 000 words in the same way and adding them as samples for the custom slot but two word and three words phrases weren't recognised and the skill failed to get the definition of phrases like;
ship it
The Solution;
What worked for me and worked really well was to generate two word samples. Despite all the examples being two worded, the skill was then able to recognise single word values and even three word values.
Here's the code to do that using nltk;
from nltk.corpus import words
import json, random
words_list = random.shuffle(words.words()[:1000])
words_list = [word.lower() for word in words_list]
words_list = list(set(words_list))
word_pairs = []
for word in words_list:
pair = ' '.join(random.sample(words_list, 2))
word_pairs.append(pair)
word_pairs = list(set(word_pairs))
for pair in word_pairs:
value = {}
value['id'] = None
value['name'] = {}
value['name']['value'] = pair
value['name']['synonyms'] = []
values.append(value)
print(json.dumps(values))
I put that in a file called custom_slot_value_geneator.py and ran it with;
python3 custom_slot_value_geneator.py | xclip -selection c
This generates the values and copies them to the clipboard.
I then copied them into the Code Editor under values, replacing the old values
"languageModel": {
"types": [
{
"name": "phrase", //my custom slot's name
"values": [...] //pasted the thousand two word pairss generated here
...
Save & Build.
That's it! Your skill would then be able to recognize any word or phrase for your custom slot, whether or not it's in the sample you generated!
I am new to swift but I have made an android app where a string array is selected from an xml file. This is a large xml file that contains a lot of string arrays and the app gets the relevant string array based on a user selection.
I am now trying to develop the same app for iOS using swift. I would like to use the same xml file but I can not see and easy way to get the correct array. For example, part of the xml looks like this
<string-array name="OCR_Businessstudies_A_Topics">
<item>1. Business objectives and strategic decisions</item>
<item>2. External influences facing businesses</item>
<item>3. Marketing and marketing strategies</item>
<item>4. Operational strategy</item>
<item>5. Human resources</item>
<item>6. Accounting and financial considerations</item>
<item>7. The global environment of business</item>
</string-array>
<string-array name="OCR_Businessstudies_AS_Topics">
<item>1. Business objectives and strategic decisions</item>
<item>2. External influences facing businesses</item>
<item>3. Marketing and marketing strategies</item>
<item>4. Operational strategy</item>
<item>5. Human resources</item>
<item>6. Accounting and financial considerations</item>
</string-array>
If I have the string "OCR_Businessstudies_A_Topics" how do i get the "OCR_Businessstudies_A_Topics" array from the xml file.
This is very straight forward in android and although I have used online tutorials for swift it seems like I have to parse the xml file but do not seem to be getting anywhere.
Is there a better approach than trying to parse the whole xml fie?
Thanks
Barry
You can write your own XML parser, conforming to NSXMLParser or use a library like HTMLReader:
let fileURL = NSBundle.mainBundle().URLForResource("data", withExtension: "xml")!
let xmlData = NSData(contentsOfURL: fileURL)!
let topic = "OCR_Businessstudies_A_Topics"
let document = HTMLDocument(data: xmlData, contentTypeHeader: "text/xml")
for item in document.nodesMatchingSelector("string-array[name='\(topic)'] item") {
print(item.textContent)
}
I am pretty new to python and I am trying to make a database using dicts in python 2.7. I am now stumped on how to put the lists into a dict and then again into a dict for the database. I have been searching for weeks on how to do this . I have functions that get the album, artist, year, track number and path for MP3 files. I am getting the data I want I just don't know how to get the data in a dict of a dict. This loop below gives me the values of the keys I want to use.
for x in FileList():
pathlist.append(x)
for artist in getArtist(x):
artistlist.append(artist)
for track in getTrack(x):
tracklist.append(track)
for year in getYear(x):
yearlist.append(year)
I hope I provided enough information for someone to help me figure this out. I am wanting to stay away from CSV files for the time being since I think it is important for me to know how to do this within Python.
First of all: do not mix TAB and space characters, like you do in your example code.
For creating a dictionary with the various lists, just create the dictionary with appropriate keys and the list as values:
dict_of_list = dict(
pathlist = pathlist,
artistlist = artistlist,
tracklist = tracklist,
yearlist = yearlist,
)
or
dict_of_list = {
'pathlist': pathlist,
'artistlist': artistlist,
'tracklist': tracklist,
'yearlist': yearlist,
}
The second version of creating would allow keys other than strings.