schema.org中的多个实体

时间:2016-09-25 02:58:50

标签: schema.org json-ld structured-data

如何在NewsArticleBlogPosting中嵌套一个或多个食谱。

我试过了,但Google's Structured Data Testing Tool引发了抱怨recipe1密钥的错误。我不确定将recipe1键更改为:

  <script type="application/ld+json">
{
"@context" : "http://schema.org",
  "@type" : "NewsArticle",
  "author" : { "@type" : "Person",
      "name" : "hgezim"
    },
  "dateModified" : "2016-09-21T06:25:35+00:00",
  "datePublished" : "2016-09-21T06:25:35+00:00",
  "headline" : "Chicken Papriak",
  "mainEntityOfPage" : "http://localhost:8080/2016/09/21/chicken-papriak/",
  "publisher" : { "@type" : "Organization",
      "name" : "Dev Blog"
  },
  "recipe1": {
    "@context": "http://schema.org",
    "@type": "Recipe",
    "author": "John Smith",
    "cookTime": "PT1H",
    "datePublished": "2009-05-08",
    "description": "This classic banana bread recipe comes from my mom -- the walnuts add a nice texture and flavor to the banana bread.",
    "image": "bananabread.jpg",
    "recipeIngredient": [
      "3 or 4 ripe bananas, smashed",
      "1 egg",
      "3/4 cup of sugar"
    ],
    "interactionStatistic": {
      "@type": "InteractionCounter",
      "interactionType": "http://schema.org/Comment",
      "userInteractionCount": "140"
    },
    "name": "Mom's World Famous Banana Bread",
    "nutrition": {
      "@type": "NutritionInformation",
      "calories": "240 calories",
      "fatContent": "9 grams fat"
    },
    "prepTime": "PT15M",
    "recipeInstructions": "Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add the flour last. Pour the mixture into a loaf pan and bake for one hour.",
    "recipeYield": "1 loaf",
    "suitableForDiet": "http://schema.org/LowFatDiet"
  }
}
  </script>

2 个答案:

答案 0 :(得分:1)

这取决于实体彼此之间的关系。您必须使用定义的属性来传达此关系。

要查找合适的媒体资源,请检查BlogPosting以查看具有Recipe或其某种父类型(CreativeWorkThing)的媒体资源作为预期值。

例如:

    如果博客文章是关于这个特定的食谱(例如,你描述你喜欢它的方式),可以使用
  • about
  • 如果食谱构成博客文章的一部分,则可以使用
  • hasPart
  • 如果您只是在博客文章中引用此配方,则可以使用
  • mentions
  • ...

答案 1 :(得分:0)

谢谢@unor。我使用void numberSearch(string fileName) { string searchVal; cout << "\nWhat value would you like to search for?\n"; cin.ignore(); getline(cin, searchVal); ifstream file; //create input file object that will be read from file.open(fileName); //"ifstream file (fileName)" if (!file) { cout << "\nUnable to open file.\n"; exit(1); } string words; int curLine = 0; //file line counter while (getline(file, words)) { ++curLine; //counts each line in the file if (words.find(searchVal) != string::npos) { cout << "\nLine " << curLine << " contains " << searchVal << endl; file.close(); return; } else { cout << "\nThe value " << searchVal << " was not found.\n"; file.close(); return; } } } 如下:

hasPart

验证为validates JSON-LD