2013-05-06 52 views
1

我还有另一个障碍,用我的GOOGLE DRIVE SDK Android应用程序来爬。我使用严格控制的索引字段上传扫描图像 - 本地字典中用户定义的“标记”。例如XXX.JPG有索引词“汽车”+“保险”。下面是一个简单的代码片段:我可以在JPEG文件上停止OCR吗?

... 
    body.setTitle("XXX.JPG"); 
    body.setDescription("car, insurance");   
    body.setIndexableText(new IndexableText().setText("car insurance")); 
    body.setMimeType("image/jpeg"); 
    body.setParents(Arrays.asList(new ParentReference().setId(...))); 

    FileContent cont = new FileContent("image/jpeg", new java.io.File(fullPath("xxx.jpg"))); 

    File gooFl = _svc.files().insert(body, cont).execute(); 
    ... 

再次,一切都很正常,只是当我开始搜索,我得到的结果,显然来自一些OCR后处理,从而使我的系统的字典无法使用。我假设我可以使用自定义的MIME类型,但对于使用标准GOOGLE DRIVE应用程序(本地,基于浏览器的...)的用户来说,JPEG图像变得不可见。所以问题是:我可以用自定义索引(可索引或描述字段)上传MIME“image/jpeg”文件,但停止GOOGLE OCR我的文件并添加索引我不打算有?
为了更具体一点,我搜索“汽车保险”,而不是我以这种方式索引的3个文件,我得到了难以管理的一堆其他结果(JPEG扫描文档),其中有“汽车”和“保险” 。不是我的应用程序想要的。
谢谢你在前进,肖恩
...

基于以下Burcu的提醒,我修改了代码的东西,看起来像这样(剥离到裸露的骨头):

// define meta-data 
File body = new File(); 
body.setTitle("xxx.jpg"); 
body.setDescription(tags);   
body.setIndexableText(new IndexableText().setText(tags)); 
body.setMimeType("image/jpeg"); 
body.setParents(Arrays.asList(new ParentReference().setId(_ymID))); 
body.setModifiedDate(DateTime.parseRfc3339(ymdGOO)); 
FileContent cont = 
    new FileContent("image/jpeg",new java.io.File(fullPath("xxx.jpg"))); 
String sID = findOnGOO(driveSvc, body.getTitle()); 
// file not found on gooDrive, upload and fix the date 
if (sID == null) { 
    driveSvc.files().insert(body, cont).setOcr(false).execute(); 
    driveSvc.files().patch(gooFl.getId(), body).setOcr(false).setSetModifiedDate(true).execute(); 
// file found on gooDrive - modify metadata and/or body 
} else { 
    // modify content + metadata 
    if (contentModified) { 
    driveSvc.files().update(sID, body, cont).setOcr(false).setSetModifiedDate(true).execute(); 
    // only metadata (tags,...) 
    } else { 
    driveSvc.files().patch(sID, body).setOcr(false).setSetModifiedDate(true).execute(); 
    } 
} 
... 

这是一个阻止上传或修改Google云端硬盘文件。这两个非标准操作是:
1 /重置文件的“修改”日期以强制文件创建的日期 - 测试,工作正常
2 /停止OCR进程干扰我的应用程序索引方案 - 将测试不久,并在这里更新

为了简单起见,我没有包含“findInGOO()”方法的实现。这是很简单的2衬垫,我可以根据要求

肖恩

回答

2

在插入它供给,设置OCR参数设置为false:

service.files().update(body, content).setOcr(false).execute(); 
+0

谢谢,再次。 – seanpj 2013-05-07 02:33:59

+0

由于我无法轻易地将文档翻译成我的java结构,所以我很难正确地完成这件事。我已经看到[files:insert](https://developers.google.com/drive/v2/reference/files/insert)的引用,但无法找出正确的java语法。此外,默认情况下,引用声明'ocr'为'false'。去搞清楚。我会测试它并会让你知道它是如何发生的。我得在某个地方/某个时间赶上你,给你买一瓶啤酒。再次感谢,谢恩 – seanpj 2013-05-07 02:41:26

+0

谢谢。 OCR和useContentAsIndexableText默认为false,我们索引提取的文本很奇怪。与此同时,我会尝试在这里重现这个问题。 – 2013-05-07 10:14:51

相关问题