RehanSaeed / rehansaeed.github.io

Muhammad Rehan Saeed's Blog
https://rehansaeed.com
30 stars 6 forks source link

[Comment] Structured Data using Schema.NET #117

Open RehanSaeed opened 4 years ago

RehanSaeed commented 4 years ago

https://rehansaeed.com/structured-data-using-schema-net/

RehanSaeed commented 4 years ago

Chad Boettcher Chad Boettcher commented on 2017-09-01 19:02:41

I'm having a problem initializing Values objects. For example, if I'm creating an Organization object, how to I initialize an Awards object with 2 awards?

var organization = new Organization()
{
    Address = new PostalAddress()
    {
        StreetAddress = this.CurrentWebsite.CustomerServiceAddress1,
        AddressLocality = this.CurrentWebsite.CustomerServiceCity,
        AddressRegion = this.CurrentWebsite.CustomerServiceState,
        PostalCode = this.CurrentWebsite.CustomerServicePostalCode,
        AddressCountry = "US"
    },
    Award = new Values()
    {
        // How do you do this for "Award 1" and "Award 2"
    },
};
RehanSaeed commented 4 years ago

Chad Boettcher Chad Boettcher commented on 2017-09-06 22:39:55

Award = new List()
{
    "Award 1",
    "Award 2"
},

By the way, you sir, are a genius. This package saved me a TON of time! Thanks!

RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2017-09-12 15:20:22

I'm having a problem initializing Values objects. For example, if I'm creating an Organization object, how to I initialize an Awards object with 2 awards?

var organization = new Organization()
{
    Address = new PostalAddress()
    {
        StreetAddress = this.CurrentWebsite.CustomerServiceAddress1,
        AddressLocality = this.CurrentWebsite.CustomerServiceCity,
        AddressRegion = this.CurrentWebsite.CustomerServiceState,
        PostalCode = this.CurrentWebsite.CustomerServicePostalCode,
        AddressCountry = "US"
    },
    Award = new Values()
    {
        // How do you do this for "Award 1" and "Award 2"
    },
};

This question is better suited to a GitHub issue. Like so:

var organization = new Organization()
{
    Award = new List<string>()
    {
        "Award 1",
        "Award 2"
    },
};

You can use a List<T> or T[] array.

RehanSaeed commented 4 years ago

Steve Steve commented on 2018-05-10 04:48:46

Great work!

I have a question tho, how can we set the dateCreated to just the year of the book published?

RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2018-05-10 10:43:33

Great work!

I have a question tho, how can we set the dateCreated to just the year of the book published?

I'm not sure what you mean but you can just set the property to a DateTimeOffset value.

RehanSaeed commented 4 years ago

Steve Steve commented on 2018-05-10 10:55:56

I'm not sure what you mean but you can just set the property to a DateTimeOffset value.

Normally, for our collection of books, we only have the publication year (we do not have the complete date)... How can we set the dateCreated to just the year (eg 2007)? The DateTimeOffset data type requires year, month and day.

RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2018-05-10 11:01:28

Normally, for our collection of books, we only have the publication year (we do not have the complete date)... How can we set the dateCreated to just the year (eg 2007)? The DateTimeOffset data type requires year, month and day.

According to https://schema.org/dateCreated, the dateCreated type only supports date or dateTime types. So setting the year alone is not possible.

RehanSaeed commented 4 years ago

Steve Steve commented on 2018-05-10 11:19:25

I understand.

In https://schema.org/Date, it mentions that it should follow ISO8601 format. Which allows yyyy date format.

ISO 8601 prescribes, as a minimum, a four-digit year [YYYY]... W3

RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2018-05-10 11:27:15

I understand.

In https://schema.org/Date, it mentions that it should follow ISO8601 format. Which allows yyyy date format.

ISO 8601 prescribes, as a minimum, a four-digit year [YYYY]... W3

Yes you are right...that's an interesting problem. The only way I can think to resolve it is for every date property like dateCreated, to add a format property like dateCreatedFormat which would take a C# date format string. This could then be used in the serialization/deserialization.

Please do raise an issue in the Schema.NET GitHub site. We'll see if we can get that implemented or also feel free to submit a pull request.

RehanSaeed commented 4 years ago

Steve Steve commented on 2018-05-10 11:53:09

Yes you are right...that's an interesting problem. The only way I can think to resolve it is for every date property like dateCreated, to add a format property like dateCreatedFormat which would take a C# date format string. This could then be used in the serialization/deserialization.

Please do raise an issue in the Schema.NET GitHub page. We'll see if we can get that implemented or also feel free to submit a pull request.

Done. :)

Thanks for the quick response! Cheers!

RehanSaeed commented 4 years ago

Asad Butt Asad Butt commented on 2018-06-23 21:46:37

Thanks for this wonderful work. I'm having slight problem with adding logo to my structure as it is not part of Article object. Any thoughts on that ? Thanks

RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2018-06-24 11:33:11

Thanks for this wonderful work. I'm having slight problem with adding logo to my structure as it is not part of Article object. Any thoughts on that ? Thanks

Logo is not part of the article object on schema.org.

RehanSaeed commented 4 years ago

Vikas Singh Vikas Singh commented on 2018-11-29 09:45:02

I'm having a problem initializing MedicalSpeciality objects. For example, if I'm creating an Physician object, how to I initialize a MedicalSpeciality with multiple speciality?

var physician = new Physician()
{
    Name = objModel.DoctorPersonalVM.DoctorName,
    Url = new Uri(Request.Url.GetLeftPart(UriPartial.Authority) + objModel.DoctorPersonalVM.Slug),
    Description = objModel.DoctorPersonalVM.AboutMe,
    MedicalSpecialty = new MedicalSpecialty()
    {
        objModel.DoctorPersonalVM.Speciality
    }
    Award = new List<string>() 
    {
        objModel.DoctorPersonalVM.AwardName,
    },
};
RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2018-12-01 11:00:50

I'm having a problem initializing MedicalSpeciality objects. For example, if I'm creating an Physician object, how to I initialize a MedicalSpeciality with multiple speciality?

var physician = new Physician()
{
    Name = objModel.DoctorPersonalVM.DoctorName,
    Url = new Uri(Request.Url.GetLeftPart(UriPartial.Authority) + objModel.DoctorPersonalVM.Slug),
    Description = objModel.DoctorPersonalVM.AboutMe,
    MedicalSpecialty = new MedicalSpecialty()
    {
        objModel.DoctorPersonalVM.Speciality
    }
    Award = new List<string>() 
    {
        objModel.DoctorPersonalVM.AwardName,
    },
};

Please raise a GitHub issue. This is not the right place to post issues.

RehanSaeed commented 4 years ago

Zander Zander commented on 2019-04-01 13:36:41

Great work, Rehan!

I'm a bit confused - is there a way to deserialize JSON schema into Schema.NET C# Book type (for example)?

RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2019-04-01 14:04:19

Great work, Rehan!

I'm a bit confused - is there a way to deserialize JSON schema into Schema.NET C# Book type (for example)?

You can just use standard JSON serialization for that. See unit tests.

RehanSaeed commented 4 years ago

Asim Shahzad Asim Shahzad commented on 2019-07-17 13:19:58

Hi,

I have implement your solution. When I test it in google testing tool, tool does not show any thing to me. what will be the expected reason?

I'm using asp.net mvc.

{"@context":"http://schema.org","@type":"Organization","name":"Malik Express","sameAs":"https://www.facebook.com/malikexpress","url":"https://malikexpress.com","address":{"@type":"PostalAddress","addressCountry":"PK","addressLocality":"Islamabad","addressRegion":"ICT","postalCode":"44000","streetAddress":"Javed Plaza, A.K. Fazl-ul-Haq Rd, Block A G 6/3 Blue Area, Islamabad, Islamabad Capital Territory 44000"},"email":"info@malikexpress.com","logo":"https://malikexpress.com/Tempate/img/logo.png"}
RehanSaeed commented 4 years ago

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2019-07-17 16:23:35

hi,

I have implement your solution. When I test it in google testing tool, tool does not show any thing to me. what will be the expected reason?

I'm using asp.net mvc.

{"@context":"http://schema.org","@type":"Organization","name":"Malik Express","sameAs":"https://www.facebook.com/malikexpress","url":"https://malikexpress.com","address":{"@type":"PostalAddress","addressCountry":"PK","addressLocality":"Islamabad","addressRegion":"ICT","postalCode":"44000","streetAddress":"Javed Plaza, A.K. Fazl-ul-Haq Rd, Block A G 6/3 Blue Area, Islamabad, Islamabad Capital Territory 44000"},"email":"info@malikexpress.com","logo":"https://malikexpress.com/Tempate/img/logo.png"}

Hard to say with this much information.

RehanSaeed commented 4 years ago

larrybud larrybud commented on 2020-01-14 01:10:19

It should be noted that to output this in razor syntax, you must use

@Html.Raw()

So the example above which says:

var jsonLd = website.ToString();

The output should be

@Html.Raw(website)

If you just do

@jsonLd

You'll get html encoded strings, which is no good.

Kk-112688 commented 2 years ago

Hi Rehan,

I have a doubt regarding SiteNavigationElement. Can you please tell me where can we assign the list of SiteNavigationElement in Website object. Unable to find. Thanks.