Hey all i'm getting data from rest api everything is working fine but i want only text data. anyone pls help me.
{
"description": {
"blocks": [
{
"key": "1h2pe",
"text": "Delicious, loquats are very low in calories; provide just 47 cal per 100 g, however, rich in insoluble dietary fiber, pectin. Pectin retains moisture in the colon and thus functions as bulk laxative and by this way, it helps to protect the colon mucous membrane by decreasing exposure time to toxic substances as well as binding to cancer causing chemicals in the colon.Pectin has also been shown to reduce blood cholesterol levels by decreasing its re-absorption in the colon by binding bile acids resulting in its excretion from the body.Loquat fruit is an excellent source of vitamin-A (provides about 1528 IU per 100g), and phenolic flvonoid antioxidants such as chlorogenic acid, neo-chlorogenic acid, hydroxybenzoic acid, feruloylquinic acid, protocatechuic acid, epicatechin, coumaric acids and ferulic acid. Ripen fruits have more chlorogenic acid concentrations.Vitamin A maintains integrity of mucus membranes and skin. Lab studies have shown that consumption of natural fruits rich in vitamin-A and flavonoids helps to protect from lung and oral cavity cancers.Fresh fruit is very rich in potassium and some B-complex vitamins such as folates, vitamin B-6 and niacin and contain small amounts of vitamin-C. Potassium is an important component of cell and body fluids, helps controlling heart rate and blood pressure.It is also a good source of iron, copper, calcium, manganese, and other minerals. Manganese is used by the body as a co-factor for the antioxidant enzyme, superoxide dismutase. Copper is required in the production of red blood cells. Iron is required for as a cofactor in cellular oxidation as well for red blood cell formation.",
"type": "unstyled",
"depth": 0,
"inlineStyleRanges": [],
"entityRanges": [],
"data": {}
}
],
"entityMap": {}
}
}
You need to create an Adapter class for whatever JSON you're trying to access in Dart.
In Java, they are called POJO classes.
Declare all the variables i.e., 'keys' as variables of type 'value' in a class, and use getters to access individual fields.
You can access the 'Text" data by...
void main() {
var mydata = {
"description": {
"blocks": [
{
"key": "1h2pe",
"text":
"Delicious, loquats are very low in calories; provide just 47 cal per 100 g, however, rich in insoluble dietary fiber, pectin. Pectin retains moisture in the colon and thus functions as bulk laxative and by this way, it helps to protect the colon mucous membrane by decreasing exposure time to toxic substances as well as binding to cancer causing chemicals in the colon.Pectin has also been shown to reduce blood cholesterol levels by decreasing its re-absorption in the colon by binding bile acids resulting in its excretion from the body.Loquat fruit is an excellent source of vitamin-A (provides about 1528 IU per 100g), and phenolic flvonoid antioxidants such as chlorogenic acid, neo-chlorogenic acid, hydroxybenzoic acid, feruloylquinic acid, protocatechuic acid, epicatechin, coumaric acids and ferulic acid. Ripen fruits have more chlorogenic acid concentrations.Vitamin A maintains integrity of mucus membranes and skin. Lab studies have shown that consumption of natural fruits rich in vitamin-A and flavonoids helps to protect from lung and oral cavity cancers.Fresh fruit is very rich in potassium and some B-complex vitamins such as folates, vitamin B-6 and niacin and contain small amounts of vitamin-C. Potassium is an important component of cell and body fluids, helps controlling heart rate and blood pressure.It is also a good source of iron, copper, calcium, manganese, and other minerals. Manganese is used by the body as a co-factor for the antioxidant enzyme, superoxide dismutase. Copper is required in the production of red blood cells. Iron is required for as a cofactor in cellular oxidation as well for red blood cell formation.",
"type": "unstyled",
"depth": 0,
"inlineStyleRanges": [],
"entityRanges": [],
"data": {}
}
],
"entityMap": {}
}
};
List firstList = mydata.values.toList();
List secondList = firstList[0].values.toList();
print("${secondList[0][0]["text"]}");
}
Related
I'm trying to write a rule that applies on a set of facts based on the content of another fact. I have simplified the problem to a House with Rooms. Let's say we have something like:
House(id);
Room(id, houseId, floor, side, paint);
Now, if I want to trigger a rule on all the Houses with all Rooms in left side painted on green I would write something like:
rule "Left side 1st floor green"
when
$h: House()
forall($r: Room(houseId=$h.id, floor==1, side=="left")
Room(id == $r.id, paint == "green"))
then
//Do whatever on rule triggering
end
But what if the objects in the working memory are organized in this way:
House(id, List<> roomIds);
Room(id, floor, side, paint);
How can I write a foreach condition (or any other approach) to make the same consideration on the rooms for a given house? Does it make sense or should I better try to reorganize my objects in advance to have the relationship expressed the other way around?
Thanks
Assuming in House the List<> roomIds is a List of Room.id(s), then you can do something like:
rule "Left side 1st floor green"
when
$h: House(/* .. conditions for specific house? .. */)
$r : Room($h.roomIds contains id, floor==1, side=="left", paint == "green")
then
//Do whatever on rule triggering
end
However this is a bit unefficient, and I do agree as others replied, changing a bit the business/data model would make writing this kind of rule more idiomatic and more efficient. For example if the House did have the list of Rooms, you can also use OOPath to navigate as desired the structure.
According to your rule, you do not have houses with rooms. According to what you have defined you have houses in your working memory and you have rooms in your working memory and you try to match these.
Why don't you have a List of Rooms in your House? That would make much more sense:
House(houseId, List<Room> rooms)
Room(roomId, floor, side, paint)
Then your rule would be:
rule "Left side 1st floor green"
when
$houses : House ($rooms : rooms, $houseId : houseId)
$room : Room ($roomId : roomId, floor==1 && side=="left" && paint == "green") from $rooms
then
//Rule would trigger for each room left side 1st floor green rooms
System.out.println("House "+$houseId+" has following left side 1st floor green room: "+$roomId);
end
My goal is to have products that have some basic information like
Name
Description
Brand/Manufacturer
Dimensions & Weight
And optionally each product can have options based on
Size
Color
Material
I've read a few articles but couldn't find a suitable answer for my problem, which is how to reflect that all those possible combinations of options can have different SKUs, prices and amounts in stock.
And additionally I'd like to have different images for different colors of a product.
So my current thought is to have separate collections for all the options:
Size
Color
Material
Then have arrays of pointers for all those options within the product document and and additional array of variations which reflects every possible combination of options and adds a SKU, price and stock field.
{
_id: "12345",
name: "My Product",
...
colors: [
{
_id: "Color_1",
images: [
"http://myserver.com/images/product_12345_1",
"http://myserver.com/images/product_12345_2",
]
},
{
_id: "Color_3",
images: [
"http://myserver.com/images/product_12345_3",
"http://myserver.com/images/product_12345_4",
]
}
],
sizes: [
{
_id: "Size_5"
},
{
_id: "Size_9"
}
],
materials: [
{
_id: "Material_2"
}
],
variations: [
{
color: "Color_1",
size: "Size_5",
material: "Material_2",
SKU: "98765"
price: 10,
stock: 2
},
{
color: "Color_1",
size: "Size_9",
material: "Material_2",
SKU: "87654"
price: 11,
stock: 5
},
...
],
}
But somehow I feel that there might be an easier way to accomplish what I'm looking for.
Data modelling of Product information is more an art than a science.
It is very common to define Products as the entities sales thinks about. Let's say a car model or a cable. E.g. a "cat 5e Ethernet cable".
Such a product has attributes and dimensions. Attributes might be
standard / norm (e.g. EIA/TIA-586)
Manufacturer (Kabelwerk Eupen)
Number of Wires (8)
Packaging (Plastic Bag)
Tags (Network, Ethernet, Cabling, Infrastructure)
RHoS (Compliant)
etc.
Attributes tend to vary between industries and even between different product categories in the same company.
Dimensions distinguish between different variants of a Product. One or more Dimensions can define a concrete Product. Typical Dimensions are size and colour. For cables, we might have:
size / length (0.5, 1, 2, 5, 10 meters)
colour (green, red, blue)
flame retardant (yes, no)
So Products are the concept of one of your merchandise. In a paper catalogue a Product usually is described as a single thing (maybe on a single page). E.g. a jacket available in blue and brown in sizes S, M, L and XL.
What defines a single Product is somewhat fuzzy. The blue and green sneaker might be the same Product, but the orange and the golden might not be seen as the same product.
Before E-Commerce, we tended to expect the same price for all Dimensions of a Product - not long ago, people were scandalized if a size 8 shoe would be more expensive than a size 9 shoe.
Along some dimensions - colour mostly - users usually except pictures. Along other dimensions - e.g. shoe size - usually there is no expectation of specific pictures.
With some products the manufacturer might be considered an Dimension (cables), for others it might be considered irrelevant (cable ties) and for others two identical looking goods from different manufacturers might be considered completely different Products (e.g. sneakers).
The other concept are SKUs - the stock keeping units are the stuff which is actually in the warehouse. Usually per Product we have Dimensions multiplied with each other SKUs. So 5 sizes x 3 colours x 2 fire retardant variants - so there could be 30 SKUs. Usually each SKU has a distinct GTIN/UPC/EAN ("Barcode" 4423456789012).
Keeping SKUs and Products separate is best practice because they are related to different concerns: Products are of importance for marketing and sales. SKUs concern auditing, bookkeeping and logistics. Products represent concepts, SKUs represent physical goods. Amount of stock usually should be kept in or near the SKU - because on large commerce applications it might get updated several times per second. I would never design a system where transaction data - amount of stock - is mixed up with master data - product description, etc.
Pricing information has been historically attached to the product because product and price data is somewhat static but dynamic pricing might change that.
You seem to be asking for a Product Database. Schemaless Databases work nicely for this because it is very hard to anticipate all needed dimensions for the next few years. Normalizing the whole thing for a Relational Database can certainly be done, but tents to result in less than elegant, and slowish code.
{
name: "Cat 5e Cable",
…
dimensions: {
color: {
title: "Color",
red: {
title: "Red",
images: [
"http://myserver.com/images/product_12345_3",
"http://myserver.com/images/product_12345_4",
],
},
green: { … }
},
size: {
title: "Size"
s05: {
title: "0.5 m",
images: [],
},
s1: {...},
fireretardant:
title: "Size"
yes: {
title: "fire retardant",
images: [],
},
no: {
title: "not fire retardant",
images: [],
}
}
// here you need a stable way of generating keys from dimension data
variations: [
{
dimensions: {color: red, size: s1, fireretardant: no}
SKU: "98765"
price: 10,
},
{
dimensions: {color: red, size: s1, fireretardant: yes}
SKU: "98765"
price: 10,
},
},
…
]
I have implemented applications with such a schema. Usually you want to limit available dimensions and valid values per dimension in the Admin GUI so staff does not come up with obscure new dimensions all the time. But this should be an administrative restriction, not one of the underlying schema.
Non-existent combinations ("fire retardant is only available in green and not in 0.5 m), conflicting instructions ("make all 5 m cables 10 € and all red ones 8 €"), differing and inconsistent ideas what e.g. needs a image, what images should be shared between Dimensions, inconsistent definitions, what considered a separate product ("USB C) or just a Variant ("3.5 mm or 5.5 mm headphone jack"), translation and conversion (don't get me started with shoe sizes) makes real life database design and maintenance interesting …
this is what the so-called "domain knowledge" is about. You need to involve a shoe salesman to design a good shoe database.
In mongodb, which style is better? 1) or 2)? Can I retrieve only line name from 1) despite of getting whole record on db.record.find("line":"east")?
1.
{
"line": "east",
"station":[
{ "name": "ABC", "_id": "1", },
{ "name": "DEF", "_id": "2" }
]
}
2.
{ "line": "east", "l_id":"1"},
{"station":"ABC", "_id":"1", "l_id":"1"},
{"station":"ABC", "_id":"2", "l_id":"1"}
Note: line and station has one to many relationship.
If you are most commonly getting stations by line and often need all stations of a line alt 1 is the best. If you are commonly retrieving single stations or a subset of stations 2 is the best. Alt 2 can lead to more queries since mongo doesn't really have any relations, alt 1 can lead to larger reads and make it more difficult to keep the working set in RAM because of larger objects. Alt 1 also has a minor drawback if you change values in a station on multiple lines - then you have to update its instance in each of the line documents containg it.
To get a partial object, i.e. not all stations in alt 1, you can do a projection to filter out what you don't want. It still means reading the whole object into memory first so you wouldn't gain a lot in performance from doing that.
Can any one suggest search engine that has flexible ranking calculation?
What is flexible ranking calculation?
for example I have two documents:
obj1 = {
title: "new record"
tags: [
{value:"tag1", weight:1},
{value:"tag2", weight:0.8},
{value:"tag3", weight:2},
]
}
obj2 = {
title: "new record with tag1 in title"
tags: [
{value:"tag1", weight:0.5},
{value:"tag2", weight:1},
{value:"tag3", weight:0.01},
]
}
let's assume weight for "title" property is 0.25
When I do search for "tag1" in all properties
I want search to return ranking = 1 for obj1 and ranking = 0.75 for obj2
I know Solr can do it but do you have any other suggestions?
You mention weight for title but then the values you described for scores mapped directly to tag values. Not sure if you missed a detail on how these two connect.
Assuming you want the score of the title match to play a role in the overall document score in addition to boosting documents that match a particular tag or value range, you can do this with Azure Search using scoring profiles (if you want a search-as-a-service solution), and can do it with Solr or Elasticsearch by including boosts as part of the query if you prefer to deploy and management your own infrastructure; in Elasticsearch for example there are function boosts that will allow you to use the value of a field as input to boost computation.
I using pyEphem to calculate RA/Decs of satellites and I'm confused by the different
values computed and described on
http://rhodesmill.org/pyephem/radec.html
this bit of code
sat=ephem.readtle("SATNAME ", \
"1 38356U 12030A 14148.90924578 .00000000 00000-0 10000-3 0 5678",\
"2 38356 0.0481 47.9760 0002933 358.9451 332.7970 1.00270012 3866")
gatech = ephem.Observer()
gatech.lon, gatech.lat = '-155.47322222', '19.82561111'
gatech.elevation = 4194
gatech.date = '2014/01/02 07:05:52'
sat.compute(gatech)
print 'a_ra=',sat.a_ra,'a_dec=',sat.a_dec,'g_ra=',sat.g_ra,'g_dec=',sat.g_dec,'ra=',sat.ra,'dec=',sat.dec
gives
a_ra= 0:52:40.75 a_dec= -3:15:23.7 g_ra= 1:14:10.55 g_dec= 0:06:09.8 ra= 0:53:23.57 dec= -3:10:50.5
if I change JUST the observers location to say
gatech.lon, gatech.lat = '-5.47322222', '19.82561111'
I get
a_ra= 1:15:36.95 a_dec= -2:32:29.9 g_ra= 1:14:10.55 g_dec= 0:06:09.8 ra= 1:16:19.75 dec= -2:28:04.6
I thought the observers position only came into the calculation of sat.ra and sat.dec
so was suprised to see a_ra and a_dec had changed.
What am I missing?
Thanks
Ad
Per the last paragraph of the “body.compute(observer)” section of the Quick Reference:
http://rhodesmill.org/pyephem/quick.html#body-compute-observer
For earth satellite objects, the astrometric coordinates [meaning a_ra and a_dec] are topocentric instead of geocentric, since there is little point in figuring out where the satellite would appear on a J2000 (or whatever epoch you are using) star chart for an observer sitting at the center of the earth.
And in the issue that has been opened about this behavior, the project is open to suggestions about where this text can appear more prominently to prevent future confusion for users:
https://github.com/brandon-rhodes/pyephem/issues/55