Text will be cut by SwiftUI, but why? - swiftui

You can directly copy this into Playground, and you will see, that the text is cut, but i don't know why it is cut? How can i prevent this?
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
Text("Background").font(.title).padding()
Text("Ahmad Shah DURRANI unified the Pashtun tribes and founded Afghanistan in 1747. The country served as a buffer between the British and Russian Empires until it won independence from notional British control in 1919. A brief experiment in democracy ended in a 1973 coup and a 1978 communist countercoup. The Soviet Union invaded in 1979 to support the tottering Afghan communist regime, touching off a long and destructive war. The USSR withdrew in 1989 under relentless pressure by internationally supported anti-communist mujahidin rebels. A series of subsequent civil wars saw Kabul finally fall in 1996 to the Taliban, a hardline Pakistani-sponsored movement that emerged in 1994 to end the country's civil war and anarchy. Following the 11 September 2001 terrorist attacks, a US, Allied, and anti-Taliban Northern Alliance military action toppled the Taliban for sheltering Usama BIN LADIN.\nA UN-sponsored Bonn Conference in 2001 established a process for political reconstruction that included the adoption of a new constitution, a presidential election in 2004, and National Assembly elections in 2005. In December 2004, Hamid KARZAI became the first democratically elected president of Afghanistan, and the National Assembly was inaugurated the following December. KARZAI was reelected in August 2009 for a second term. The 2014 presidential election was the country's first to include a runoff, which featured the top two vote-getters from the first round, Abdullah ABDULLAH and Ashraf GHANI. Throughout the summer of 2014, their campaigns disputed the results and traded accusations of fraud, leading to a US-led diplomatic intervention that included a full vote audit as well as political negotiations between the two camps. In September 2014, GHANI and ABDULLAH agreed to form the Government of National Unity, with GHANI inaugurated as president and ABDULLAH elevated to the newly-created position of chief executive officer. The day after the inauguration, the GHANI administration signed the US-Afghan Bilateral Security Agreement and NATO Status of Forces Agreement, which provide the legal basis for the post-2014 international military presence in Afghanistan. After two postponements, the next presidential election has been re-scheduled for September 2019.\nThe Taliban remains a serious challenge for the Afghan Government in almost every province. The Taliban still considers itself the rightful government of Afghanistan, and it remains a capable and confident insurgent force fighting for the withdrawal of foreign military forces from Afghanistan, establishment of sharia law, and rewriting of the Afghan constitution. In 2019, negotiations between the US and the Taliban in Doha entered their highest level yet, building on momentum that began in late 2018. Underlying the negotiations is the unsettled state of Afghan politics, and prospects for a sustainable political settlement remain unclear.").lineLimit(5000).padding()
Text("another")
Text("text")
}
}
}
PlaygroundPage.current.setLiveView(ContentView())

I think it is to do with how SwiftUI renders the VStack with regard to the available screen space. You would expect the large Text to take up the remaining space and you wouldn't be able to see the final two Texts. However you can see them, and the large Text has been truncated. I think the VStack is trying to fit all the items on the screen. If you add additional items after the large Text then it truncates the large Text even further.
Setting a .frame with a maxHeight of .infinity has no effect.
However, if you wrap yourVStack in a ScrollView or a List then the full text is shown.
If you don't want a line limit to your Text then you can pass nil to it as it says the following in the documentation, rather than picking some arbitrarily large number.
If nil, no line limit applies.
struct ContentView: View {
var body: some View {
ScrollView {
VStack(alignment: .leading) {
Text("Background").font(.title).padding()
Text("Ahmad Shah DURRANI unified the Pashtun tribes and founded Afghanistan in 1747. The country served as a buffer between the British and Russian Empires until it won independence from notional British control in 1919. A brief experiment in democracy ended in a 1973 coup and a 1978 communist countercoup. The Soviet Union invaded in 1979 to support the tottering Afghan communist regime, touching off a long and destructive war. The USSR withdrew in 1989 under relentless pressure by internationally supported anti-communist mujahidin rebels. A series of subsequent civil wars saw Kabul finally fall in 1996 to the Taliban, a hardline Pakistani-sponsored movement that emerged in 1994 to end the country's civil war and anarchy. Following the 11 September 2001 terrorist attacks, a US, Allied, and anti-Taliban Northern Alliance military action toppled the Taliban for sheltering Usama BIN LADIN.\nA UN-sponsored Bonn Conference in 2001 established a process for political reconstruction that included the adoption of a new constitution, a presidential election in 2004, and National Assembly elections in 2005. In December 2004, Hamid KARZAI became the first democratically elected president of Afghanistan, and the National Assembly was inaugurated the following December. KARZAI was reelected in August 2009 for a second term. The 2014 presidential election was the country's first to include a runoff, which featured the top two vote-getters from the first round, Abdullah ABDULLAH and Ashraf GHANI. Throughout the summer of 2014, their campaigns disputed the results and traded accusations of fraud, leading to a US-led diplomatic intervention that included a full vote audit as well as political negotiations between the two camps. In September 2014, GHANI and ABDULLAH agreed to form the Government of National Unity, with GHANI inaugurated as president and ABDULLAH elevated to the newly-created position of chief executive officer. The day after the inauguration, the GHANI administration signed the US-Afghan Bilateral Security Agreement and NATO Status of Forces Agreement, which provide the legal basis for the post-2014 international military presence in Afghanistan. After two postponements, the next presidential election has been re-scheduled for September 2019.\nThe Taliban remains a serious challenge for the Afghan Government in almost every province. The Taliban still considers itself the rightful government of Afghanistan, and it remains a capable and confident insurgent force fighting for the withdrawal of foreign military forces from Afghanistan, establishment of sharia law, and rewriting of the Afghan constitution. In 2019, negotiations between the US and the Taliban in Doha entered their highest level yet, building on momentum that began in late 2018. Underlying the negotiations is the unsettled state of Afghan politics, and prospects for a sustainable political settlement remain unclear.")
.lineLimit(nil)
.padding()
Text("another")
Text("text")
}
}
}
}

Related

Google Cloud VideoIntelligence Speech Transcription - Transcription Size

I use Google Cloud Speech Transcription as following :
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.SPEECH_TRANSCRIPTION]
operation = video_client.annotate_video(gs_video_path, features=features)
result = operation.result(timeout=3600)
And I present the transcript and store the transcript in Django Objects using PostgreSQL as following :
transcriptions = response.annotation_results[0].speech_transcriptions
for transcription in transcriptions:
best_alternative = transcription.alternatives[0]
confidence = best_alternative.confidence
transcript = best_alternative.transcript
if SpeechTranscript.objects.filter(text = transcript).count() == 0:
SpeechTranscript.objects.create(text = transcript,
confidence = confidence)
print(f"Adding -> {confidence:4.10%} | {transcript.strip()}")
else:
pass
For instance the following is the text that I receive from a sample video :
94.9425220490% | I refuse to where is it short sleeve dress shirt. I'm just not going there the president of the United States is a visit to Walter Reed hospital in mid-july format was the combination of weeks of cajoling by trump staff and allies to get the presents for both public health and political perspective wearing a mask to protect against the spread of covid-19 reported in advance of that watery trip and I quote one presidential aide to the president to set an example for a supporters by wearing a mask and the visit.
94.3865835667% | Mask wearing is because well science our best way to slow the spread of the coronavirus. Yes trump or Matthew or 3 but if you know what he said while doing sell it still anybody's guess about what can you really think about NASCAR here is what probably have a mass give you probably have a hospital especially and that particular setting were you talking to a lot of people I think it's but I do believe it. Have a a time and a place very special line trump saying I've never been against masks but I do believe they have a time and a place that isn't exactly a ringing endorsement for mask wearing.
94.8513686657% | Republican skip this isn't it up to four men over the perfumer's that wine about time and place should be a blinking red warning light for people who think debate over whether last for you for next coronavirus. They are is finally behind us time in a place lined everything you need to know about weird Trump is like headed next time he'll get watery because it was a hospital and will continue to express not so scepticism to wear masks in public house new CDC guidelines recommending that mask to be worn inside and one social this thing is it possible outside he sent this?
92.9862976074% | He wearing a face mask as agreed presidents prime minister's dictators Kings Queens and somehow. I don't see it for myself literally main door he responded this way back backstage, but they said you didn't need it trump went to Michigan to this later and he appeared in which personality approaching Mark former vice president Joe Biden
94.6677267551% | In his microwave fighting for wearing a mask and he walked onto the stage where it is massive mask there's nobody understands and there's any takes it off you like to have it hanging off you. I think it makes them feel good frankly if you want to know the truth who's got the largest basket together. Seen it because trump thinks that maths make him and people generally I guess what a week or something is resistant wearing one in public from 1 today which has had a correlation between the erosion of the public's confidence and trump have the corner coronavirus and his number is SE6 a second term in the 67.
94.9921131134% | The coronavirus pandemic in the heels of national and swings they both lots of them that show trump slipping further and further behind former vice president Joe Biden when it comes to General Election good policy would seem to make for good politics at all virtually every infectious disease expert believes that wearing masks in public is our best to contain the spread of coronavirus until a vaccine would do well to listen to buy on this one a mare is the point we make episode every Tuesday and Thursday make sure to check them all out.
What is the predicted size of a transcript that is generated within the speech transcription results. What decides the size of each transcript ? What is the max and minimum character length ? How should I design my SQL table column size, in order to be prepared for the expected transcript size ?
As I mentioned in the comments, the Video Intelligence transcripts are splits with roughly 50-60 seconds from the video.
I have created a Public Issue Tracker case, link, so the product team can clarify this information within the documentation. Although, I do not have an eta for this request, I encourage you to follow the case's thread.

How to replace line break and keeping the remaining string

I have a csv file, within the cells are comments which contains line breaks.
I have almost succeeded to select those comments
select: ("[^,])(.[^"]*)((\n){1,})(.[^"]*)(",)
replace: I have tried $1$2$3$6 and \1\2\3\6
Example of string:
Panthéon Sorbonne (Paris I),,,,,,,,,,,"More than 6 years in Finance
Corporate Finance, Mergers & Acquisitions, Cross-border
transactions, Emerging Market in particular South America Mid Market,
all sectors Financial analysis, Valuation DCF and Multiples Modeling,
Speaking French, English, Spanish and Portuguese ",,,,,
Expected result:
Panthéon Sorbonne (Paris I),,,,,,,,,,,"More than 6 years in Finance Corporate Finance, Mergers & Acquisitions, Cross-border transactions, Emerging Market in particular South America Mid Market, all sectors Financial analysis, Valuation DCF and Multiples Modeling, Speaking French, English, Spanish and Portuguese",,,,,
none of these trials have successfull.

Word2Vec Doesn't Contain Embedding for Number 23

Hi I am on the course of developing Encoder-Decoder model with Attention which predicts WTO Panel Report for the given Factual Relation given as Text_Inputs.
Sample_sentence for factual relation is as follow:
sample_sentence = "On 23 January 1995, the United States received a request from Venezuela to hold consultations under Article XXII:1 of the General Agreement on Tariffs and Trade 1994 (\"General Agreement\"), Article 14.1 of the Agreement on Technical Barriers to Trade (\"TBT Agreement\") and Article 4 of the Understanding on Rules and Procedures Governing the Settlement of Disputes (\"DSU\"), on the rule issued by the Environmental Protection Agency on 15 December 1993, entitled \"Regulation of Fuels and Fuel Additives - Standards for Reformulated and Conventional Gasoline\" (WT/DS2/1). The consultations between Venezuela and the United States took place on 24 February 1995. As they did not result in a satisfactory solution of the matter, Venezuela, in a communication dated 25 March 1995, requested the Dispute Settlement Body (\"DSB\") to establish a panel to examine the matter under Article XXIII:2 of the General Agreement and Article 6 of the DSU (WT/DS2/2). On 10 April 1995, the DSB established a panel in accordance with the request made by Venezuela. On 28 April 1995, the parties to the dispute agreed that the Panel should have standard terms of reference (DSU, Art. 7) and agreed on the composition of the Panel as follows"
I am trying to using Word2Vec from google and encode each word into 300dim Word Vectors however, like number 23 appears as not included in the Word2Vec VocaSets.
Which would be the solution for this problem?
1) Use another Word Embedding for example Glovec?
2) Or Another any other advice?
Thx in advance for your help
edit)
I think to succefully fulfill this task, I think first I have to understand how current NMT application deals with Named Entity Recognition problem in advance before they actually train it.
Any suggestive literatures?
Word2Vec only learns words it has seen a lot.
Maybe try replacing the numbers in your source with text ie ("On the twenty third of ...")?

Bluetooth LE: Send data from iOS got cuts short

If this has been asked before, I apologize.
I send a long string that contains about length of 750 bytes from iOS device to a bluetooth thermal printer. However, when the string is printed out, the printer only prints out partial of the context which is about 160 bytes in CChar. I am a bit confused why this happens, can any one care to explain about this?
code:
let cfEnc = CFStringEncodings.GB_18030_2000
let enc = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(cfEnc.rawValue))
let ccc = "The franchise began in 1977 with the release of the film Star Wars
(subtitled Episode IV: A New Hope in 1981[2][3]), which became a worldwide pop
culture phenomenon. It was followed by the successful sequels The Empire
Strikes Back (1980) and Return of the Jedi (1983); these three films constitute
the original Star Wars trilogy. A prequel trilogy was released between 1999 and
2005, which received mixed reactions. A sequel trilogy began in 2015 with the
release of Star Wars: The Force Awakens. All seven films were nominated for
Academy Awards (with wins going to the first two films) and have been
commercial successes, with a combined box office revenue of $7.471 billion,[4]
making Star Wars the third highest-grossing film series.[5] Spin-off films
include Star Wars: The Clone Wars (2008) and Rogue One (2016), which is the
first in an upcoming series of anthology films.\n\nThe series has spawned an
extensive media franchise—the Star Wars expanded universe—including books,
television series, computer and video games, and comic books, resulting in
significant development of the series's fictional universe. Star Wars also
holds a Guinness World Records title for the \"Most successful film
merchandising franchise. In 2015, the total value of the Star Wars franchise
was estimated at USD $41.9 billion,[6] making Star Wars the second highest-
grossing media franchise of all time.\n\nIn 2012, The Walt Disney Company
acquired Lucasfilm for $4.06 billion and earned the distribution rights to all
subsequent Star Wars films, beginning with the release of The Force Awakens in
2015.[7] The former distributor, 20th Century Fox, retains the physical
distribution rights to the first two Star Wars trilogies, owning permanent
rights for the original 1977 film and holding the rights to Episodes I–III, V,
and VI until May 2020.[8][9] Walt Disney Studios owns digital distribution
rights to all the Star Wars films, excluding A New Hope."
print(ccc.lengthOfBytes(using: String.Encoding(rawValue: enc))) //count number is 164
if let data = ccc.data(using: String.Encoding(rawValue: enc)) {
self.writeValue(data)
}
in writeValue function
private func writeValue(_ data: Data!) {
self.printerPeripheral?.writeValue(data, for: self.writeCharacteristic, type: .withResponse)
print("+++++++++++++++++++++++++++++++++++++++++++++++++++++")
print(self.writeCharacteristic.uuid.uuidString)
print("sending number of byte to BLE:\(data!)") // I get 748 as return
print("+++++++++++++++++++++++++++++++++++++++++++++++++++++")
}
Do I have to chop string in order to have it work?

How to scrape a particular part of a HTML page using regular expression or HTMLAgilityPack in visual studio 2010 using C#?

I have var source="<p><img src="http://l.yimg.com/bt/api/res/1.2/TRLtYhdbTvFcX_GOU_0S4g--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2012-04-14T023232Z_5_CBRE83B1MAL00_RTROPTP_2_USA.JPG" width="130" height="86" alt="People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York" align="left" title="People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York" border="0" />(Reuters) - An unusual stock split designed to preserve Google Inc founders' control of the Web search leader raised questions and some grumbling on Wall Street, even as investors focused on the company's short-term business concerns. Shares of Google closed 4 percent lower at $624.60 on Friday, driven by deepening worries about its search ad rates and payments to partners. The declining search trends underscored investor uncertainty about Google's growth prospects and unease about the company's pending $12.5 billion acquisition of Motorola Mobility. ...</p><br clear="all"/>" Now i need to parse/scrape this to get the link address in a variable i.e http://in.news.yahoo.com/googles-stock-split-raises-questions-023232813.html and the image src in a separate variable. I also need the description text between </a> and </p>.. Kindly help i am badly stuck...
Try the below code snippet using HtmlAgilityPack
var source = #"<p><img src=""http://l.yimg.com/bt/api/res/1.2/TRLtYhdbTvFcX_GOU_0S4g--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2012-04-14T023232Z_5_CBRE83B1MAL00_RTROPTP_2_USA.JPG"" width=""130"" height=""86"" alt=""People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York"" align=""left"" title=""People visit Google's stand at the National Retail Federation Annual Convention and Expo in New York"" border=""0"" />(Reuters) - An unusual stock split designed to preserve Google Inc founders' control of the Web search leader raised questions and some grumbling on Wall Street, even as investors focused on the company's short-term business concerns. Shares of Google closed 4 percent lower at $624.60 on Friday, driven by deepening worries about its search ad rates and payments to partners. The declining search trends underscored investor uncertainty about Google's growth prospects and unease about the company's pending $12.5 billion acquisition of Motorola Mobility. ...</p><br clear=""all""/>";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(source);
var paraNode = doc.DocumentNode.SelectSingleNode("//p");
var desc = paraNode.InnerText;
var anchorNode = doc.DocumentNode.SelectSingleNode("//p/a");
var link = anchorNode.GetAttributeValue("href", null);
var imgNode = doc.DocumentNode.SelectSingleNode("//p/a/img");
var src = imgNode.GetAttributeValue("src", null);
There are many ways to do this, but this is just one of the approach to get the job done. It gives you an idea how to do it with HtmlAgilityPack. XPATH will give you lot of power while parsing stuff like this.